Sha256: 028ea279d5b1fcea024122aa7dc2b3221b03856ada399b2a178ebb169394faf4

Contents?: true

Size: 1.23 KB

Versions: 64

Compression:

Stored size: 1.23 KB

Contents

require 'pg'

master = Rubber.instances.for_role('postgresql_master').first.full_name
slave = "localhost"
opts = { :dbname => Rubber.config.db_name,
         :user => Rubber.config.db_user,
         :password => Rubber.config.db_pass }
mconn = PGconn.open(opts.merge({:host => master}))
sconn = PGconn.open(opts.merge({:host => slave}))

mval = mconn.exec("select pg_current_xlog_location()")[0]["pg_current_xlog_location"]
sresult = sconn.exec("select pg_last_xlog_receive_location(), pg_last_xlog_replay_location()")[0]
sval_receive = sresult["pg_last_xlog_receive_location"]
sval_replay = sresult["pg_last_xlog_replay_location"]


def numeric(val)
  # First part is logid, second part is record offset
  parts = val.split("/")
  raise "Invalid location" if parts.size != 2 && parts.any {|p| p.to_s.strip.size == 0}
  result = (0xFFFFFFFF * parts[0].to_i) + parts[1].to_i(16)
  return result
end


master_offset = numeric(mval)
receive_offset = numeric(sval_receive)
replay_offset = numeric(sval_replay)

puts "PUTVAL #{HOSTNAME}/postgresql/gauge-replication_receive_delay interval=#{INTERVAL} N:#{master_offset - receive_offset}"
puts "PUTVAL #{HOSTNAME}/postgresql/gauge-replication_replay_delay interval=#{INTERVAL} N:#{master_offset - replay_offset}"

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
rubber-2.13.1 templates/collectd/script/collectd/role/postgresql_slave/replication_status.rb
rubber-2.13.0 templates/collectd/script/collectd/role/postgresql_slave/replication_status.rb
rubber-2.12.2 templates/collectd/script/collectd/role/postgresql_slave/replication_status.rb
rubber-2.12.1 templates/collectd/script/collectd/role/postgresql_slave/replication_status.rb
rubber-2.12.0 templates/collectd/script/collectd/role/postgresql_slave/replication_status.rb
rubber-2.11.0 templates/collectd/script/collectd/role/postgresql_slave/replication_status.rb
rubber-2.10.2 templates/collectd/script/collectd/role/postgresql_slave/replication_status.rb
rubber-2.10.1 templates/collectd/script/collectd/role/postgresql_slave/replication_status.rb
rubber-2.10.0 templates/collectd/script/collectd/role/postgresql_slave/replication_status.rb
rubber-2.9.0 templates/collectd/script/collectd/role/postgresql_slave/replication_status.rb
rubber-2.8.1 templates/collectd/script/collectd/role/postgresql_slave/replication_status.rb
rubber-2.8.0 templates/collectd/script/collectd/role/postgresql_slave/replication_status.rb
rubber-2.7.5 templates/collectd/script/collectd/role/postgresql_slave/replication_status.rb
rubber-2.7.4 templates/collectd/script/collectd/role/postgresql_slave/replication_status.rb
rubber-2.7.3 templates/collectd/script/collectd/role/postgresql_slave/replication_status.rb
rubber-2.7.2 templates/collectd/script/collectd/role/postgresql_slave/replication_status.rb
rubber-2.7.1 templates/collectd/script/collectd/role/postgresql_slave/replication_status.rb
rubber-2.7.0 templates/collectd/script/collectd/role/postgresql_slave/replication_status.rb
rubber-2.6.5 templates/collectd/script/collectd/role/postgresql_slave/replication_status.rb
rubber-2.6.4 templates/collectd/script/collectd/role/postgresql_slave/replication_status.rb