"Fossies" - the Fresh Open Source Software Archive

Member "dstat-0.7.4/plugins/dstat_mysql5_io.py" (17 Jan 2019, 1966 Bytes) of package /linux/privat/dstat-0.7.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "dstat_mysql5_io.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 0.7.3_vs_0.7.4.

    1 ### Author: <lefred$inuits,be>
    2 
    3 global mysql_user
    4 mysql_user = os.getenv('DSTAT_MYSQL_USER') or os.getenv('USER')
    5 
    6 global mysql_pwd
    7 mysql_pwd = os.getenv('DSTAT_MYSQL_PWD')
    8 
    9 global mysql_host
   10 mysql_host = os.getenv('DSTAT_MYSQL_HOST')
   11 
   12 global mysql_port
   13 mysql_port = os.getenv('DSTAT_MYSQL_PORT')
   14 
   15 global mysql_socket
   16 mysql_socket = os.getenv('DSTAT_MYSQL_SOCKET')
   17 
   18 class dstat_plugin(dstat):
   19     """
   20     Plugin for MySQL 5 I/O.
   21     """
   22 
   23     def __init__(self):
   24         self.name = 'mysql5 io'
   25         self.nick = ('recv', 'sent')
   26         self.vars = ('Bytes_received', 'Bytes_sent')
   27 
   28     def check(self): 
   29         global MySQLdb
   30         import MySQLdb
   31         try:
   32             args = {}
   33             if mysql_user:
   34                 args['user'] = mysql_user
   35             if mysql_pwd:
   36                 args['passwd'] = mysql_pwd
   37             if mysql_host:
   38                 args['host'] = mysql_host
   39             if mysql_port:
   40                 args['port'] = mysql_port
   41             if mysql_socket:
   42                 args['unix_socket'] = mysql_socket
   43 
   44             self.db = MySQLdb.connect(**args)
   45         except:
   46             raise Exception('Cannot interface with MySQL server')
   47 
   48     def extract(self):
   49         try:
   50             c = self.db.cursor()
   51             c.execute("""show global status like 'Bytes_%';""")
   52             lines = c.fetchall()
   53             for line in lines:
   54                 if len(line[1]) < 2: continue
   55                 if line[0] in self.vars:
   56                     if line[0] + 'raw' in self.set2:
   57                         self.set2[line[0]] = float(line[1]) - self.set2[line[0] + 'raw']
   58                     self.set2[line[0] + 'raw'] = float(line[1])
   59 
   60             for name in self.vars:
   61                 self.val[name] = self.set2[name] * 1.0 / elapsed
   62 
   63             if step == op.delay:
   64                 self.set1.update(self.set2)
   65 
   66         except Exception as e:
   67             for name in self.vars:
   68                 self.val[name] = -1
   69 
   70 # vim:ts=4:sw=4:et