#!/usr/bin/env python# coding=utf-8import timeimport sysimport osimport Mysqldbconn = 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) &NBSp; 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 ()
This article is from the "My Operations Blog" blog, be sure to keep this source http://linuxpython.blog.51cto.com/10015972/1643779
MYSQL-QPS Statistics Python script (query throughput per second)