flask+mysql+highcharts监控内存
2017-06-09 17:19
99 查看
agent.py
# -*- coding:utf-8 -*- import time import pymysql conn = pymysql.connect(host='127.0.0.1',user='root',password='osyunwei',db='memory') conn.autocommit(True) cur = conn.cursor() def getMem(): with open('/proc/meminfo') as f: total = int(f.readline().split()[1]) free = int(f.readline().split()[1]) available = f.readline() buffers = int(f.readline().split()[1]) cache = int(f.readline().split()[1]) mem_use = total - free - buffers - cache t = int(time.time()) sql = 'insert into memory(memory,time) values(%s,%s)' %(mem_use/1024,t) cur.execute(sql) print mem_use / 1024 if __name__ =="__main__": while True: time.sleep(3) getMem()
monitor.py
# -*- coding:utf-8 -*- from flask import Flask,render_template,request import pymysql import json conn = pymysql.connect(host='127.0.0.1',user='root',password='osyunwei',db='memory') conn.autocommit(True) cur = conn.cursor() app = Flask(__name__) @app.route('/') def index(): return render_template('index.html') @app.route('/data/') def data(): sql = 'select memory,time from memory' cur.execute(sql) arr = [] for i in cur.fetchall(): arr.append([i[1] * 1000, i[0]]) return json.dumps(arr) if __name__ == "__main__": app.run(host='0.0.0.0',port=8888,debug=True)
index.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>内存监控</title> </head> <body> <div id="container" style="min-width:400px;height:400px;"></div> <script src="/static/jquery.js"></script> <script src="/static/highstock.js"></script> <script src="/static/exporting.js"></script> <script> $(function () { Highcharts.setOptions({ global: { useUTC: false } }); $.getJSON('/data', function (data) { $('#container').highcharts('StockChart', { rangeSelector : { selected : 1 }, title : { text : 'memory data' }, series : [{ name : 'memory', data : data, }] }); }); }); </script> </body> </html>
目录结构
. ├── agent.py ├── monitor.py ├── static │ ├── exporting.js │ ├── highstock.js │ └── jquery.js └── templates └── index.html
相关文章推荐
- flask + mysql + highcharts(动态刷新)实现的简单监控系统
- How-to: 使用 highcharts + MySQL 构建自己的简易网站监控系统
- 用Python的Flask框架结合MySQL写一个内存监控程序
- nagios监控mysql(check_mysql)及内存使用率(check_mem) 推荐
- zabbix用low level discovery监控磁盘吞吐量与iops zabbix监控nginx,php-fpm和mysql占用内存和进程个数
- flask+ highcharts实现报表转换成趋势图(2)
- Highcharts+PHP+Mysql生成饼状统计图
- 使用Flask结合python实现多台服务的内存监控
- JQUERY HighCharts 内存增长太快 大家看看怎么回事
- mysql 5.7 内存使用监控
- zabbix通过自定义脚本监控nginx,php-fpm和mysql占用内存数和进程的个数
- PHP+mysql+Highcharts生成饼状图
- PHP+mysql+Highcharts实现饼状统计图
- flask+ highcharts实现报表转换成趋势图(1)
- Highcharts Stock 实时图表监控JS
- zabbix通过自定义脚本监控nginx,php-fpm和mysql占用内存数和进程的个数
- PHP+mysql+Highcharts实现饼状统计图
- 使用python编写一个监控使用内存并使用flask模块出图
- mysql 5.7 内存使用监控
- flask+ highcharts实现报表转换成趋势图(3)----python使用csv像sql一样