sensu-plugins-chrony 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 61897a11958c84be26ba2c26c6f6b0adc179069d
4
- data.tar.gz: 9adfdeeb69502f704a852237c6629bafc083a1aa
3
+ metadata.gz: fbee417370232667d4b3b9edf97326b3ee60fd5d
4
+ data.tar.gz: 9e62f3fd51ea37044e82dd75ff6a7a8928743eed
5
5
  SHA512:
6
- metadata.gz: 9b3c7b14b75c7fff195b33240384630b2857bb38fe55dbed9e17353e3b3568f177ebba2dcdc50b1ffb7b08e27b377c326d0568f809f0aa14c026e7bd9e3a15a2
7
- data.tar.gz: 91321d38af52a4a405b217601c4b92f7d6e212418115f29bb908a677ecf4a9be7207d5d9b4b9e07129769676f9f8ee8405051ff02ddf18bd04faf50ee59cb85f
6
+ metadata.gz: 7fd93d42abd56f7c88f92c588ada85dcc04d068d5b92edf2bd2479eded00391b2aa48b52a0f4e14c2bf9d15d7e46bd96f3a77d6bd11266359ad824dafe8ee194
7
+ data.tar.gz: c6397e9073a5d2dd832b22c3b7fb8cb726d498de4f8b8781575584a382fb9d400d06a972caf5ed89725e4a2678f8a389534562be492058764b7ceb36feb2b513
@@ -34,7 +34,7 @@ class ChronyMetrics < Sensu::Plugin::Metric::CLI::Graphite
34
34
  description: 'Metric naming scheme, text to prepend to metric',
35
35
  short: '-s SCHEME',
36
36
  long: '--scheme SCHEME',
37
- default: Socket.gethostname
37
+ default: "#{Socket.gethostname}.chronystats"
38
38
 
39
39
  def run
40
40
  # #YELLOW
@@ -42,39 +42,34 @@ class ChronyMetrics < Sensu::Plugin::Metric::CLI::Graphite
42
42
  config[:scheme] = config[:host]
43
43
  end
44
44
 
45
- chronystats = get_chronystats(config[:host])
45
+ chronystats = get_chronystats
46
46
  critical "Failed to get chronycstats from #{config[:host]}" if chronystats.empty?
47
47
  metrics = {
48
- chronystats: chronystats
48
+ config[:scheme] => chronystats
49
49
  }
50
50
  metrics.each do |name, stats|
51
51
  stats.each do |key, value|
52
- output([config[:scheme], name, key].join('.'), value)
52
+ output([name, key].join('.'), value)
53
53
  end
54
54
  end
55
55
  ok
56
56
  end
57
57
 
58
- def get_chronystats(host)
59
- key_pattern = Regexp.compile(
60
- [
61
- "Stratum",
62
- "Last offset",
63
- "RMS offset",
64
- "Frequency",
65
- "Residual freq",
66
- "Skew",
67
- "Root delay",
68
- "Root dispersion",
69
- "Update interval"
70
- ].join('|'))
71
- num_val_pattern = /[\-\+]?[\d]+(\.[\d]+)?/
72
- pattern = /^(#{key_pattern})\s*:\s*(#{num_val_pattern}).*$/
58
+ def get_chronystats
59
+ num_val_pattern = /^[-+]?\d+(\.\d+)?\s/
73
60
 
74
- `chronyc tracking`.scan(pattern).reduce({}) do |hash, parsed|
75
- key, val, fraction = parsed
76
- hash[key.downcase.tr(" ", "_")] = fraction ? val.to_f : val.to_i
61
+ `chronyc tracking`.each_line.reduce({}) do |hash, line|
62
+ key, val = line.split(/\s*:\s*/)
63
+ matched = val.match(num_val_pattern) || (next hash)
64
+ number, fraction = matched.to_a
65
+ number = fraction ? number.to_f : number.to_i
66
+ number = - number if /slow/ =~ val # for system time
67
+ hash[snakecase(key)] = number
77
68
  hash
78
69
  end
79
70
  end
71
+
72
+ def snakecase(str)
73
+ str.downcase.tr(' ', '_').gsub(/[()]/, '')
74
+ end
80
75
  end
@@ -2,7 +2,7 @@ module SensuPluginsChrony
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- PATCH = 9
5
+ PATCH = 10
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-chrony
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matteo Cerutti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-05 00:00:00.000000000 Z
11
+ date: 2016-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-plugin