def get_response(self): m = Monitor() c = Chart() cpu_info = m.cpu() mem_info = m.mem() swap_info = m.swap() net_info = m.net() disk_info = m.disk() net_pie = [ c.pie_two_html( "net{}".format(k + 1), "{}网卡信息".format(v["name"]), "收发包数统计", "收发字节统计", ["收包数", "发包数"], ["收字节", "发字节"], [v["packets_recv"], v["packets_sent"]], [v["bytes_recv"], v["bytes_sent"]], ) for k, v in enumerate(net_info) if v["packets_recv"] and v['packets_sent'] ] self.html("index.html", data=dict( title="系统监控", cpu_info=cpu_info, mem_info=mem_info, swap_info=swap_info, net_info=net_info, disk_info=disk_info, cpu_liquid=c.liquid_html("cpu_avg", "CPU平均使用率", cpu_info['percent_avg']), mem_gauge=c.gauge_html("mem", "内存使用率", mem_info['percent']), swap_gauge=c.gauge_html("swap", "交换分区使用率", mem_info['percent']), net_pie=net_pie, ) )
def on_message(self, message): try: m = Monitor() data = dict() if message == "system": data = dict(mem=m.mem(), swap=m.swap(), cpu=m.cpu(), disk=m.disk(), net=m.net(), dt=m.dt()) RealTimeHandler.send_updates(json.dumps(data)) except Exception as e: print(e)
def on_message(self, message): try: m = Monitor() data = dict() if message == "system": data = dict(mem=m.mem(), swap=m.swap(), cpu=m.cpu(), disk=m.disk(), net=m.net(), dt=m.dt()) # 对消息进行处理,把新的消息推送到所有连接的客户端 self.broadcast(self.waiters, json.dumps(data)) # 广播 except Exception as e: print(e)
def get(self): # self.write('<h1>硬件实时监控系统</h1>') c = Chart() # 生成图对象 m = Monitor() # 获取系统信息对象 # CPU信息 cpu_info = m.cpu() # 内存信息 mem_info = m.mem() # 交换分区信息 swap_info = m.swap() # 网络信息 net_info = m.net() net_pie = [ c.pie_two_html(chart_id="net{}".format(k + 1), title="{}网卡信息".format(v['name']), sub_title1='收发包数统计', sub_title2='收发字节统计', key1=['收包数', '发包数'], value1=[v['packets_recv'], v['packets_sent']], key2=['收字节数', '发字节数'], value2=[v['bytes_recv'], v['bytes_sent']]) for k, v in enumerate(net_info) if v['packets_recv'] and v['packets_sent'] ] # 磁盘信息 disk_info = m.disk() self.render('index.html', data=dict( title='系统监控', cpu_liquid=c.liquid_html('cpu_avg', 'CPU平均使用率', cpu_info['percent_avg']), cpu_info=cpu_info, mem_gauge=c.gauge_html('mem', '内存使用率', mem_info['percent']), mem_info=mem_info, swap_gauge=c.gauge_html('swap', '交换分区使用率', swap_info['percent']), swap_info=swap_info, net_pie=net_pie, net_info=net_info, disk_info=disk_info, ))
async def get(self): # 实例化系统信息类 monitor = Monitor() # 实例化可视化图表类 chart = Chart() # CPU信息 cpu_info = monitor.cpu() # 内存信息 mem_info = monitor.mem() # 交换分区 swap_info = monitor.swap() # 网络信息 net_info = monitor.net() # 磁盘信息 disk_info = monitor.disk() # 网络信息 net_pie = [ chart.pie_two_html( "net{}".format(k + 1), "{}网卡信息".format(v["name"]), "收发包数统计", "收发字节统计", ["收包数", "发包数"], ["收字节", "发字节"], [v["packets_recv"], v["packets_sent"]], [v["bytes_recv"], v["bytes_sent"]], ) for k, v in enumerate(net_info) if v["packets_recv"] and v['packets_sent'] ] # 渲染视图 self.render( "index.html", data=dict( title="系统监控", cpu_info=cpu_info, mem_info=mem_info, swap_info=swap_info, net_info=net_info, disk_info=disk_info, cpu_liquid=chart.liquid_html("cpu_avg", "CPU平均使用率", cpu_info['percent_avg']), mem_gauge=chart.gauge_html("mem", "内存使用率", mem_info['percent']), swap_gauge=chart.gauge_html("swap", "交换分区使用率", mem_info['percent']), net_pie=net_pie, ) )
def on_message(self, message): """接收消息""" try: m = Monitor() data = dict() if message == 'system': data = dict( mem=m.mem(), swap=m.swap(), cpu=m.cpu(), disk=m.disk(), net=m.net(), dt=m.dt() ) # pprint(data) # 接收消息并处理,把新消息发给所有客户端 self.broadcast(self.waiters, json.dumps(data)) # 广播 except Exception as e: print(e)
def get_response(self): # self.write("<h1>我们要开发一个硬件实时监控系统</h1>") m = Monitor() c = Chart() cpu_info = m.cpu() mem_info = m.mem() swap_info = m.swap() net_info = m.net() disk_info = m.disk() # print(cpu_info) net_pie = [ c.pie_two_html( "net{}".format(k + 1), "{}网卡信息".format(v["name"]), "收发包数统计", "收发字节统计", ["收包数", "发包数"], ["收字节", "发字节"], [v["packets_recv"], v["packets_sent"]], [v["bytes_recv"], v["bytes_sent"]], ) for k, v in enumerate(net_info) if v["packets_recv"] and v["packets_sent"] # 只接收有收包数和发包数的网卡信息 ] # 这里我们在views_common.py的CommonHandler里面重载的render方法:html self.html("index.html", data=dict( title="系统监控", cpu_info=cpu_info, mem_info=mem_info, swap_info=swap_info, net_info=net_info, disk_info=disk_info, cpu_liquid=c.liquid_html("cpu_avg", "CPU平均使用率", cpu_info["percent_avg"]), mem_gauge=c.gauge_html("mem", "内存使用率", mem_info["percent"]), swap_gauge=c.gauge_html("swap", "交换分区使用率", swap_info["percent"]), net_pie=net_pie, ))