def getConnectionStats ( self ) : cur = self . _conn . cursor ( ) cur . execute ( """SELECT datname,numbackends FROM pg_stat_database;""" ) rows = cur . fetchall ( ) if rows : return dict ( rows ) else : return { }
python check number of connections of mysql
Returns dictionary with number of connections for each database .
def getConnectionStats(self):
        """Returns dictionary with number of connections for each database.
        
        @return: Dictionary of database connection statistics.
        
        """
        cur = self._conn.cursor()
        cur.execute("""SELECT datname,numbackends FROM pg_stat_database;""")
        rows = cur.fetchall()
        if rows:
            return dict(rows)
        else:
            return {}