当前位置: 首页>>代码示例>>Python>>正文


Python Stats.refresh方法代码示例

本文整理汇总了Python中stats.Stats.refresh方法的典型用法代码示例。如果您正苦于以下问题:Python Stats.refresh方法的具体用法?Python Stats.refresh怎么用?Python Stats.refresh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在stats.Stats的用法示例。


在下文中一共展示了Stats.refresh方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: WaypointMonitor

# 需要导入模块: from stats import Stats [as 别名]
# 或者: from stats.Stats import refresh [as 别名]
class WaypointMonitor(Thread):

    def __init__(self, monitor_type, **kwargs):
        Thread.__init__(self)
        self.stat = Stats(monitor_type, **kwargs)
        self.stat_type = monitor_type
        self.waypoint_address = None
        print "Created waypoint monitor for %s" % self.stat

    def set_waypoint(self, waypoint_ip):
        self.waypoint_address = waypoint_ip
        print "Registered waypoint for %s.  Any large flows will be redirected to %s." % (self.stat, waypoint_ip)

    def set_high_threshold(self, s):
        self.stat.set_high_threshold(s)
        print "Set high threshold for flow rate to %3.3f Mbps" % (int(s) * (1.0/1000000))
        print("-------------------------")

    def set_low_threshold(self, s):
        self.stat.set_low_threshold(s)
        print "Set low threshold for flow rate to %3.3f Mbps" % (int(s) * (1.0/1000000))
        print("-------------------------")

    def run(self):
        global sigint
        high_rate_set = False
        while not sigint:
            is_high, is_low = self.stat.refresh()
            if is_high and not high_rate_set:
                ac = AffinityControl()
                high_rate_set = True
#                ac.add_waypoint(link_name, self.waypoint_address)
                ac.add_isolate(link_name)
                ac.enable_affinity()
                print "Adding isolate affinity to link: %s" % (link_name)
#                time.sleep(3)
            elif is_low and high_rate_set: 
                high_rate_set = False
                ac.remove_isolate(link_name)
                ac.enable_affinity()
                print "Adding isolate affinity to link: %s" % (link_name)
            time.sleep(10)
开发者ID:inocybe,项目名称:odl-affinity,代码行数:44,代码来源:demo3.py

示例2: WaypointMonitor

# 需要导入模块: from stats import Stats [as 别名]
# 或者: from stats.Stats import refresh [as 别名]
class WaypointMonitor(Thread):

    def __init__(self, monitor_type, **kwargs):
        Thread.__init__(self)
        self.stat = Stats(monitor_type, **kwargs)
        self.stat_type = monitor_type
        self.waypoint_address = None
        print "Created waypoint monitor for %s" % self.stat

    def set_waypoint(self, waypoint_ip):
        self.waypoint_address = waypoint_ip
        print "Registered waypoint for %s.  Any large flows will be redirected to %s." % (self.stat, waypoint_ip)

    def set_large_flow_threshold(self, s):
        self.stat.set_large_flow_threshold(s)
        print "Set threshold for large flows to %d bytes" % s
        print("-------------------------")

    def run2(self):
        global sigint
        did_waypoint = False
        while not sigint:
            is_fast, is_big = self.stat.refresh()
            if is_big and not did_waypoint:
                print "Large flow detected (%d bytes, %d packets, %3.3f bit/s)" % (self.stat.get_bytes(), self.stat.get_packets(), self.stat.get_bit_rate())
                print "   ICMP: %d bytes, %d packets" % (self.stat.get_bytes(1), self.stat.get_packets(1))
                print "   UDP: %d bytes, %d packets" % (self.stat.get_bytes(17), self.stat.get_packets(17))
                print "   TCP: %d bytes, %d packets" % (self.stat.get_bytes(6), self.stat.get_packets(6))
                print "   other: %d bytes, %d packets" % (self.stat.get_bytes(-1), self.stat.get_packets(-1))
                print("-------------------------")
                ac = AffinityControl()
                # First AG: Sources sending data into this subnet
                src_ag_name = "sources"
                src_ips = self.stat.get_large_incoming_hosts()
                if (self.waypoint_address in src_ips):
                    src_ips.remove(self.waypoint_address)
                ac.add_affinity_group(src_ag_name, ips=src_ips)
                # Second AG: This entity
                dst_ag_name = "client"
                if (self.stat_type == Stats.TYPE_SUBNET):
                    ac.add_affinity_group(dst_ag_name, subnet=self.stat.subnet)
                elif (self.stat_type == Stats.TYPE_HOST):
                    pass
                else:
                    print "type", self.stat_type, "not supported for redirection"
                # AL: Between them
                link_name = "inflows"
                ac.add_affinity_link(link_name, src_ag_name, dst_ag_name)
