riemann-tools 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +11 -0
  3. data/.github/workflows/ci.yml +13 -0
  4. data/.github/workflows/codeql-analysis.yml +72 -0
  5. data/.rubocop.yml +32 -0
  6. data/CHANGELOG.md +31 -2
  7. data/README.markdown +8 -24
  8. data/Rakefile +4 -2
  9. data/SECURITY.md +42 -0
  10. data/bin/riemann-apache-status +92 -78
  11. data/bin/riemann-bench +54 -49
  12. data/bin/riemann-cloudant +44 -40
  13. data/bin/riemann-consul +82 -76
  14. data/bin/riemann-dir-files-count +53 -47
  15. data/bin/riemann-dir-space +53 -47
  16. data/bin/riemann-diskstats +78 -75
  17. data/bin/riemann-fd +68 -48
  18. data/bin/riemann-freeswitch +108 -103
  19. data/bin/riemann-haproxy +46 -40
  20. data/bin/riemann-health +4 -343
  21. data/bin/riemann-kvminstance +18 -13
  22. data/bin/riemann-memcached +35 -29
  23. data/bin/riemann-net +4 -104
  24. data/bin/riemann-nginx-status +74 -67
  25. data/bin/riemann-ntp +4 -33
  26. data/bin/riemann-portcheck +40 -31
  27. data/bin/riemann-proc +96 -90
  28. data/bin/riemann-varnish +51 -45
  29. data/bin/riemann-zookeeper +38 -34
  30. data/lib/riemann/tools/health.rb +347 -0
  31. data/lib/riemann/tools/net.rb +104 -0
  32. data/lib/riemann/tools/ntp.rb +41 -0
  33. data/lib/riemann/tools/version.rb +1 -1
  34. data/lib/riemann/tools.rb +37 -40
  35. data/riemann-tools.gemspec +4 -1
  36. data/tools/riemann-aws/{Rakefile.rb → Rakefile} +2 -0
  37. data/tools/riemann-aws/bin/riemann-aws-billing +72 -66
  38. data/tools/riemann-aws/bin/riemann-aws-rds-status +55 -41
  39. data/tools/riemann-aws/bin/riemann-aws-sqs-status +37 -31
  40. data/tools/riemann-aws/bin/riemann-aws-status +63 -51
  41. data/tools/riemann-aws/bin/riemann-elb-metrics +149 -148
  42. data/tools/riemann-aws/bin/riemann-s3-list +70 -65
  43. data/tools/riemann-aws/bin/riemann-s3-status +85 -82
  44. data/tools/riemann-chronos/{Rakefile.rb → Rakefile} +2 -0
  45. data/tools/riemann-chronos/bin/riemann-chronos +136 -119
  46. data/tools/riemann-docker/{Rakefile.rb → Rakefile} +2 -0
  47. data/tools/riemann-docker/bin/riemann-docker +163 -174
  48. data/tools/riemann-elasticsearch/{Rakefile.rb → Rakefile} +2 -0
  49. data/tools/riemann-elasticsearch/bin/riemann-elasticsearch +155 -147
  50. data/tools/riemann-marathon/{Rakefile.rb → Rakefile} +2 -0
  51. data/tools/riemann-marathon/bin/riemann-marathon +138 -122
  52. data/tools/riemann-mesos/{Rakefile.rb → Rakefile} +2 -0
  53. data/tools/riemann-mesos/bin/riemann-mesos +125 -110
  54. data/tools/riemann-munin/{Rakefile.rb → Rakefile} +2 -0
  55. data/tools/riemann-munin/bin/riemann-munin +28 -22
  56. data/tools/riemann-rabbitmq/{Rakefile.rb → Rakefile} +2 -0
  57. data/tools/riemann-rabbitmq/bin/riemann-rabbitmq +226 -222
  58. data/tools/riemann-riak/{Rakefile.rb → Rakefile} +2 -0
  59. data/tools/riemann-riak/bin/riemann-riak +281 -289
  60. data/tools/riemann-riak/riak_status/riak_status.rb +39 -39
  61. metadata +65 -16
