bin/metric-postgres-locks.rb in sensu-plugins-postgres-1.3.0 vs bin/metric-postgres-locks.rb in sensu-plugins-postgres-1.4.0

- old
+ new

@@ -26,15 +26,22 @@ # Author Gilles Devaux <gilles.devaux@gmail.com> # Released under the same terms as Sensu (the MIT license); see LICENSE # for details. # +require 'sensu-plugins-postgres/pgpass' require 'sensu-plugin/metric/cli' require 'pg' require 'socket' class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite + option :pgpass, + description: 'Pgpass file', + short: '-f FILE', + long: '--pgpass', + default: ENV['PGPASSFILE'] || "#{ENV['HOME']}/.pgpass" + option :user, description: 'Postgres User', short: '-u USER', long: '--user USER' @@ -44,24 +51,21 @@ long: '--password PASS' option :hostname, description: 'Hostname to login to', short: '-h HOST', - long: '--hostname HOST', - default: 'localhost' + long: '--hostname HOST' option :port, description: 'Database port', short: '-P PORT', - long: '--port PORT', - default: 5432 + long: '--port PORT' option :database, description: 'Database name', short: '-d DB', - long: '--db DB', - default: 'postgres' + long: '--db DB' option :scheme, description: 'Metric naming scheme, text to prepend to $queue_name.$metric', long: '--scheme SCHEME', default: "#{Socket.gethostname}.postgresql" @@ -70,14 +74,16 @@ description: 'Connection timeout (seconds)', short: '-T TIMEOUT', long: '--timeout TIMEOUT', default: nil + include Pgpass + def run timestamp = Time.now.to_i locks_per_type = Hash.new(0) - + pgpass con = PG.connect(host: config[:hostname], dbname: config[:database], user: config[:user], password: config[:password], port: config[:port],