1. Vladimir Rusinov
  2. ztc

Commits

Vladimir Rusinov  committed 9cf2761

pep8 fixes

  • Participants
  • Parent commits 95ef26c
  • Branches default

Comments (0)

Files changed (4)

File src/ztc/pgsql/pgcluster.py

View file
 #!/usr/bin/env python
-#pylint: disable=W0232
+#pylint: disable-msg=W0232
 """PgCluster ZTCCheck
 Used to perform database-wide checks (like querying each database of the
 cluster)
         otta = 0
         bloatest = []  # list of bloatest tables
         ret = self.query_eachdb(query, exclude=['template0'])
-        for db in ret.keys():
+        for db in ret.keys():  # pylint:disable-msg=C0103
             # loop through all databases
-            for r in ret[db]:
+            for table in ret[db]:
                 # and its tables
-                pages += r[4]
-                otta += r[5]
+                pages += table[4]
+                otta += table[5]
                 if pages > 1000:
                     # add to list of bloatest tables
                     bloat = 100 - 100 * (pages - otta) / pages
-                    item = (bloat, "%s.%s.%s->%s" % (db, r[0], r[1], r[2]))
+                    item = (bloat, "%s.%s.%s->%s" % (db, table[0], table[1],
+                                                     table[2]))
                     if len(bloatest) < 5:
                         heapq.heappush(bloatest, item)
                     else:
                         heapq.heapreplace(bloatest, item)
         self.logger.debug("pages: %i, otta: %i" % (pages, otta))
+
+        # print out list of tables with higest bloat
         while len(bloatest):
-            b = heapq.heappop(bloatest)
-            self.logger.debug("bloatest: %s: %.2f%%" % (b[1], 100 - b[0]))
+            table = heapq.heappop(bloatest)
+            self.logger.debug("bloatest: %s: %.2f%%" % (table[1],
+                                                        100 - table[0]))
         if pages < 5000:  # cluster < then 40 Mb is no serious
             return 0
         else:
 
     # lower-level functions
     def get_dblist(self):
+        """ Get list of all databases
+
+        Returns: list of strings - names of all databases of postgresql
+            cluster
+        """
         connect_dict = {
             'host': self.config.get('host', None),  # none = connect via socket
             'user': self.config.get('user', 'postgres'),
             'password': self.config.get('password', None),
             'database': self.config.get('database', 'postgres')}
-        d = PgConn(connect_dict, self.logger)
-        dbs = d.query("SELECT datname FROM pg_database")
+        db = PgConn(connect_dict, self.logger)  # pylint: disable-msg=C0103
+        dbs = db.query("SELECT datname FROM pg_database")
         self.dbs = [x[0] for x in dbs]
 
     def query_eachdb(self, sql, exclude=None):
         ret = {}
         if not self.dbs:
             self.get_dblist()
-        for db in self.dbs:
+        for db in self.dbs:  # pylint: disable-msg=C0103
             if db in exclude:
                 continue
             connect_dict['database'] = db

File src/ztc/pgsql/pgconn.py

View file
 
 import psycopg2 as pg
 
+
 class PgConn(object):
-    dbh = None # database handler
-    cur = None # database cursor
+    dbh = None  # database handler
+    cur = None  # database cursor
 
     def __init__(self, connect_dict, logger):
         self.logger = logger

File src/ztc/pgsql/pgdb.py

View file
             'host': self.config.get('host', None),  # none = connect via socket
             'user': self.config.get('user', 'postgres'),
             'password': self.config.get('password', None),
-            'database': self.config.get('database', 'postgres')
-        }
+            'database': self.config.get('database', 'postgres')}
         self.dbconn = PgConn(connect_dict, self.logger)
 
     def _get(self, metric, *args, **kwargs):

File src/ztc/pgsql/queries.py

View file
           'dirty': "SELECT COUNT(*) FROM pg_buffercache WHERE isdirty='t'",
           'used': """SELECT COUNT(*) FROM pg_buffercache
                 WHERE reldatabase IS NOT NULL;""",
-           'total': "SELECT count(*) FROM pg_buffercache"
-          }
+           'total': "SELECT count(*) FROM pg_buffercache"}
 
 # number of connections
 CONN_NUMBER = {