@@ -1,83 +1,90 @@
1
1
  #!/usr/bin/env ruby
2
- Process.setproctitle($0)
2
+ # frozen_string_literal: true
3
+
4
+ Process.setproctitle($PROGRAM_NAME)
3
5
 
4
6
  # Gathers nginx status stub statistics and submits them to Riemann.
5
7
  # See http://wiki.nginx.org/HttpStubStatusModule for configuring Nginx appropriately
6
8
 
7
- require File.expand_path('../../lib/riemann/tools', __FILE__)
8
-
9
- class Riemann::Tools::NginxStatus
10
- include Riemann::Tools
11
- require 'net/http'
12
- require 'uri'
13
-
14
- opt :uri, "Nginx Stub Status URI", :default => 'http://localhost:8080/nginx_status'
15
- opt :checks, "Which metrics to report.", :type => :strings, :default => %w{active accepted handled requests reading writing waiting}
16
- opt :active_warning, "Active connections warning threshold", :default => 0
17
- opt :active_critical, "Active connections critical threshold", :default => 0
18
- opt :reading_warning, "Reading connections warning threshold", :default => 0
19
- opt :reading_critical, "Reading connections critical threshold", :default => 0
20
- opt :writing_warning, "Writing connections warning threshold", :default => 0
21
- opt :writing_critical, "Writing connections critical threshold", :default => 0
22
- opt :waiting_warning, "Waiting connections warning threshold", :default => 0
23
- opt :waiting_critical, "Waiting connections critical threshold", :default => 0
24
-
25
- def initialize
26
- @uri = URI.parse(opts[:uri])
27
-
28
- # sample response:
29
- #
30
- # Active connections: 1
31
- # server accepts handled requests
32
- # 39 39 39
33
- # Reading: 0 Writing: 1 Waiting: 0
34
- @keys = %w{active accepted handled requests reading writing waiting}
35
- @re = /Active connections: (\d+) \n.+\n (\d+) (\d+) (\d+) \nReading: (\d+) Writing: (\d+) Waiting: (\d+)/m
36
- end
9
+ require File.expand_path('../lib/riemann/tools', __dir__)
37
10
 
38
- def state(key, value)
39
- if opts.has_key? "#{key}_critical".to_sym
40
- critical_threshold = opts["#{key}_critical".to_sym]
41
- return 'critical' if critical_threshold > 0 and value >= critical_threshold
42
- end
11
+ module Riemann
12
+ module Tools
13
+ class NginxStatus
14
+ include Riemann::Tools
15
+ require 'net/http'
16
+ require 'uri'
43
17
 
44
- if opts.has_key? "#{key}_warning".to_sym
45
- warning_threshold = opts["#{key}_warning".to_sym]
46
- return 'warning' if warning_threshold > 0 and value >= warning_threshold
47
- end
18
+ opt :uri, 'Nginx Stub Status URI', default: 'http://localhost:8080/nginx_status'
19
+ opt :checks, 'Which metrics to report.', type: :strings,
20
+ default: %w[active accepted handled requests reading writing waiting]
21
+ opt :active_warning, 'Active connections warning threshold', default: 0
22
+ opt :active_critical, 'Active connections critical threshold', default: 0
23
+ opt :reading_warning, 'Reading connections warning threshold', default: 0
24
+ opt :reading_critical, 'Reading connections critical threshold', default: 0
25
+ opt :writing_warning, 'Writing connections warning threshold', default: 0
26
+ opt :writing_critical, 'Writing connections critical threshold', default: 0
27
+ opt :waiting_warning, 'Waiting connections warning threshold', default: 0
28
+ opt :waiting_critical, 'Waiting connections critical threshold', default: 0
48
29
 
49
- return 'ok'
50
- end
30
+ def initialize
31
+ @uri = URI.parse(opts[:uri])
51
32
 
