Skip to content

Commit

Permalink
Merge pull request #108 from jamtur01/ntp
Browse files Browse the repository at this point in the history
Added NTP statistics collector
  • Loading branch information
gsandie committed Feb 17, 2015
2 parents 2030221 + b76c395 commit 97bbd1b
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 97bbd1b

Please sign in to comment.