Sha256: dcf86cde6a1453b35e1ec0d898c7ae14fb80cdec334e5f37a515429ebafce9e3

Contents?: true

Size: 829 Bytes

Versions: 8

Compression:

Stored size: 829 Bytes

Contents

#!/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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
riemann-tools-0.2.14 bin/riemann-ntp
riemann-tools-0.2.13 bin/riemann-ntp
riemann-tools-0.2.11 bin/riemann-ntp
riemann-tools-0.2.10 bin/riemann-ntp
riemann-tools-0.2.9 bin/riemann-ntp
riemann-tools-0.2.8 bin/riemann-ntp
riemann-tools-0.2.7 bin/riemann-ntp
riemann-tools-0.2.6 bin/riemann-ntp