Skip to content

Commit

Permalink
Added NTP statistics collector
Browse files Browse the repository at this point in the history
The collector uses ntpq to list the NTP peers.

It then returns the delay, offset and jitter for each to Riemann.
  • Loading branch information
jamtur01 committed Feb 17, 2015
1 parent 2030221 commit b76c395
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions bin/riemann-ntp
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b76c395

Please sign in to comment.