52
- def tick
53
- response = nil
54
- begin
55
- response = Net::HTTP.get(@uri)
56
- rescue => e
57
- report(
58
- :service => "nginx health",
59
- :state => "critical",
60
- :description => "Connection error: #{e.class} - #{e.message}"
61
- )
62
- end
33
+ # sample response:
34
+ #
35
+ # Active connections: 1
36
+ # server accepts handled requests
37
+ # 39 39 39
38
+ # Reading: 0 Writing: 1 Waiting: 0
39
+ @keys = %w[active accepted handled requests reading writing waiting]
40
+ @re = /Active connections: (\d+) \n.+\n (\d+) (\d+) (\d+) \nReading: (\d+) Writing: (\d+) Waiting: (\d+)/m
41
+ end
42
+
43
+ def state(key, value)
44
+ if opts.key? "#{key}_critical".to_sym
45
+ critical_threshold = opts["#{key}_critical".to_sym]
46
+ return 'critical' if critical_threshold.positive? && (value >= critical_threshold)
47
+ end
48
+
49
+ if opts.key? "#{key}_warning".to_sym
50
+ warning_threshold = opts["#{key}_warning".to_sym]
51
+ return 'warning' if warning_threshold.positive? && (value >= warning_threshold)
52
+ end
53
+
54
+ 'ok'
55
+ end
56
+
57
+ def tick
58
+ response = nil
59
+ begin
60
+ response = Net::HTTP.get(@uri)
61
+ rescue StandardError => e
62
+ report(
63
+ service: 'nginx health',
64
+ state: 'critical',
65
+ description: "Connection error: #{e.class} - #{e.message}",
66
+ )
67
+ end
63
68
 
64
- return if response.nil?
69
+ return if response.nil?
65
70
 
66
- report(
67
- :service => "nginx health",
68
- :state => "ok",
69
- :description => "Nginx status connection ok"
70
- )
71
+ report(
72
+ service: 'nginx health',
73
+ state: 'ok',
74
+ description: 'Nginx status connection ok',
75
+ )
71
76
 
72
- values = @re.match(response).to_a[1,7].map { |v| v.to_i }
77
+ values = @re.match(response).to_a[1, 7].map(&:to_i)
73
78
 
74
- @keys.zip(values).each do |key, value|
75
- report({
76
- :service => "nginx #{key}",
77
- :metric => value,
78
- :state => state(key, value),
79
- :tags => ['nginx']
80
- })
79
+ @keys.zip(values).each do |key, value|
80
+ report({
81
+ service: "nginx #{key}",
82
+ metric: value,
83
+ state: state(key, value),
84
+ tags: ['nginx'],
85
+ })
86
+ end
87
+ end
81
88
  end
82
89
  end
83
90
  end
data/bin/riemann-ntp CHANGED
@@ -1,39 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
- Process.setproctitle($0)
2
+ # frozen_string_literal: true
3
3
 
4
- # Reports NTP stats to Riemann.
5
-
6
- require File.expand_path('../../lib/riemann/tools', __FILE__)
7
-
8
- class Riemann::Tools::Ntp
9
- include Riemann::Tools
4
+ Process.setproctitle($PROGRAM_NAME)
10
5
 
11
- def initialize
12
- @hostname = `hostname`.chomp
13
- end
14
-
15
- def tick
16
- stats = `ntpq -p -n`
17
- stats.each_line do |stat|
18
- m = stat.split()
19
- next if m.grep(/^===/).any? || m.grep(/^remote/).any?
20
- @ntp_host = m[0].gsub("*","").gsub("-","").gsub("+","")
21
- send("delay",m[7])
22
- send("offset",m[8])
23
- send("jitter",m[9])
24
- end
25
- end
6
+ # Reports NTP stats to Riemann.
26
7
 
