首页 > 数据库技术 > 详细

mysql-qps统计python脚本(每秒查询处理量)

时间:2015-05-07 17:06:50      阅读:295      评论:0      收藏:0      [点我收藏+]
#!/usr/bin/env python
# coding=utf-8
import time
import sys
import os
import MySQLdb
conn = MySQLdb.connect(host=‘127.0.0.1‘,port=3306,user=‘root‘,passwd=‘abc.123‘, charset=‘utf8‘)
conn.autocommit(True)
cursor=conn.cursor()
while True:
    diff = 1
    sql = "show global status where Variable_name in(‘com_select‘,‘com_insert‘,‘com_delete‘,‘com_update‘)"
    cursor.execute(sql)
    results = cursor.fetchall()
    first = []
    for rec in results:
        first.append(rec[1])
    time.sleep(diff)
    sql = "show global status where Variable_name in(‘com_select‘,‘com_insert‘,‘com_delete‘,‘com_update‘)"
    cursor.execute(sql)
    results = cursor.fetchall()
    second = []
    for rec in results:
        second.append(rec[1])
    qps = 0
    tps = 0
    for i in range(0, 4):
        if i != 0:
            b = int(second[i]) - int(first[i])
            tps += b
        a = int(second[i]) - int(first[i])
        qps += a
    print ‘qps = %s‘%(qps/diff)
    print ‘tps = %s‘%(tps/diff)
conn.close()


本文出自 “我的运维博客” 博客,请务必保留此出处http://linuxpython.blog.51cto.com/10015972/1643779

mysql-qps统计python脚本(每秒查询处理量)

原文:http://linuxpython.blog.51cto.com/10015972/1643779

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!