Skip to content

Commit eeff95f

Browse files
author
Aaron Baer
committed
determine more accurately which connections are active or waiting on lock and also produce new metric called total
1 parent df1a9b2 commit eeff95f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

bin/metric-postgres-connections.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,21 @@ def run
7777

7878
metrics = {
7979
active: 0,
80-
waiting: 0
80+
waiting: 0,
81+
total: 0
8182
}
8283
con.exec(request.join(' ')) do |result|
8384
result.each do |row|
84-
if row['waiting']
85+
if row['waiting'] == 't'
8586
metrics[:waiting] = row['count']
86-
else
87+
elsif role['waiting'] == 'f'
8788
metrics[:active] = row['count']
8889
end
8990
end
9091
end
9192

93+
metrics[:total] = (metrics[:waiting].to_i + metrics[:active].to_i)
94+
9295
metrics.each do |metric, value|
9396
output "#{config[:scheme]}.connections.#{config[:db]}.#{metric}", value, timestamp
9497
end

0 commit comments

Comments
 (0)