Example #1
0
def main():
    """
    Main method.
    """
    
    if "config" in sys.argv:
        print format_multiline("""
            graph_title PostgreSql Database Running Queries
            graph_args -l 0
            graph_category postgresql
            running.label Number of running queries (including locked)
            running.type GAUGE
            granted_locks.label Number of granted locks
            granted_locks.type GAUGE
            non_granted_locks.label Number of tx waiting for locks
            non_granted_locks.type GAUGE
        """)
        return
    
    conn = connect()
    cursor = conn.cursor()
    cursor.execute("SELECT COUNT(*) FROM pg_stat_activity")
    running_count = cursor.fetchone()[0]
    
    cursor.execute("SELECT COUNT(*) FROM pg_locks WHERE granted IS TRUE")
    granted_locks = cursor.fetchone()[0]
    
    cursor.execute("SELECT COUNT(*) FROM pg_locks WHERE granted IS FALSE")
    non_granted_locks = cursor.fetchone()[0]
    
    print "running.value %d" % running_count
    print "granted_locks.value %d" % granted_locks
    print "non_granted_locks.value %d" % non_granted_locks
Example #2
0
def main():
    """
    Main method.
    """
    conn = connect()
    cursor = conn.cursor()
    
    if "config" in sys.argv:

        print format_multiline("""
            graph_title PostgreSql Database Size (on disk)
            graph_args --base 1024 -l 0 --vertical-label Bytes --upper-limit 3719946240
            graph_category postgresql
        """)
    
    for db_name in get_dbs_to_monitor(cursor):
        cursor.execute("SELECT pg_database_size(%s)", [db_name])
        db_size = cursor.fetchall()[0][0]
        
        if "config" in sys.argv:
            print format_multiline("""
                %(db_name)s.label %(db_name)s
                %(db_name)s.type GAUGE
            """ % { 'db_name': db_name })
        else:
            print "%s.value %d" % (db_name, db_size, )
def main():
    """
    Main method.
    """
    conn = connect()
    cursor = conn.cursor()

    if "config" in sys.argv:
        # graph_args -l 0 --vertical-label Tx --base 1000
        # graph_vlabel (+) commits / (-) rollbacks per seccond
        print format_multiline(
            """
            graph_title PostgreSql Commits and Rollbacks
            graph_category postgresql
        """
        )

    dbs_to_monitor = get_dbs_to_monitor(cursor)

    cursor.execute("SELECT datname, datid, xact_commit, xact_rollback FROM pg_stat_database " + "ORDER BY datname")

    for datname, datid, xact_commit, xact_rollback in cursor.fetchall():  # pylint: disable=W0612

        if not datname in dbs_to_monitor:
            continue

        var_commit = "%s_ct" % datname
        var_rb = "%s_rb" % datname
        if "config" in sys.argv:
            print format_multiline(
                """
                %(var_commit)s.label %(db_name)s commits
                %(var_commit)s.draw LINE
                %(var_commit)s.type DERIVE
                %(var_commit)s.min 0
                
                %(var_rb)s.label %(db_name)s rollbacks
                %(var_rb)s.draw LINE
                %(var_rb)s.type DERIVE
                %(var_rb)s.min 0
            """
                % {"db_name": datname, "var_commit": var_commit, "var_rb": var_rb}
            )

        else:
            print format_multiline(
                """
                %(var_commit)s.value %(xact_commit)d
                %(var_rb)s.value %(xact_rollback)d
            """
                % {
                    "db_name": datname,
                    "xact_commit": xact_commit,
                    "xact_rollback": xact_rollback,
                    "var_commit": var_commit,
                    "var_rb": var_rb,
                }
            )
Example #4
0
def main():
    """
    Main method.
    """
    conn = connect()
    cursor = conn.cursor()

    if "config" in sys.argv:
        # graph_args -l 0 --vertical-label Tx --base 1000
        # graph_vlabel (+) commits / (-) rollbacks per seccond
        print format_multiline("""
            graph_title PostgreSql Commits and Rollbacks
            graph_category postgresql
        """)

    dbs_to_monitor = get_dbs_to_monitor(cursor)

    cursor.execute("SELECT datname, datid, xact_commit, xact_rollback FROM pg_stat_database " + \
        "ORDER BY datname")

    for datname, datid, xact_commit, xact_rollback in cursor.fetchall():  # pylint: disable=W0612

        if not datname in dbs_to_monitor:
            continue

        var_commit = "%s_ct" % datname
        var_rb = "%s_rb" % datname
        if "config" in sys.argv:
            print format_multiline("""
                %(var_commit)s.label %(db_name)s commits
                %(var_commit)s.draw LINE
                %(var_commit)s.type DERIVE
                %(var_commit)s.min 0
                
                %(var_rb)s.label %(db_name)s rollbacks
                %(var_rb)s.draw LINE
                %(var_rb)s.type DERIVE
                %(var_rb)s.min 0
            """ % {
                'db_name': datname,
                'var_commit': var_commit,
                'var_rb': var_rb
            })

        else:
            print format_multiline(
                """
                %(var_commit)s.value %(xact_commit)d
                %(var_rb)s.value %(xact_rollback)d
            """ % {
                    'db_name': datname,
                    'xact_commit': xact_commit,
                    'xact_rollback': xact_rollback,
                    'var_commit': var_commit,
                    'var_rb': var_rb
                })
