Skip to content

Commit

Permalink
Update plugins/dstat_mysql5_cmds.py
Browse files Browse the repository at this point in the history
  • Loading branch information
carlhu committed Sep 17, 2012
1 parent be86f47 commit fe5f916
Showing 1 changed file with 4 additions and 25 deletions.
29 changes: 4 additions & 25 deletions plugins/dstat_mysql5_cmds.py
Expand Up @@ -6,15 +6,6 @@
global mysql_pwd
mysql_pwd = os.getenv('DSTAT_MYSQL_PWD')

global mysql_host
mysql_host = os.getenv('DSTAT_MYSQL_HOST')

global mysql_port
mysql_port = os.getenv('DSTAT_MYSQL_PORT')

global mysql_socket
mysql_socket = os.getenv('DSTAT_MYSQL_SOCKET')

class dstat_plugin(dstat):
"""
Plugin for MySQL 5 commands.
Expand All @@ -31,19 +22,7 @@ def check(self):
global MySQLdb
import MySQLdb
try:
args = {}
if mysql_user:
args['user'] = mysql_user
if mysql_pwd:
args['passwd'] = mysql_pwd
if mysql_host:
args['host'] = mysql_host
if mysql_port:
args['port'] = mysql_port
if mysql_socket:
args['unix_socket'] = mysql_socket

self.db = MySQLdb.connect(**args)
self.db = MySQLdb.connect(user=mysql_user, passwd=mysql_pwd)
except Exception, e:
raise Exception, 'Cannot interface with MySQL server: %s' % e

Expand All @@ -54,7 +33,9 @@ def extract(self):
c.execute("""show global status like '%s';""" % name)
line = c.fetchone()
if line[0] in self.vars:
self.set2[line[0]] = long(line[1])
if line[0] + 'raw' in self.set2:
self.set2[line[0]] = long(line[1]) - self.set2[line[0] + 'raw']
self.set2[line[0] + 'raw'] = long(line[1])

for name in self.vars:
self.val[name] = self.set2[name] * 1.0 / elapsed
Expand All @@ -65,5 +46,3 @@ def extract(self):
except Exception, e:
for name in self.vars:
self.val[name] = -1

# vim:ts=4:sw=4:et

0 comments on commit fe5f916

Please sign in to comment.