#                ac.add_waypoint(link_name, self.waypoint_address)
                ac.add_isolate(link_name)
#                ac.enable_waypoint(link_name)
                ac.enable_affinity()
                did_waypoint = True
                raw_input("[Press Enter to disable affinity rules] ")
                ac.disable_affinity()
#                ac.disable_waypoint(link_name)
            time.sleep(1)



    def run(self):
        global sigint
        did_waypoint = False
        while not sigint:
            is_fast, is_big = self.stat.refresh()
            if is_fast and not did_waypoint:
                print "Fast flow detected (%3.3f bit/s)" % (self.stat.get_ewma_rate())
                ac = AffinityControl()
                # First AG: Sources sending data into this subnet
                src_ag_name = "sources"
                # Hosts that transmit > 10% of link capacity
                src_ips = self.stat.get_large_incoming_hosts()
                print "LFD src list = ", src_ips
                print "Discard waypoint address"
                if (self.waypoint_address in src_ips):
                    src_ips.remove(self.waypoint_address)
 
                ac.add_affinity_group(src_ag_name, ips=src_ips)

                # Second AG: This entity
                dst_ag_name = "client"
                if (self.stat_type == Stats.TYPE_SUBNET):
                    ac.add_affinity_group(dst_ag_name, subnet=self.stat.subnet)
                elif (self.stat_type == Stats.TYPE_HOST):
                    ac.add_affinity_group(dst_ag_name, ips=self.dst)
                else:
                    print "type", self.stat_type, "not supported for redirection"

                # AL: Between them
                link_name = "inflows"
                ac.add_affinity_link(link_name, src_ag_name, dst_ag_name)
#                ac.add_waypoint(link_name, self.waypoint_address)
                ac.add_isolate(link_name)
                ac.enable_affinity()
                did_waypoint = True
                time.sleep(10)
            
            # Flow now gone, disable affinity.
            elif did_waypoint and not is_fast: 
                ac.disable_affinity()
#.........这里部分代码省略.........
开发者ID:inocybe,项目名称:odl-affinity,代码行数:103,代码来源:demo.py

示例3: __init__

