flask+mysql+highcharts监控内存
来源:互联网 发布:mac app store创建id 编辑:程序博客网 时间:2024/05/23 02:03
agent.py
# -*- coding:utf-8 -*-import timeimport pymysqlconn = 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 / 1024if __name__ =="__main__": while True: time.sleep(3) getMem()
monitor.py
# -*- coding:utf-8 -*-from flask import Flask,render_template,requestimport pymysqlimport jsonconn = 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
阅读全文
0 0
- flask+mysql+highcharts监控内存
- flask + mysql + highcharts(动态刷新)实现的简单监控系统
- (3)使用Highcharts开发JVM监控内存
- highcharts内存泄漏
- flask+ highcharts实现报表转换成趋势图(1)
- flask+ highcharts实现报表转换成趋势图(2)
- highcharts 内存泄露的解决
- 使用highcharts实现实时监控曲线图
- Flask连MySQL数据库
- Flask连接MYSQL
- Python--Flask+MySQL
- flask-mysql配置
- Flask使用mysql数据库
- flask 配置mysql数据库
- python flask mysql-python
- 内存监控
- 使用Python和Flask编写Prometheus监控
- MySQL监控
- 如何利用HTTP技术提升网页的加载速度
- splunk学习笔记——安装说明
- 利用GBDT模型构造新特征
- esxi
- Mybatis源码学习笔记(四) 配置详解之typeAliases
- flask+mysql+highcharts监控内存
- LoadRunner中如何对用户名、密码同时参数化
- 安卓测试小工具
- 技术博客004
- nutch和solr
- scrapy中文手册笔记(一)
- Android Studio安装及配置过程中出现的问题
- sql里的 DML语法结构
- Android启动过程深入解析