Skip to content

Commit 8b9351a

Browse files
committed
Merge pull request #11 from slyness/connection_metrics
improve metrics for postgresql connections
2 parents df1a9b2 + 302c446 commit 8b9351a

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
44
This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
55

66
## [Unreleased]
7+
- Correctly evaluate and collect metrics for active connections and active connections waiting on backend locks
8+
- Add new metric `total`
79

810
## [0.1.0] - 2016-03-09
911
### Added

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 row['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)