Example #5
0
def main():
    """
    Main method.
    """
    conn = connect()
    cursor = conn.cursor()

    if "config" in sys.argv:
        # graph_args -l 0 --vertical-label Tx --base 1000
        # graph_vlabel (+) commits / (-) rollbacks per seccond
        print format_multiline("""
            graph_title PostgreSql Number of tuples managed
            graph_category postgresql
        """)

    dbs_to_monitor = get_dbs_to_monitor(cursor)

    cursor.execute("SELECT datname, datid, tup_returned, tup_fetched, tup_inserted, " + \
        "tup_updated, tup_deleted FROM pg_stat_database ORDER BY datname")

    for datname, datid, tup_returned, tup_fetched, tup_inserted, tup_updated, tup_deleted in \
            cursor.fetchall(): # pylint: disable=W0612

        if not datname in dbs_to_monitor:
            continue

        if "config" in sys.argv:
            for report_type in [
                    'tup_returned', 'tup_fetched', 'tup_inserted',
                    'tup_updated', 'tup_deleted'
            ]:
                print format_multiline("""
                    %(db_name)s_%(report_type)s.label %(db_name)s %(report_type)s
                    %(db_name)s_%(report_type)s.draw LINE
                    %(db_name)s_%(report_type)s.type DERIVE
                    %(db_name)s_%(report_type)s.min 0
                """ % {
                    'db_name': datname,
                    'report_type': report_type,
                })
        else:
            print format_multiline(
                """
                %(db_name)s_tup_returned.value %(tup_returned)d
                %(db_name)s_tup_fetched.value %(tup_fetched)d
                %(db_name)s_tup_inserted.value %(tup_inserted)d
                %(db_name)s_tup_updated.value %(tup_updated)d
                %(db_name)s_tup_deleted.value %(tup_deleted)d
            """ % {
                    'db_name': datname,
                    'tup_returned': tup_returned,
                    'tup_fetched': tup_fetched,
                    'tup_inserted': tup_inserted,
                    'tup_updated': tup_updated,
                    'tup_deleted': tup_deleted
                })
def main():
    """
    Main method.
    """
    conn = connect()
    cursor = conn.cursor()
    
    if "config" in sys.argv:

        print format_multiline("""
            graph_title PostgreSql Block IO
            graph_args --base 1000 -l 0
            graph_category postgresql
        """)
    
    # Do this BEFORE cursor.execute(...)!!!
    dbs_to_monitor = get_dbs_to_monitor(cursor)
    
    cursor.execute("SELECT datid, datname, blks_read, blks_hit FROM pg_stat_database" + \
        " ORDER BY datname")
    
    first = True
    for datid, datname, blks_read, blks_hit in cursor.fetchall(): # pylint: disable=W0612
        
        if not datname in dbs_to_monitor:
            continue
        
        # AFTER the continue...
        if "config" in sys.argv:
            print format_multiline("""
                %(db_name)s_read.label %(db_name)s block reads
                %(db_name)s_read.type DERIVE
                %(db_name)s_read.min 0
                %(db_name)s_read.draw LINE
                
                %(db_name)s_hit.label %(db_name)s buffer hits
                %(db_name)s_hit.type DERIVE
                %(db_name)s_hit.min 0
                %(db_name)s_hit.draw LINE
            """ % { 'db_name': datname, })
        else:
            print format_multiline("""
                %(db_name)s_read.value %(read)d
                %(db_name)s_hit.value %(hit)d
            """ % { 'db_name': datname, 'read': blks_read, 'hit': blks_hit})
def main():
    """
    Main method.
    """
    conn = connect()
    cursor = conn.cursor()
    
    if "config" in sys.argv:
        # graph_args -l 0 --vertical-label Tx --base 1000
        # graph_vlabel (+) commits / (-) rollbacks per seccond
        print format_multiline("""
            graph_title PostgreSql Number of tuples managed
            graph_category postgresql
        """)
    
    dbs_to_monitor = get_dbs_to_monitor(cursor)
    
    cursor.execute("SELECT datname, datid, tup_returned, tup_fetched, tup_inserted, " + \
        "tup_updated, tup_deleted FROM pg_stat_database ORDER BY datname")
    
    for datname, datid, tup_returned, tup_fetched, tup_inserted, tup_updated, tup_deleted in \
            cursor.fetchall(): # pylint: disable=W0612
        
        if not datname in dbs_to_monitor:
            continue
        
        if "config" in sys.argv:
            for report_type in [ 'tup_returned', 'tup_fetched', 'tup_inserted', 'tup_updated',
                    'tup_deleted']:
                print format_multiline("""
                    %(db_name)s_%(report_type)s.label %(db_name)s %(report_type)s
                    %(db_name)s_%(report_type)s.draw LINE
                    %(db_name)s_%(report_type)s.type DERIVE
                    %(db_name)s_%(report_type)s.min 0
                """ % { 'db_name': datname, 'report_type': report_type, })
        else:
            print format_multiline("""
                %(db_name)s_tup_returned.value %(tup_returned)d
                %(db_name)s_tup_fetched.value %(tup_fetched)d
                %(db_name)s_tup_inserted.value %(tup_inserted)d
                %(db_name)s_tup_updated.value %(tup_updated)d
                %(db_name)s_tup_deleted.value %(tup_deleted)d
            """ % { 'db_name': datname, 'tup_returned': tup_returned, 'tup_fetched': tup_fetched,
                'tup_inserted': tup_inserted, 'tup_updated': tup_updated,
                'tup_deleted': tup_deleted })