class Riemann::Tools::PostgreSQLQuery
Public Class Methods
new()
click to toggle source
# File bin/riemann-postgresql-query, line 19 def initialize begin @conn = PG.connect(:host => opts[:postgresql_host], :port => opts[:postgresql_port], :user => opts[:postgresql_username], :password => opts[:postgresql_password], :dbname => opts[:postgresql_database]) rescue PG::Error puts "Error: Unable to connect with PostgreSQL server." exit 1 end end
Public Instance Methods
tick()
click to toggle source
# File bin/riemann-postgresql-query, line 33 def tick query = opts[:query] @conn.transaction do results = @conn.exec(query) result = results.to_a.first if result # Iterate through cols result.each do |key, value| data = { :host => opts[:postgresql_host].dup, :service => "#{opts[:service]}-#{key}", :metric => value.to_f, :state => 'ok', :description => query, :tags => ['postgresql'] } report(data) end end end end