Commits

Wil Tan  committed 10f2db4

report BIND memory stats

  • Participants
  • Parent commits bccb331

Comments (0)

Files changed (4)

 source "http://rubygems.org"
 gem "newrelic_plugin"
-
+gem "nokogiri"
 2. Extract to the location you want to run the BIND agent from
 3. Copy `config/template_newrelic_plugin.yml` to `config/newrelic_plugin.yml`
 4. Edit `config/newrelic_plugin.yml` and replace "YOUR_LICENSE_KEY_HERE" with your New Relic license key
-5. Create a plugin in New Relic
-6. Edit `newrelic_bind_agent` and replace "PUT YOUR GUID HERE" with the GUID that was generated when you created the plugin
 7. run `./newrelic_bind_agent`

File config/template_newrelic_plugin.yml

 agents:
   # this is where configuration for agents belongs
   bind:
-    hertz: 300
+    stats_url: http://127.0.0.1:80/

File newrelic_bind_agent

 #! /usr/bin/env ruby
 
 #
-# This is an example agent which generates synthetic data.
-# A 1mHz (one cycle every 16 minutes) sin+1, cos+1 and sin+5 wave is generated,
-# using the Unix epoch as the base.
+# 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 ExampleAgent
+module BindAgent
 
   class Agent < NewRelic::Plugin::Agent::Base
 
-    agent_guid "_TYPE_YOUR_GUID_HERE_"
-    agent_version "1.0.1"
-    agent_config_options :hertz  # frequency of the periodic functions
-    agent_human_labels("Example Agent") { "Synthetic example data" }
+    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
-      x = Time.now.to_f * hertz * Math::PI * 2
-      report_metric "SIN",     "Value", Math.sin(x) + 1.0
-      report_metric "COS",     "Value", Math.cos(x) + 1.0
-      report_metric "BIASSIN", "Value", Math.sin(x) + 5.0
+      puts "fetching " + stats_url
+      uri = URI.parse(stats_url)
+      response = Net::HTTP.get_response(uri)
+      doc = Nokogiri::XML(response.body)
+      puts "got response " + response.code
+
+      doc.xpath('/isc/bind/statistics/memory/summary/*').each do |node|
+        puts "sending metric " + node.name + " = " +  node.text
+        report_metric node.name, "Value", node.text.to_i
+      end
     end
 
   end
 
   #
   # Register this agent with the component.
-  # The ExampleAgent is the name of the module that defines this
+  # 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 :example, ExampleAgent
+  NewRelic::Plugin::Setup.install_agent :bind, BindAgent
 
   #
   # Launch the agent; this never returns.