27
- def send(type,metric)
28
- report(
29
- :host => @hostname,
30
- :service => "ntp peer #{@ntp_host} #{type}",
31
- :metric => metric.to_f,
32
- :state => "ok",
33
- :description => "ntp peer #{@ntp_host} #{type}",
34
- :tags => ["ntp"]
35
- )
36
- end
37
- end
8
+ require 'riemann/tools/ntp'
38
9
 
39
10
  Riemann::Tools::Ntp.run
@@ -1,42 +1,51 @@
1
1
  #!/usr/bin/env ruby
2
- Process.setproctitle($0)
2
+ # frozen_string_literal: true
3
+
4
+ Process.setproctitle($PROGRAM_NAME)
3
5
 
4
6
  # Checks for open tcp ports.
5
7
  # (c) Max Voit 2017
6
8
 
7
- require File.expand_path('../../lib/riemann/tools', __FILE__)
8
-
9
- class Riemann::Tools::Portcheck
10
- include Riemann::Tools
11
- require 'socket'
12
-
13
- opt :hostname, "Host, defaults to localhost", :default => `hostname`.chomp
14
- opt :ports, "List of ports to check, e.g. '-r 80 443'", :type => :ints
15
-
16
- def initialize
17
- @hostname = opts.fetch(:hostname)
18
- @ports = opts.fetch(:ports)
19
- end
20
-
21
- def tick
22
- for thisport in @ports
23
- # try opening tcp connection with 5s timeout;
24
- # if this fails, the port is considered closed
25
- portopen = Socket.tcp(@hostname, thisport, connect_timeout: 5) { true } rescue false
26
- if portopen
27
- state = "ok"
28
- else
29
- state = "critical"
9
+ require File.expand_path('../lib/riemann/tools', __dir__)
10
+
11
+ module Riemann
12
+ module Tools
13
+ class Portcheck
14
+ include Riemann::Tools
15
+ require 'socket'
16
+
17
+ opt :hostname, 'Host, defaults to localhost', default: `hostname`.chomp
18
+ opt :ports, "List of ports to check, e.g. '-r 80 443'", type: :ints
19
+
20
+ def initialize
21
+ @hostname = opts.fetch(:hostname)
22
+ @ports = opts.fetch(:ports)
23
+ end
24
+
25
+ def tick
26
+ @ports.each do |thisport|
27
+ # try opening tcp connection with 5s timeout;
28
+ # if this fails, the port is considered closed
29
+ portopen = begin
30
+ Socket.tcp(@hostname, thisport, connect_timeout: 5) { true }
31
+ rescue StandardError
32
+ false
33
+ end
34
+ state = if portopen
35
+ 'ok'
36
+ else
37
+ 'critical'
38
+ end
39
+ report(
40
+ host: @hostname.to_s,
41
+ service: "port #{thisport}",
42
+ state: state.to_s,
43
+ tags: ['portcheck'],
44
+ )
30
45
  end
31
- report(
32
- :host => "#{@hostname}",
33
- :service => "port #{thisport}",
34
- :state => "#{state}",
35
- :tags => ["portcheck"]
36
- )
46
+ end
37
47
  end
38
48
  end
39
-
40
49
  end
41
50
 
42
51
  Riemann::Tools::Portcheck.run
data/bin/riemann-proc CHANGED
@@ -1,108 +1,114 @@
1
1
  #!/usr/bin/env ruby
2
- Process.setproctitle($0)
2
+ # frozen_string_literal: true
3
+
4
+ Process.setproctitle($PROGRAM_NAME)
3
5
 
4
6
  # Reports running process count to riemann.
5
7
 
6
- require File.expand_path('../../lib/riemann/tools', __FILE__)
8
+ require File.expand_path('../lib/riemann/tools', __dir__)
7
9
 
8
- class Riemann::Tools::Proc
9
- include Riemann::Tools
10
+ module Riemann
11
+ module Tools
12
+ class Proc
13
+ include Riemann::Tools
10
14
 
