riemann-tools 0.2.8 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/riemann-proc +65 -6
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 210cb204200a12c61ba5387331a58d573a4cf004
4
- data.tar.gz: a06f02966d09ba2009d19331da18c91f4e237f2f
3
+ metadata.gz: 028a34582916278f0704c6830fb1accc1fe940e9
4
+ data.tar.gz: 995651768195d973c5be15c0998e3c2e0be52237
5
5
  SHA512:
6
- metadata.gz: c61c8d015c9a1a494ab7e2311cd80d5a774eb1c089f5a2ca891b797aa7c2a4021fe4523f365c97256bfdbae3e6e781f5cafde649271e61fac90eb12b752650bf
7
- data.tar.gz: 70a6995d1ce99d458b009ec94e28f4b417bfa14f24eeb2862b1073abb48100ec3f0799c70466b99347e6639d6d656367648ac3ff450d5b77558757d38f31db53
6
+ metadata.gz: 1271ec7e1c3269784a68cf39c64dbe55a5a845c82a06c8fe6afe5a1377a115df023ee248882a33db26642e0fd0e7406126db49b36797ec5914b26a041869f1ab
7
+ data.tar.gz: 009f079f02ed9e54f57adf2940b710e7c1905c53f99c8704e9647bcddde4aa890944d4c8c92b4bb091da39ad07b4d09aa61865dfc53deb0f7aa17f5a40faac21
@@ -7,9 +7,9 @@ require File.expand_path('../../lib/riemann/tools', __FILE__)
7
7
  class Riemann::Tools::Proc
8
8
  include Riemann::Tools
9
9
 
10
- opt :proc_regex, "regular expression that matches the process to be monitored", type: :string
11
- opt :proc_min_critical, "running process count minimum", :default => 1
12
- opt :proc_max_critical, "running process count maximum", :default => 1
10
+ opt :proc_regex, "regular expression that matches the process to be monitored", type: :string, :default => ".*"
11
+ opt :proc_min_critical, "running process count minimum", :default => 0
12
+ opt :proc_max_critical, "running process count maximum", :default => 65536
13
13
 
14
14
  def initialize
15
15
  @limits = { :critical => { :min => opts[:proc_min_critical], :max => opts[:proc_max_critical] } }
@@ -32,12 +32,71 @@ class Riemann::Tools::Proc
32
32
 
33
33
  def linux_proc
34
34
  process = opts[:proc_regex]
35
- found = `ps axo args | grep '#{process}' | grep -v grep | grep -v riemann-proc`
35
+ found = `ps axo pid=,rss=,vsize=,state=,cputime=,lstart=,command= | grep '#{process}' | grep -v grep | grep -v riemann-proc`
36
36
  running = found.count("\n")
37
37
  if running > @limits[:critical][:max] or running < @limits[:critical][:min]
38
- alert "proc #{process}", :critical, running, "process #{process} is running #{running} instances:\n" + found
38
+ alert "proc count/#{process}", :critical, running, "process #{process} is running #{running} instances.\n"
39
39
  else
40
- alert "proc #{process}", :ok, running, "process #{process} is running #{running} instances:\n" + found
40
+ alert "proc count/#{process}", :ok, running, "process #{process} is running #{running} instances.\n"
41
+ end
42
+ # Iterate on all the lines and create an entry for the following metrics:
43
+ #
44
+ # process/<pid>-<start-time>/rss
45
+ # process/<pid>-<start-time>/vsize
46
+ # process/<pid>-<start-time>/running
47
+ # process/<pid>-<start-time>/cputime
48
+ #
49
+ # description should contain the command itself.
50
+ # value should be either process RSS, VSIZE, or 1 if running
51
+ # state is always unknown for the moment
52
+ #
53
+ ps_regex = /([0-9]+)[ ]+([0-9]+)[ ]+([0-9]+)[ ]+([A-Z])[ ]+([0-9:.]+)[ ]+[A-Za-z]{3}[ ]+([A-Za-z]{3} [0-9]+ [0-9:]+ [0-9]+)[ ]+(.*)/
54
+ found.each_line do |line|
55
+ m = ps_regex.match(line)
56
+ if not m.nil?
57
+ pid, rss, vsize, state, cputime, start, command = m.captures
58
+ start_s = DateTime.parse(start, "Mmm DD HH:MM:ss YYYY").to_time.to_i
59
+ cputime_s = DateTime.parse(cputime, "%H:%M:%S")
60
+ cputime_seconds = (cputime_s.hour * 3600) + (cputime_s.minute * 60) + cputime_s.second
61
+ running = 0
62
+ case state[0]
63
+ when "R"
64
+ state_s = "ok"
65
+ running = 1
66
+ when "S"
67
+ state_s = "ok"
68
+ when "I"
69
+ state_s = "warning"
70
+ when "T", "U", "Z"
71
+ state_s = "critical"
72
+ else
73
+ state_s = "unknown"
74
+ end
75
+ report(
76
+ :service => "proc #{pid}-#{start_s}/rss",
77
+ :state => state_s.to_s,
78
+ :metric => rss.to_f,
79
+ :description => command,
80
+ )
81
+ report(
82
+ :service => "proc #{pid}-#{start_s}/vsize",
83
+ :state => state_s.to_s,
84
+ :metric => vsize.to_f,
85
+ :description => command,
86
+ )
87
+ report(
88
+ :service => "proc #{pid}-#{start_s}/running",
89
+ :state => state_s.to_s,
90
+ :metric => running.to_f,
91
+ :description => command,
92
+ )
93
+ report(
94
+ :service => "proc #{pid}-#{start_s}/cputime",
95
+ :state => state_s.to_s,
96
+ :metric => cputime_seconds,
97
+ :description => command,
98
+ )
99
+ end
41
100
  end
42
101
  end
43
102
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riemann-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Kingsbury
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-09 00:00:00.000000000 Z
11
+ date: 2016-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: riemann-client