Class: Riemann::Tools::Ntp

Inherits:
Object
  • Object
show all
Includes:
Riemann::Tools
Defined in:
lib/riemann/tools/ntp.rb

Constant Summary

Constants included from Riemann::Tools

VERSION

Instance Attribute Summary

Attributes included from Riemann::Tools

#argv

Instance Method Summary collapse

Methods included from Riemann::Tools

#attributes, #endpoint_name, included, #options, #report, #riemann, #run

Constructor Details

#initializeNtp

Returns a new instance of Ntp.



11
12
13
14
15
16
17
# File 'lib/riemann/tools/ntp.rb', line 11

def initialize
  super

  @hostname = `hostname`.chomp
  @ostype = `uname -s`.chomp.downcase
  abort 'WARNING: macOS not explicitly supported. Exiting.' if @ostype == 'darwin'
end

Instance Method Details

#send(type, metric) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/riemann/tools/ntp.rb', line 32

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

#tickObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/riemann/tools/ntp.rb', line 19

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