11
- opt :proc_regex, "regular expression that matches the process to be monitored", type: :string, :default => ".*"
12
- opt :proc_min_critical, "running process count minimum", :default => 0
13
- opt :proc_max_critical, "running process count maximum", :default => 65536
15
+ opt :proc_regex, 'regular expression that matches the process to be monitored', type: :string, default: '.*'
16
+ opt :proc_min_critical, 'running process count minimum', default: 0
17
+ opt :proc_max_critical, 'running process count maximum', default: 65_536
14
18
 
15
- def initialize
16
- @limits = { :critical => { :min => opts[:proc_min_critical], :max => opts[:proc_max_critical] } }
19
+ def initialize
20
+ @limits = { critical: { min: opts[:proc_min_critical], max: opts[:proc_max_critical] } }
17
21
 
18
- abort "FATAL: specify a process regular expression, see --help for usage" unless opts[:proc_regex]
22
+ abort 'FATAL: specify a process regular expression, see --help for usage' unless opts[:proc_regex]
19
23
 
20
- ostype = `uname -s`.chomp.downcase
21
- puts "WARNING: OS '#{ostype}' not explicitly supported. Falling back to Linux" unless ostype == "linux"
22
- @check = method :linux_proc
23
- end
24
+ ostype = `uname -s`.chomp.downcase
25
+ puts "WARNING: OS '#{ostype}' not explicitly supported. Falling back to Linux" unless ostype == 'linux'
26
+ @check = method :linux_proc
27
+ end
24
28
 
25
- def alert(service, state, metric, description)
26
- report(
27
- :service => service.to_s,
28
- :state => state.to_s,
29
- :metric => metric.to_f,
30
- :description => description
31
- )
32
- end
29
+ def alert(service, state, metric, description)
30
+ report(
31
+ service: service.to_s,
32
+ state: state.to_s,
33
+ metric: metric.to_f,
34
+ description: description,
35
+ )
36
+ end
33
37
 
34
- def linux_proc
35
- process = opts[:proc_regex]
36
- found = `ps axo pid=,rss=,vsize=,state=,cputime=,lstart=,command= | grep '#{process}' | grep -v grep | grep -v riemann-proc`
37
- running = found.count("\n")
38
- if running > @limits[:critical][:max] or running < @limits[:critical][:min]
39
- alert "proc count/#{process}", :critical, running, "process #{process} is running #{running} instances.\n"
40
- else
41
- alert "proc count/#{process}", :ok, running, "process #{process} is running #{running} instances.\n"
42
- end
43
- # Iterate on all the lines and create an entry for the following metrics:
44
- #
45
- # process/<pid>-<start-time>/rss
46
- # process/<pid>-<start-time>/vsize
47
- # process/<pid>-<start-time>/running
48
- # process/<pid>-<start-time>/cputime
49
- #
50
- # description should contain the command itself.
51
- # value should be either process RSS, VSIZE, or 1 if running
52
- # state is always unknown for the moment
53
- #
54
- ps_regex = /([0-9]+)[ ]+([0-9]+)[ ]+([0-9]+)[ ]+([A-Z])[ ]+([0-9:.]+)[ ]+[A-Za-z]{3}[ ]+([A-Za-z]{3}[ ]{1,2}[0-9]+ [0-9:]+ [0-9]+)[ ]+(.*)/
55
- found.each_line do |line|
56
- m = ps_regex.match(line)
57
- if not m.nil?
58
- pid, rss, vsize, state, cputime, start, command = m.captures
59
- start_s = DateTime.parse(start, "Mmm DD HH:MM:ss YYYY").to_time.to_i
60
- cputime_s = DateTime.parse(cputime, "%H:%M:%S")
61
- cputime_seconds = (cputime_s.hour * 3600) + (cputime_s.minute * 60) + cputime_s.second
62
- running = 0
63
- case state[0]
64
- when "R"
65
- state_s = "ok"
66
- running = 1
67
- when "S"
68
- state_s = "ok"
69
- when "I"
70
- state_s = "warning"
71
- when "T", "U", "Z"
72
- state_s = "critical"
38
+ def linux_proc
39
+ process = opts[:proc_regex]
40
+ found = `ps axo pid=,rss=,vsize=,state=,cputime=,lstart=,command= | grep '#{process}' | grep -v grep | grep -v riemann-proc`
41
+ running = found.count("\n")
42
+ if (running > @limits[:critical][:max]) || (running < @limits[:critical][:min])
43
+ alert "proc count/#{process}", :critical, running, "process #{process} is running #{running} instances.\n"
73
44
  else
