#!/usr/bin/env python #_*_coding:utf8 _*_ import MySQLdb import datetime #qps #!/usr/bin/env python import MySQLdb import time from influxdb import InfluxDBClient def getInfluxdb(): client=InfluxDBClient(host='192.168.15.104', port=8086, username='admin', password='root123', database='mysql15104') return client def get_cur(): conn=MySQLdb.connect(host="192.168.30.103",user="dlan",passwd="root123",port=3307,db="test",charset='utf8') conn.select_db("test") cur=conn.cursor() return cur def get_mysql_status(cursor): data=cursor.execute('show global status;'); data_list=cursor.fetchall() data_dict={} for item in data_list: data_dict[item[0]] = item[1] return data_dict def getQPS(cursor): first_status=get_mysql_status(cursor) time.sleep(1) second_status=get_mysql_status(cursor) qps=int(second_status['Com_select'])-int(first_status['Com_select']) return qps if __name__=='__main__': while True: cur=get_cur() aa=getQPS(cur) print aa date=int(time.time()) json_body = [ { "measurement":'wangyuan', "tags":{ "host": "mycat", "time":date }, "fields":{ "qps":aa } } ] print json_body
MySQL_qps
原创
©著作权归作者所有:来自51CTO博客作者DBAspace的原创作品,请联系作者获取转载授权,否则将追究法律责任
下一篇:MySQL_tps
![](https://ucenter.51cto.com/images/noavatar_middle.gif)
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
MySQL及MySQL Workbench下载与安装
安装MySQLworkbench以及环境配置的详细教程
mysql MySQL MySQLworkbench