本文整理汇总了Python中monitor.Monitor.run方法的典型用法代码示例。如果您正苦于以下问题:Python Monitor.run方法的具体用法?Python Monitor.run怎么用?Python Monitor.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类monitor.Monitor
的用法示例。
在下文中一共展示了Monitor.run方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from monitor import Monitor [as 别名]
# 或者: from monitor.Monitor import run [as 别名]
def main():
logger = Logger()
logger.redirect_std()
logger.info("started pylemon daemon")
config = Config()
if not config.parse("/etc/pylemon.conf"):
logger.error("abort pylemon because of failure during config parse")
exit(1)
monitor = Monitor(config)
monitor.watch_config()
monitor.run()
示例2: main
# 需要导入模块: from monitor import Monitor [as 别名]
# 或者: from monitor.Monitor import run [as 别名]
def main():
parser = argparse.ArgumentParser(description='Monitor an http access log')
parser.add_argument('filename', help='path to the log file')
parser.add_argument('-f', '--frequency', type=int, help='tail frequency, in s')
parser.add_argument('-o', '--once', action='store_true',
help='run once then exit (i.e. don\'t tail)')
args = parser.parse_args()
monitor = Monitor(args.filename)
try:
monitor.run(tail=not args.once, frequency=args.frequency or DEFAULT_FREQUENCY)
except (KeyboardInterrupt, SystemExit):
print 'HTTP Log Monitor finished'
示例3: bench
# 需要导入模块: from monitor import Monitor [as 别名]
# 或者: from monitor.Monitor import run [as 别名]
def bench(args):
config_dir = '{0}/{1}'.format(args.dir, args.bench_name)
brname = args.bench_name + '-br'
ip = IPRoute()
ctn_intfs = flatten((l.get_attr('IFLA_IFNAME') for l in ip.get_links() if l.get_attr('IFLA_MASTER') == br) for br in ip.link_lookup(ifname=brname))
if not args.repeat:
# currently ctn name is same as ctn intf
# TODO support proper mapping between ctn name and intf name
for ctn in ctn_intfs:
dckr.remove_container(ctn, force=True) if ctn_exists(ctn) else None
if os.path.exists(config_dir):
shutil.rmtree(config_dir)
else:
for ctn in ctn_intfs:
if ctn != 'tester':
dckr.remove_container(ctn, force=True) if ctn_exists(ctn) else None
if args.file:
with open(args.file) as f:
conf = yaml.load(f)
else:
conf = gen_conf(args)
if not os.path.exists(config_dir):
os.makedirs(config_dir)
with open('{0}/scenario.yaml'.format(config_dir), 'w') as f:
f.write(yaml.dump(conf))
if len(conf['tester']) > gc_thresh3():
print 'gc_thresh3({0}) is lower than the number of peer({1})'.format(gc_thresh3(), len(conf['tester']))
print 'type next to increase the value'
print '$ echo 16384 | sudo tee /proc/sys/net/ipv4/neigh/default/gc_thresh3'
if args.target == 'gobgp':
target = GoBGP
elif args.target == 'bird':
target = BIRD
elif args.target == 'quagga':
target = Quagga
is_remote = True if 'remote' in conf['target'] and conf['target']['remote'] else False
if is_remote:
r = ip.get_routes(dst=conf['target']['local-address'].split('/')[0], family=AF_INET)
if len(r) == 0:
print 'no route to remote target {0}'.format(conf['target']['local-address'])
sys.exit(1)
idx = [t[1] for t in r[0]['attrs'] if t[0] == 'RTA_OIF'][0]
intf = ip.get_links(idx)[0]
if intf.get_attr('IFLA_MASTER') not in ip.link_lookup(ifname=brname):
br = ip.link_lookup(ifname=brname)
if len(br) == 0:
ip.link_create(ifname=brname, kind='bridge')
br = ip.link_lookup(ifname=brname)
br = br[0]
ip.link('set', index=idx, master=br)
else:
print 'run', args.target
if args.image:
target = target(args.target, '{0}/{1}'.format(config_dir, args.target), image=args.image)
else:
target = target(args.target, '{0}/{1}'.format(config_dir, args.target))
target.run(conf, brname)
print 'run monitor'
m = Monitor('monitor', config_dir+'/monitor')
m.run(conf, brname)
time.sleep(1)
print 'waiting bgp connection between {0} and monitor'.format(args.target)
m.wait_established(conf['target']['local-address'].split('/')[0])
if not args.repeat:
print 'run tester'
t = Tester('tester', config_dir+'/tester')
t.run(conf, brname)
start = datetime.datetime.now()
q = Queue()
m.stats(q)
if not is_remote:
target.stats(q)
def mem_human(v):
if v > 1000 * 1000 * 1000:
return '{0:.2f}GB'.format(float(v) / (1000 * 1000 * 1000))
elif v > 1000 * 1000:
return '{0:.2f}MB'.format(float(v) / (1000 * 1000))
elif v > 1000:
return '{0:.2f}KB'.format(float(v) / 1000)
else:
return '{0:.2f}B'.format(float(v))
#.........这里部分代码省略.........
示例4: TCPServer
# 需要导入模块: from monitor import Monitor [as 别名]
# 或者: from monitor.Monitor import run [as 别名]
from SocketServer import TCPServer
except ImportError:
from socketserver import TCPServer
import threading
import sys
import os
import logging
from monitor import Monitor
from publishers import WebsocketPublisher
from connection import Connection
PORT = 80
if __name__ == "__main__":
logging.basicConfig(level=logging.WARN, filename="pyicemon.log")
# Serve static HTTP content.
os.chdir("static")
handler = SimpleHTTPRequestHandler
httpd = TCPServer(("", PORT), handler)
t = threading.Thread(target=httpd.serve_forever)
t.daemon = True
t.start()
# Fire up pyicemon.
host, port = sys.argv[1], sys.argv[2]
mon = Monitor(Connection(host, int(port)))
mon.addPublisher(WebsocketPublisher(port=9999))
mon.run()