longqueries.py
changeset 5 57cf8fdff5ed
parent 2 efee419b7a2d
child 7 685b20d2d3ab
equal deleted inserted replaced
4:80634cb1c65b 5:57cf8fdff5ed
     1 #!/usr/bin/env python3.2
     1 #!/usr/bin/env python3.2
     2 
     2 
     3 from pgtools import pgstats
     3 from pgtools import pgstats
     4 from toolbase import ToolBase
     4 from toolbase import SimpleTool
     5 
     5 
     6 
     6 
     7 class LongQueriesTool(ToolBase):
     7 class LongQueriesTool(SimpleTool):
     8     def __init__(self):
     8     def __init__(self):
     9         ToolBase.__init__(self, name='longqueries', desc='Lis long queries.')
     9         SimpleTool.__init__(self, name='longqueries', desc='List long queries.')
    10         self.init()
    10         self.init()
    11 
    11 
    12     def main(self):
    12     def main(self):
    13         stats = pgstats.PgStats(self.pgm.get_conn('target'))
    13         stats = pgstats.PgStats(self.pgm.get_conn('target'))
    14 
    14 
    15         for ln in stats.list_long_queries():
    15         for ln in stats.list_long_queries():
    16             print(ln['query'])
    16             print(ln['query'])
    17             print('   ', 'query_start:', ln['query_start'].strftime('%F %T'))
    17             print('   ', 'query_start:', ln['query_start'].strftime('%F %T'))
       
    18             print()
    18 
    19 
    19 
    20 
    20 tool = LongQueriesTool()
    21 tool = LongQueriesTool()
    21 tool.main()
    22 tool.main()
    22 
    23