码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2015-05-07 17:07:11      阅读:959      评论:0      收藏:0      [点我收藏+]

标签:mysql

#!/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脚本(每秒查询处理量)

标签:mysql

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!