74
- state_s = "unknown"
45
+ alert "proc count/#{process}", :ok, running, "process #{process} is running #{running} instances.\n"
46
+ end
47
+ # Iterate on all the lines and create an entry for the following metrics:
48
+ #
49
+ # process/<pid>-<start-time>/rss
50
+ # process/<pid>-<start-time>/vsize
51
+ # process/<pid>-<start-time>/running
52
+ # process/<pid>-<start-time>/cputime
53
+ #
54
+ # description should contain the command itself.
55
+ # value should be either process RSS, VSIZE, or 1 if running
56
+ # state is always unknown for the moment
57
+ #
58
+ ps_regex = /([0-9]+) +([0-9]+) +([0-9]+) +([A-Z]) +([0-9:.]+) +[A-Za-z]{3} +([A-Za-z]{3} {1,2}[0-9]+ [0-9:]+ [0-9]+) +(.*)/
59
+ found.each_line do |line|
60
+ m = ps_regex.match(line)
61
+ next if m.nil?
62
+
63
+ pid, rss, vsize, state, cputime, start, command = m.captures
64
+ start_s = DateTime.parse(start, 'Mmm DD HH:MM:ss YYYY').to_time.to_i
65
+ cputime_s = DateTime.parse(cputime, '%H:%M:%S')
66
+ cputime_seconds = (cputime_s.hour * 3600) + (cputime_s.minute * 60) + cputime_s.second
67
+ running = 0
68
+ case state[0]
69
+ when 'R'
70
+ state_s = 'ok'
71
+ running = 1
72
+ when 'S'
73
+ state_s = 'ok'
74
+ when 'I'
75
+ state_s = 'warning'
76
+ when 'T', 'U', 'Z'
77
+ state_s = 'critical'
78
+ else
79
+ state_s = 'unknown'
80
+ end
81
+ report(
82
+ service: "proc #{pid}-#{start_s}/rss",
83
+ state: state_s.to_s,
84
+ metric: rss.to_f,
85
+ description: command,
86
+ )
87
+ report(
88
+ service: "proc #{pid}-#{start_s}/vsize",
89
+ state: state_s.to_s,
90
+ metric: vsize.to_f,
91
+ description: command,
92
+ )
93
+ report(
94
+ service: "proc #{pid}-#{start_s}/running",
95
+ state: state_s.to_s,
96
+ metric: running.to_f,
97
+ description: command,
98
+ )
99
+ report(
100
+ service: "proc #{pid}-#{start_s}/cputime",
101
+ state: state_s.to_s,
102
+ metric: cputime_seconds,
103
+ description: command,
104
+ )
75
105
  end
76
- report(
77
- :service => "proc #{pid}-#{start_s}/rss",
78
- :state => state_s.to_s,
79
- :metric => rss.to_f,
80
- :description => command,
81
- )
82
- report(
83
- :service => "proc #{pid}-#{start_s}/vsize",
84
- :state => state_s.to_s,
85
- :metric => vsize.to_f,
86
- :description => command,
87
- )
88
- report(
89
- :service => "proc #{pid}-#{start_s}/running",
90
- :state => state_s.to_s,
91
- :metric => running.to_f,
92
- :description => command,
93
- )
94
- report(
95
- :service => "proc #{pid}-#{start_s}/cputime",
96
- :state => state_s.to_s,
97
- :metric => cputime_seconds,
98
- :description => command,
99
- )
100
106
  end