# 需要导入模块: from stats import Stats [as 别名]
# 或者: from stats.Stats import refresh [as 别名]
class pyTrainer:
    def __init__(self,filename = None, data_path = None):
        #Version constants
        self.version ="1.10.0-dev"
        #Process command line options
        self.startup_options = self.get_options()
        #Setup logging
        self.environment = Environment(platform.get_platform(), self.startup_options.conf_dir)
        self.environment.create_directories()
        self.set_logging(self.startup_options.log_level, self.startup_options.log_type)
        logging.debug('>>')
        logging.debug("PyTrainer version %s" % (self.version))
        self.data_path = data_path
        self.date = Date()
        self.ddbb = None
        # Checking profile
        logging.debug('Checking configuration and profile...')
        self.profile = Profile(self.environment, self.data_path,self)
        self.uc = UC()
        self.windowmain = None
        self.ddbb = DDBB(self.profile, self)
        logging.debug('connecting to DDBB')
        self.ddbb.connect()
        
        initialize_data(self.ddbb, self.environment.conf_dir)
            
        self._sport_service = SportService(self.ddbb)
        self.record = Record(self._sport_service, data_path, self)
        self.athlete = Athlete(data_path,self)
        self.stats = Stats(self._sport_service, self)
        pool_size = self.profile.getIntValue("pytraining","activitypool_size", default=1)
        self.activitypool = ActivityPool(self, size=pool_size)
        #preparamos la ventana principal
        self.windowmain = Main(self._sport_service, data_path,self,self.version, gpxDir=self.profile.gpxdir)
        self.date = Date(self.windowmain.calendar)
        self.waypoint = Waypoint(data_path,self)
        self.extension = Extension(data_path, self)
        self.plugins = Plugins(data_path, self)
        self.importdata = Importdata(self._sport_service, data_path, self, self.profile)
        self.loadPlugins()
        self.loadExtensions()
        self.windowmain.setup()
        self.windowmain.on_calendar_selected(None)
        self.refreshMainSportList()
        self.windowmain.run()
        logging.debug('<<')


    def get_options(self):
        '''
        Define usage and accepted options for command line startup

        returns: options - dict with option: value pairs
        '''
        usage = '''usage: %prog [options]

        For more help on valid options try:
           %prog -h '''
        parser = OptionParser(usage=usage)
        parser.set_defaults(log_level=logging.ERROR, validate=False, equip=False, newgraph=True, conf_dir=None, log_type="file")
        parser.add_option("-d", "--debug", action="store_const", const=logging.DEBUG, dest="log_level", help="enable logging at debug level")
        parser.add_option("-i", "--info", action="store_const", const=logging.INFO, dest="log_level", help="enable logging at info level")
        parser.add_option("-w", "--warn", action="store_const", const=logging.WARNING, dest="log_level", help="enable logging at warning level")
        parser.add_option("--valid", action="store_true", dest="validate", help="enable validation of files imported by plugins (details at info or debug logging level) - note plugin must support validation")
        parser.add_option("--oldgraph", action="store_false", dest="newgraph", help="Turn off new graphing approach")
        parser.add_option("--newgraph", action="store_true", dest="newgraph", help="Deprecated Option: Turn on new graphing approach")
        parser.add_option("--confdir", dest="conf_dir", help="Specify the directory where application configuration will be stored.")
        parser.add_option("--logtype", dest="log_type", metavar="TYPE",  type="choice" , choices=["file", "console"], help="Specify where logging should be output to. TYPE is one of 'file' (default), or 'console'.")
        (options, args) = parser.parse_args()
        return options

    def set_logging(self, level, log_type):
        '''Setup rotating log file with customized format'''
        if("console" == log_type):
            handler = logging.StreamHandler(sys.stdout)
        else:
            handler = logging.handlers.RotatingFileHandler(self.environment.log_file, maxBytes=100000, backupCount=5)
        formatter = logging.Formatter('%(asctime)s|%(levelname)s|%(module)s|%(funcName)s|%(message)s')
        handler.setFormatter(formatter)
        logging.getLogger('').addHandler(handler)
        self.set_logging_level(self.startup_options.log_level)

    def set_logging_level(self, level):
        '''Set level of information written to log'''
        logging.debug("Setting logger to level: "+ str(level))
        logging.getLogger('').setLevel(level)

    def quit(self):
        logging.debug('--')
        logging.info("Exit!")
        #self.webservice.stop()
        self.windowmain.gtk_main_quit()
        logging.shutdown()
        sys.exit() # Any nonzero value is considered "abnormal termination" by shells and the like

    def loadPlugins(self):
        logging.debug('>>')
        activeplugins = self.plugins.getActivePlugins()
        if (len(activeplugins)<1):
             logging.info("No active plugins")
#.........这里部分代码省略.........
开发者ID:dantleech,项目名称:pytrainer,代码行数:103,代码来源:main.py


注:本文中的stats.Stats.refresh方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。