Skip to content

Commit 72ac9b5

Browse files
author
unknown
committed
exemples + readme
1 parent b51a44d commit 72ac9b5

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ test.py
99
__pycache__
1010
.gitignore
1111
output*
12-
monitor_usage_examples.py

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ The ids are displayed using any of the other instructions
5050

5151
**Note** : the previously shown arguments arguments can be used simultaneously. Therefor the following instruction is valid :<br/>
5252
`[authentification string] mostUsed longestTimeOnAverage mostRowsReturnedAccumulated 10`<br/>
53-
It will display just the queries for `mostUsed`, `longestTimeOnAverage` and `mostRowsReturnedAccumulated` one after an other
53+
It will display just the queries for `mostUsed`, `longestTimeOnAverage` and `mostRowsReturnedAccumulated` one after an other<br/>
54+
Using the same argument twice will not display it twice
5455

5556
**Note** : the queries that are used by this program are not displayed by default. See the configurations variables to display them
5657

monitor.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,10 @@ def print_query_from_id(self, argv):
233233
return False
234234
buff = "\n"
235235
buff += " =========\n"
236-
buff += "displaying query of queryid " + argv[1] + "\n"
236+
buff += "displaying query of queryid " + str(argv[1]) + "\n"
237237
buff += " =========\n"
238238
buff += "\n"
239-
self.cursor.execute("SELECT query FROM pg_stat_statements WHERE queryid = %s", (int(argv[1]),))
239+
self.cursor.execute("SELECT query FROM pg_stat_statements WHERE queryid = %s", (str(argv[1]),))
240240
res = self.cursor.fetchall()
241241
if len(res) == 0:
242242
buff += "Error : there is no queries matching that id"

monitor_usage_examples.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from monitor import Monitor
2+
3+
# these arguments send the arguments directly
4+
5+
# you need to put in the right values to be able to correctly connect to your database
6+
authentication_string = "dbname=tests user=postgres password=pswd host=127.0.0.1 port=5432"
7+
8+
# example to get the 10 queries that have the longest average time and the 10 queries that have longest accumulated time
9+
# + display the queries used by the Monitor class
10+
# + display ALL queries
11+
monitor = Monitor()
12+
monitor.displayUsedQueries = True # display the queries used by the program to get it's information
13+
monitor.useIgnore = False # display ALL queries
14+
monitor.run(authentication_string, 'longestTimeOnAverage', 'longestTimeAccumulated', 10)
15+
16+
# example to display the 10 most used queries
17+
# + ignore only BEGIN, COMMIT and pg_stat_statements
18+
# + do not write to file
19+
monitor = Monitor()
20+
monitor.ignore = [ # ignore only BEGIN and COMMIT
21+
"BEGIN",
22+
"COMMIT",
23+
"pg_stat_statements"
24+
]
25+
monitor.writeToFile = False # do not write to a file
26+
monitor.run(authentication_string, 'mostUsed', 10)
27+
28+
# example to display a query
29+
monitor = Monitor()
30+
monitor.run(authentication_string, 19846765274300731) # this id will need to be replaced with an id as display by the Monitor class from your database in order to work

0 commit comments

Comments
 (0)