Class: Dexter::PgStatActivityParser
Constant Summary
Constants inherited
from LogParser
LogParser::REGEX
Constants included
from Logging
Logging::COLOR_CODES
Instance Method Summary
collapse
Methods inherited from LogParser
#initialize
Methods included from Logging
#colorize, #log, #output
Instance Method Details
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/dexter/pg_stat_activity_parser.rb', line 3
def perform
previous_queries = {}
10.times do
active_queries = {}
processed_queries = {}
stat_activity.each do |row|
if row["state"] == "active"
active_queries[row["id"]] = row
else
process_entry(row["query"], row["duration_ms"].to_f)
processed_queries[row["id"]] = true
end
end
previous_queries.each do |id, row|
if !active_queries[id] && !processed_queries[id]
process_entry(row["query"], row["duration_ms"].to_f)
end
end
previous_queries = active_queries
sleep(0.1)
end
end
|
#stat_activity ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/dexter/pg_stat_activity_parser.rb', line 32
def stat_activity
sql = " SELECT\n pid || ':' || COALESCE(query_start, xact_start) AS id,\n query,\n state,\n EXTRACT(EPOCH FROM NOW() - COALESCE(query_start, xact_start)) * 1000.0 AS duration_ms\n FROM\n pg_stat_activity\n WHERE\n datname = current_database()\n AND pid != pg_backend_pid()\n ORDER BY\n 1\n SQL\n @logfile.send(:execute, sql)\nend\n"
|