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.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +11 -0
- data/.github/workflows/ci.yml +13 -0
- data/.github/workflows/codeql-analysis.yml +72 -0
- data/.rubocop.yml +32 -0
- data/CHANGELOG.md +31 -2
- data/README.markdown +8 -24
- data/Rakefile +4 -2
- data/SECURITY.md +42 -0
- data/bin/riemann-apache-status +92 -78
- data/bin/riemann-bench +54 -49
- data/bin/riemann-cloudant +44 -40
- data/bin/riemann-consul +82 -76
- data/bin/riemann-dir-files-count +53 -47
- data/bin/riemann-dir-space +53 -47
- data/bin/riemann-diskstats +78 -75
- data/bin/riemann-fd +68 -48
- data/bin/riemann-freeswitch +108 -103
- data/bin/riemann-haproxy +46 -40
- data/bin/riemann-health +4 -343
- data/bin/riemann-kvminstance +18 -13
- data/bin/riemann-memcached +35 -29
- data/bin/riemann-net +4 -104
- data/bin/riemann-nginx-status +74 -67
- data/bin/riemann-ntp +4 -33
- data/bin/riemann-portcheck +40 -31
- data/bin/riemann-proc +96 -90
- data/bin/riemann-varnish +51 -45
- data/bin/riemann-zookeeper +38 -34
- data/lib/riemann/tools/health.rb +347 -0
- data/lib/riemann/tools/net.rb +104 -0
- data/lib/riemann/tools/ntp.rb +41 -0
- data/lib/riemann/tools/version.rb +1 -1
- data/lib/riemann/tools.rb +37 -40
- data/riemann-tools.gemspec +4 -1
- data/tools/riemann-aws/{Rakefile.rb → Rakefile} +2 -0
- data/tools/riemann-aws/bin/riemann-aws-billing +72 -66
- data/tools/riemann-aws/bin/riemann-aws-rds-status +55 -41
- data/tools/riemann-aws/bin/riemann-aws-sqs-status +37 -31
- data/tools/riemann-aws/bin/riemann-aws-status +63 -51
- data/tools/riemann-aws/bin/riemann-elb-metrics +149 -148
- data/tools/riemann-aws/bin/riemann-s3-list +70 -65
- data/tools/riemann-aws/bin/riemann-s3-status +85 -82
- data/tools/riemann-chronos/{Rakefile.rb → Rakefile} +2 -0
- data/tools/riemann-chronos/bin/riemann-chronos +136 -119
- data/tools/riemann-docker/{Rakefile.rb → Rakefile} +2 -0
- data/tools/riemann-docker/bin/riemann-docker +163 -174
- data/tools/riemann-elasticsearch/{Rakefile.rb → Rakefile} +2 -0
- data/tools/riemann-elasticsearch/bin/riemann-elasticsearch +155 -147
- data/tools/riemann-marathon/{Rakefile.rb → Rakefile} +2 -0
- data/tools/riemann-marathon/bin/riemann-marathon +138 -122
- data/tools/riemann-mesos/{Rakefile.rb → Rakefile} +2 -0
- data/tools/riemann-mesos/bin/riemann-mesos +125 -110
- data/tools/riemann-munin/{Rakefile.rb → Rakefile} +2 -0
- data/tools/riemann-munin/bin/riemann-munin +28 -22
- data/tools/riemann-rabbitmq/{Rakefile.rb → Rakefile} +2 -0
- data/tools/riemann-rabbitmq/bin/riemann-rabbitmq +226 -222
- data/tools/riemann-riak/{Rakefile.rb → Rakefile} +2 -0
- data/tools/riemann-riak/bin/riemann-riak +281 -289
- data/tools/riemann-riak/riak_status/riak_status.rb +39 -39
- metadata +65 -16
data/bin/riemann-nginx-status
CHANGED
@@ -1,83 +1,90 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
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('
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
11
|
+
module Riemann
|
12
|
+
module Tools
|
13
|
+
class NginxStatus
|
14
|
+
include Riemann::Tools
|
15
|
+
require 'net/http'
|
16
|
+
require 'uri'
|
43
17
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
50
|
-
|
30
|
+
def initialize
|
31
|
+
@uri = URI.parse(opts[:uri])
|
51
32
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
:
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
-
|
69
|
+
return if response.nil?
|
65
70
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
+
report(
|
72
|
+
service: 'nginx health',
|
73
|
+
state: 'ok',
|
74
|
+
description: 'Nginx status connection ok',
|
75
|
+
)
|
71
76
|
|
72
|
-
|
77
|
+
values = @re.match(response).to_a[1, 7].map(&:to_i)
|
73
78
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
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
|
-
|
2
|
+
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
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
|
-
|
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
|
-
|
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
|
data/bin/riemann-portcheck
CHANGED
@@ -1,42 +1,51 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
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('
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
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
|
-
|
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('
|
8
|
+
require File.expand_path('../lib/riemann/tools', __dir__)
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
+
module Riemann
|
11
|
+
module Tools
|
12
|
+
class Proc
|
13
|
+
include Riemann::Tools
|
10
14
|
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
16
|
-
|
19
|
+
def initialize
|
20
|
+
@limits = { critical: { min: opts[:proc_min_critical], max: opts[:proc_max_critical] } }
|
17
21
|
|
18
|
-
|
22
|
+
abort 'FATAL: specify a process regular expression, see --help for usage' unless opts[:proc_regex]
|
19
23
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
-
|
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
|
-
|
105
|
-
|
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
|
-
|
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('
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|