Module: ZabbixRubyClient::Plugins::Postgres

Extended by:
Postgres
Included in:
Postgres
Defined in:
lib/zabbix-ruby-client/plugins/postgres.rb

Instance Method Summary collapse

Instance Method Details

#collect(*args) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/zabbix-ruby-client/plugins/postgres.rb', line 8

def collect(*args)
  host = args[0]
  psqlargs = args[1]
  dbname = args[2]
  # be sure to have this in the config file
  # args: [ "-U username -h localhost", "dbname" ]
  # and setup username in a ~/.pgpass (0600) file for the zrc user
  # localhost:5432:dbname:username:password
  psqlstatus = `psql #{psqlargs} -A -t -c "select * from pg_stat_database where datname='#{dbname}'" #{dbname}`
  if $?.to_i == 0
    status = get_status(psqlstatus)
  else
    Log.warn "The connection failed."
    return []
  end

  time = Time.now.to_i
  back = []
  status.each do |e,v|
    back << "#{host} postgres.#{e}[#{dbname}] #{time} #{v}"
  end
  return back
end

#discover(*args) ⇒ Object



32
33
34
35
# File 'lib/zabbix-ruby-client/plugins/postgres.rb', line 32

def discover(*args)
  dbname = args[1]
  [ "postgres.db.discovery", "{\"{#DBNAME}\": \"#{dbname}\"}" ]
end

#get_status(status) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/zabbix-ruby-client/plugins/postgres.rb', line 37

def get_status(status)
  ret = {}
  els = status.split "|"
  ret["numbackends"] = els[2]
  ret["xact_commit"] = els[3]
  ret["xact_rollback"] = els[4]
  ret["blks_read"] = els[5]
  ret["blks_hit"] = els[6]
  ret["tup_returned"] = els[7]
  ret["tup_fetched"] = els[8]
  ret["tup_inserted"] = els[9]
  ret["tup_updated"] = els[10]
  ret["tup_deleted"] = els[11]
  ret["conflicts"] = els[12]
  ret["temp_files"] = els[13]
  ret["temp_bytes"] = els[14]
  ret["deadlocks"] = els[15]
  ret["blk_read_time"] = els[16]
  ret["blk_write_time"] = els[17]
  ret
end