longqueries.py
changeset 73 390376b9e70f
parent 44 4fe39c59c515
child 83 515fadd3d286
equal deleted inserted replaced
72:539c2dd47f3b 73:390376b9e70f
     5 
     5 
     6 
     6 
     7 class LongQueriesTool(toolbase.SimpleTool):
     7 class LongQueriesTool(toolbase.SimpleTool):
     8     def __init__(self):
     8     def __init__(self):
     9         toolbase.SimpleTool.__init__(self, name='longqueries', desc='List long queries.')
     9         toolbase.SimpleTool.__init__(self, name='longqueries', desc='List long queries.')
       
    10         self.parser.add_argument('--age', default='1m', help='How long must be the query running to be listed.')
    10         self.init()
    11         self.init()
    11 
    12 
    12     def main(self):
    13     def main(self):
    13         stats = pgstats.PgStats(self.pgm.get_conn('target'))
    14         stats = pgstats.PgStats(self.pgm.get_conn('target'))
    14 
    15 
    15         for ln in stats.list_long_queries('1m'):
    16         for ln in stats.list_long_queries(self.args.age):
    16             print(highlight(1),
    17             print(highlight(1),
    17                   'backend PID: ', ln['procpid'],
    18                   'backend PID: ', ln['procpid'],
    18                   ', query_start: ', ln['query_start'].strftime('%F %T'),
    19                   ', query_start: ', ln['query_start'].strftime('%F %T'),
    19                   ', client IP: ', ln['client_addr'],
    20                   ', client IP: ', ln['client_addr'],
    20                   ln['waiting'] and ', ' + highlight(1, YELLOW|BOLD) + 'waiting' or '',
    21                   ln['waiting'] and ', ' + highlight(1, YELLOW|BOLD) + 'waiting' or '',