-
Notifications
You must be signed in to change notification settings - Fork 0
/
newrelic_bind_agent
executable file
·83 lines (71 loc) · 2.51 KB
/
newrelic_bind_agent
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#! /usr/bin/env ruby
#
# An agent which extracts BIND statistics and report them to New Relic.
#
require "rubygems"
require "bundler/setup"
require "newrelic_plugin"
require "socket"
require 'nokogiri'
module BindAgent
class Agent < NewRelic::Plugin::Agent::Base
agent_guid "au.com.fairfax.bind_agent"
agent_version "1.0.0"
agent_config_options :stats_url # bind statistics channel url to v2 xml
agent_human_labels("BIND Agent") { Socket.gethostname }
def poll_cycle
#puts "fetching " + stats_url
uri = URI.parse(stats_url)
response = Net::HTTP.get_response(uri)
doc = Nokogiri::XML(response.body)
#doc = Nokogiri::XML(open('bindstats-kumo1.xml'))
#puts "got response " + response.code
doc.xpath('statistics/server/counters[@type="opcode"]/counter').each do |node|
metric = "Request/Opcode/#{node["name"]}"
val = node.text
puts "#{metric} = #{val}"
report_metric metric, "Value", val
end
doc.xpath('statistics/server/counters[@type="qtype"]/counter').each do |node|
metric = "QueryType/#{node["name"]}"
val = node.text
puts "#{metric} = #{val}"
report_metric metric, "Value", val
end
doc.xpath('statistics/server/counters[@type="nsstat"]/counter').each do |node|
metric = "NSStat/#{node["name"]}"
val = node.text
puts "#{metric} = #{val}"
report_metric metric, "Value", val
end
doc.xpath('statistics/server/counters[@type="zonestat"]/counter').each do |node|
metric = "ZoneStat/#{node["name"]}"
val = node.text
puts "#{metric} = #{val}"
report_metric metric, "Value", val
end
doc.xpath('statistics/server/counters[@type="sockstat"]/counter').each do |node|
metric = "SockStat/#{node["name"]}"
val = node.text
puts "#{metric} = #{val}"
report_metric metric, "Value", val
end
doc.xpath('statistics/memory/summary/*').each do |node|
metric = "Mem/#{node.name}"
puts "#{metric} = #{node.text.to_i}"
report_metric metric, "Value", node.text.to_i
end
end
end
#
# Register this agent with the component.
# The BindAgent is the name of the module that defines this
# driver (the module must contain at least three classes - a
# PollCycle, a Metric and an Agent class, as defined above).
#
NewRelic::Plugin::Setup.install_agent :bind, BindAgent
#
# Launch the agent; this never returns.
#
NewRelic::Plugin::Run.setup_and_run
end