Sha256: 615ed93c77deb0a61e1f54c1da7d15c794221708d7a73bf8b963b0c156aeca26

Contents?: true

Size: 1013 Bytes

Versions: 13

Compression:

Stored size: 1013 Bytes

Contents

# frozen_string_literal: true

require 'riemann/tools'

# Reports NTP stats to Riemann.
module Riemann
  module Tools
    class Ntp
      include Riemann::Tools

      def initialize
        @hostname = `hostname`.chomp
        @ostype = `uname -s`.chomp.downcase
        abort 'WARNING: macOS not explicitly supported. Exiting.' if @ostype == 'darwin'
      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
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
riemann-tools-1.10.0 lib/riemann/tools/ntp.rb
riemann-tools-1.9.1 lib/riemann/tools/ntp.rb
riemann-tools-1.9.0 lib/riemann/tools/ntp.rb
riemann-tools-1.8.2 lib/riemann/tools/ntp.rb
riemann-tools-1.8.1 lib/riemann/tools/ntp.rb
riemann-tools-1.8.0 lib/riemann/tools/ntp.rb
riemann-tools-1.7.1 lib/riemann/tools/ntp.rb
riemann-tools-1.7.0 lib/riemann/tools/ntp.rb
riemann-tools-1.6.0 lib/riemann/tools/ntp.rb
riemann-tools-1.5.0 lib/riemann/tools/ntp.rb
riemann-tools-1.4.0 lib/riemann/tools/ntp.rb
riemann-tools-1.3.0 lib/riemann/tools/ntp.rb
riemann-tools-1.2.0 lib/riemann/tools/ntp.rb