101
- end
102
- end
103
107
 
104
- def tick
105
- @check.call
108
+ def tick
109
+ @check.call
110
+ end
111
+ end
106
112
  end
107
113
  end
108
114
 
data/bin/riemann-varnish CHANGED
@@ -1,53 +1,59 @@
1
1
  #!/usr/bin/env ruby
2
- Process.setproctitle($0)
2
+ # frozen_string_literal: true
3
+
4
+ Process.setproctitle($PROGRAM_NAME)
3
5
 
4
6
  # Reports varnish stats to Riemann.
5
7
 
6
8
  require 'open3'
7
- require File.expand_path('../../lib/riemann/tools', __FILE__)
8
-
9
- class Riemann::Tools::Varnish
10
- include Riemann::Tools
11
-
12
- opt :varnish_host, "Varnish hostname", :default => `hostname`.chomp
13
-
14
- def initialize
15
- cmd = 'varnishstat -V'
16
- Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
17
- @ver = /varnishstat \(varnish-(\d+)/.match(stderr.read)[1].to_i
18
- end
19
-
20
- if @ver >= 4
21
- @vstats = [ "MAIN.sess_conn",
22
- "MAIN.sess_drop ",
23
- "MAIN.client_req",
24
- "MAIN.cache_hit",
25
- "MAIN.cache_miss" ]
26
- else
27
- @vstats = [ "client_conn",
28
- "client_drop",
29
- "client_req",
30
- "cache_hit",
31
- "cache_miss" ]
32
- end
33
- end
34
-
35
- def tick
36
- if @ver >= 4
37
- stats = `varnishstat -1 -f #{@vstats.join(" -f ")}`
38
- else
39
- stats = `varnishstat -1 -f #{@vstats.join(",")}`
40
- end
41
- stats.each_line do |stat|
42
- m = stat.split()
43
- report(
44
- :host => opts[:varnish_host].dup,
45
- :service => "varnish #{m[0]}",
46
- :metric => m[1].to_f,
47
- :state => "ok",
48
- :description => "#{m[3..-1].join(' ')}",
49
- :tags => ["varnish"]
50
- )
9
+ require File.expand_path('../lib/riemann/tools', __dir__)
10
+
11
+ module Riemann
12
+ module Tools
13
+ class Varnish
14
+ include Riemann::Tools
15
+
16
+ opt :varnish_host, 'Varnish hostname', default: `hostname`.chomp
17
+
18
+ def initialize
19
+ cmd = 'varnishstat -V'
20
+ Open3.popen3(cmd) do |_stdin, _stdout, stderr, _wait_thr|
21
+ @ver = /varnishstat \(varnish-(\d+)/.match(stderr.read)[1].to_i
22
+ end
23
+
24
+ @vstats = if @ver >= 4
25
+ ['MAIN.sess_conn',
26
+ 'MAIN.sess_drop ',
27
+ 'MAIN.client_req',
28
+ 'MAIN.cache_hit',
29
+ 'MAIN.cache_miss',]
30
+ else
31
+ %w[client_conn
32
+ client_drop
33
+ client_req
34
+ cache_hit
35
+ cache_miss]
36
+ end
37
+ end
38
+
39
+ def tick
40
+ stats = if @ver >= 4
41
+ `varnishstat -1 -f #{@vstats.join(' -f ')}`
42
+ else
43
+ `varnishstat -1 -f #{@vstats.join(',')}`
44
+ end
45
+ stats.each_line do |stat|
46
+ m = stat.split
47
+ report(
48
+ host: opts[:varnish_host].dup,
49
+ service: "varnish #{m[0]}",
50
+ metric: m[1].to_f,
51
+ state: 'ok',
52
+ description: m[3..].join(' ').to_s,
53
+ tags: ['varnish'],
54
+ )
55
+ end
56
+ end
51
57
  end
52
58
  end
53
59
  end