Skip to content

Commit 4639b11

Browse files
majormoseseheydrick
authored andcommitted
Fix/26 (#39)
* Fixed lock count collect I found bug on your source. You do not need to plus 1 when while syntax after add "group by" If you want get correct number need use count * add a CHANGELOG entry
1 parent c643728 commit 4639b11

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
55

66
## [Unreleased]
77

8+
### Fixed
9+
- metric-postgres-locks.rb: Fixed lock count collect (@madboxkr)
10+
811
## [1.4.1] - 2017-09-26
912
### Fixed
1013
- metrics-postgres-query.rb: Add a nil check to avoid failure when the query result is empty (@eheydrick)

bin/metric-postgres-locks.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ def run
9090
port: config[:port],
9191
connect_timeout: config[:timeout])
9292
request = [
93-
'SELECT mode, count(mode) FROM pg_locks',
94-
"where database = (select oid from pg_database where datname = '#{config[:database]}')",
95-
'group by mode'
93+
'SELECT mode, count(mode) AS count FROM pg_locks',
94+
"WHERE database = (SELECT oid FROM pg_database WHERE datname = '#{config[:database]}')",
95+
'GROUP BY mode'
9696
]
9797

9898
con.exec(request.join(' ')) do |result|
9999
result.each do |row|
100100
lock_name = row['mode'].downcase.to_sym
101-
locks_per_type[lock_name] += 1
101+
locks_per_type[lock_name] = row['count']
102102
end
103103
end
104104

0 commit comments

Comments
 (0)