在/usr/shared/dstat目录下dstat_mysql5_conn.py中的部分源代码
c = self.db.cursor() c.execute("""show global variables like ‘max_connections‘;""") max = c.fetchone() c.execute("""show global status like ‘Threads_connected‘;""") thread = c.fetchone() if thread[0] in self.vars: self.set2[thread[0]] = float(thread[1]) self.set2[‘Threads‘] = float(thread[1] / float(max[1]) 1.0 * 100)
print type(max[1]) ,type(thread[1])
<type ‘str‘> <type ‘str‘>
调试下,从数据库中获取到的数据(数字) 是str 所以
self.set2[‘Threads‘] = float(thread[1] / float(max[1]) 1.0 * 100) --是str[thread[1]]/float[float(max[1])
修改这段代码为
self.set2[‘Threads‘] = float(float(thread[1]) / float(max[1]) * 100)
#!/bin/bash #file:mysql5conn.sh export DSTAT_MYSQL_USER=‘user‘ export DSTAT_MYSQL_PWD=‘pwd‘ dstat --mysql5-conn $@
[root@shylock ~]# ./mysql5io.sh 1 10 mysql5-co ThCo %Con 0.00 0.00 1.00 0.66 1.00 0.66 1.00 0.66 1.00 0.66 1.00 0.66 1.00 0.66 1.00 0.66 1.00 0.66 1.00 0.66 1.00 0.66
dstat mysql5-conn,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/jachin/p/3855376.html