Sha256: 07b754faa8f6ea9ce301aaea64f09a17ec7a2082e10462843548dad67fe849c7

Contents?: true

Size: 854 Bytes

Versions: 1

Compression:

Stored size: 854 Bytes

Contents

#!/usr/bin/env ruby
Process.setproctitle($0)

# 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

1 entries across 1 versions & 1 rubygems

Version Path
riemann-tools-1.0.0 bin/riemann-ntp