author | Radek Brich <radek.brich@devl.cz> |
Mon, 17 Dec 2012 16:48:12 +0100 | |
changeset 56 | 94e091c23ebb |
parent 44 | 4fe39c59c515 |
child 73 | 390376b9e70f |
permissions | -rwxr-xr-x |
2 | 1 |
#!/usr/bin/env python3.2 |
2 |
||
9
2fcc8ef0b97d
Reorganize again :-) Add setup.py.
Radek Brich <radek.brich@devl.cz>
parents:
7
diff
changeset
|
3 |
from pgtoolkit import pgstats, toolbase |
44
4fe39c59c515
Update longqueries tool: add client IP, waiting attributes.
Radek Brich <radek.brich@devl.cz>
parents:
39
diff
changeset
|
4 |
from pgtoolkit.highlight import highlight, YELLOW, BOLD |
2 | 5 |
|
6 |
||
7
685b20d2d3ab
Reorganize directories. PgDataDiff - reworked. PgManager - add fetchone_adapted, fetchall_adapted to cursor.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
7 |
class LongQueriesTool(toolbase.SimpleTool): |
2 | 8 |
def __init__(self): |
7
685b20d2d3ab
Reorganize directories. PgDataDiff - reworked. PgManager - add fetchone_adapted, fetchall_adapted to cursor.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
9 |
toolbase.SimpleTool.__init__(self, name='longqueries', desc='List long queries.') |
2 | 10 |
self.init() |
11 |
||
12 |
def main(self): |
|
13 |
stats = pgstats.PgStats(self.pgm.get_conn('target')) |
|
14 |
||
39 | 15 |
for ln in stats.list_long_queries('1m'): |
44
4fe39c59c515
Update longqueries tool: add client IP, waiting attributes.
Radek Brich <radek.brich@devl.cz>
parents:
39
diff
changeset
|
16 |
print(highlight(1), |
4fe39c59c515
Update longqueries tool: add client IP, waiting attributes.
Radek Brich <radek.brich@devl.cz>
parents:
39
diff
changeset
|
17 |
'backend PID: ', ln['procpid'], |
4fe39c59c515
Update longqueries tool: add client IP, waiting attributes.
Radek Brich <radek.brich@devl.cz>
parents:
39
diff
changeset
|
18 |
', query_start: ', ln['query_start'].strftime('%F %T'), |
4fe39c59c515
Update longqueries tool: add client IP, waiting attributes.
Radek Brich <radek.brich@devl.cz>
parents:
39
diff
changeset
|
19 |
', client IP: ', ln['client_addr'], |
4fe39c59c515
Update longqueries tool: add client IP, waiting attributes.
Radek Brich <radek.brich@devl.cz>
parents:
39
diff
changeset
|
20 |
ln['waiting'] and ', ' + highlight(1, YELLOW|BOLD) + 'waiting' or '', |
4fe39c59c515
Update longqueries tool: add client IP, waiting attributes.
Radek Brich <radek.brich@devl.cz>
parents:
39
diff
changeset
|
21 |
highlight(0), sep='') |
2 | 22 |
print(ln['query']) |
5 | 23 |
print() |
2 | 24 |
|
25 |
||
26 |
tool = LongQueriesTool() |
|
27 |
tool.main() |
|
28 |