bin/metric-postgres-graphite.rb in sensu-plugins-postgres-0.1.1 vs bin/metric-postgres-graphite.rb in sensu-plugins-postgres-1.0.0

- old
+ new

@@ -68,20 +68,23 @@ description: 'Database port', short: '-P PORT', long: '--port PORT', default: 5432 - def run - @dbmaster = config[:master_host] - @dbslave = config[:slave_host] - @dbport = config[:port] - @dbname = config[:database] - @dbusername = config[:user] - @password = config[:pass] + option :timeout, + description: 'Connection timeout (seconds)', + short: '-T TIMEOUT', + long: '--timeout TIMEOUT', + default: nil + def run # Establishing connections to the master - conn_master = PGconn.connect(@dbmaster, @dbport, '', '', @dbname, @dbusername, @password) + conn_master = PG.connect(host: config[:master_host], + dbname: config[:database], + user: config[:user], + password: config[:password], + connect_timeout: config[:timeout]) res1 = conn_master.exec('SELECT pg_current_xlog_location()').getvalue(0, 0) m_segbytes = conn_master.exec('SHOW wal_segment_size').getvalue(0, 0).sub(/\D+/, '').to_i << 20 conn_master.close def lag_compute(res1, res, m_segbytes) # rubocop:disable NestedMethodDefinition @@ -89,10 +92,14 @@ s_segment, s_offset = res.split(/\//) ((m_segment.hex - s_segment.hex) * m_segbytes) + (m_offset.hex - s_offset.hex) end # Establishing connections to the slave - conn_slave = PGconn.connect(@dbslave, @dbport, '', '', @dbname, @dbusername, @password) + conn_slave = PG.connect(host: config[:slave_host], + dbname: config[:database], + user: config[:user], + password: config[:password], + connect_timeout: config[:timeout]) res = conn_slave.exec('SELECT pg_last_xlog_receive_location()').getvalue(0, 0) conn_slave.close # Compute lag lag = lag_compute(res1, res, m_segbytes)