首页 > 代码库 > dstat mysql5-conn

dstat mysql5-conn

在/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.shexport DSTAT_MYSQL_USER=userexport DSTAT_MYSQL_PWD=pwddstat --mysql5-conn $@
[root@shylock ~]# ./mysql5io.sh  1 10mysql5-coThCo %Con0.00 0.001.00 0.661.00 0.661.00 0.661.00 0.661.00 0.661.00 0.661.00 0.661.00 0.661.00 0.661.00 0.66