From b76c395b54c81b4ed7d6ea9e01bd8a5bf84638d8 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Mon, 16 Feb 2015 20:24:06 -0500 Subject: [PATCH] Added NTP statistics collector The collector uses ntpq to list the NTP peers. It then returns the delay, offset and jitter for each to Riemann. --- bin/riemann-ntp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 bin/riemann-ntp diff --git a/bin/riemann-ntp b/bin/riemann-ntp new file mode 100755 index 00000000..2c275e9a --- /dev/null +++ b/bin/riemann-ntp @@ -0,0 +1,38 @@ +#!/usr/bin/env ruby + +# Reports NTP stats to Riemann. + +require File.expand_path('../../lib/riemann/tools', __FILE__) + +class Riemann::Tools::Ntp + include Riemann::Tools + + def initialize + @hostname = `hostname`.chomp + end + + def tick + stats = `ntpq -p -n` + stats.each_line do |stat| + m = stat.split() + next if m.grep(/^===/).any? || m.grep(/^remote/).any? + @ntp_host = m[0].gsub("*","").gsub("-","").gsub("+","") + send("delay",m[7]) + send("offset",m[8]) + send("jitter",m[9]) + end + end + + def send(type,metric) + report( + :host => @hostname, + :service => "ntp peer #{@ntp_host} #{type}", + :metric => metric.to_f, + :state => "ok", + :description => "ntp peer #{@ntp_host} #{type}", + :tags => ["ntp"] + ) + end +end + +Riemann::Tools::Ntp.run