riemann-tools 1.0.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +11 -0
  3. data/.github/workflows/ci.yml +15 -0
  4. data/.github/workflows/codeql-analysis.yml +72 -0
  5. data/.gitignore +2 -0
  6. data/.rubocop.yml +40 -0
  7. data/.ruby-version +1 -0
  8. data/CHANGELOG.md +62 -2
  9. data/README.markdown +8 -24
  10. data/Rakefile +14 -5
  11. data/SECURITY.md +42 -0
  12. data/bin/riemann-apache-status +3 -94
  13. data/bin/riemann-bench +4 -67
  14. data/bin/riemann-cloudant +3 -54
  15. data/bin/riemann-consul +3 -102
  16. data/bin/riemann-dir-files-count +3 -51
  17. data/bin/riemann-dir-space +3 -51
  18. data/bin/riemann-diskstats +3 -91
  19. data/bin/riemann-fd +4 -63
  20. data/bin/riemann-freeswitch +4 -116
  21. data/bin/riemann-haproxy +3 -54
  22. data/bin/riemann-health +3 -344
  23. data/bin/riemann-kvminstance +4 -19
  24. data/bin/riemann-memcached +3 -33
  25. data/bin/riemann-net +3 -105
  26. data/bin/riemann-nginx-status +3 -80
  27. data/bin/riemann-ntp +3 -34
  28. data/bin/riemann-portcheck +3 -37
  29. data/bin/riemann-proc +3 -104
  30. data/bin/riemann-varnish +3 -50
  31. data/bin/riemann-wrapper +75 -0
  32. data/bin/riemann-zookeeper +3 -37
  33. data/lib/riemann/tools/apache_status.rb +107 -0
  34. data/lib/riemann/tools/bench.rb +72 -0
  35. data/lib/riemann/tools/cloudant.rb +57 -0
  36. data/lib/riemann/tools/consul_health.rb +107 -0
  37. data/lib/riemann/tools/dir_files_count.rb +56 -0
  38. data/lib/riemann/tools/dir_space.rb +56 -0
  39. data/lib/riemann/tools/diskstats.rb +94 -0
  40. data/lib/riemann/tools/fd.rb +81 -0
  41. data/lib/riemann/tools/freeswitch.rb +119 -0
  42. data/lib/riemann/tools/haproxy.rb +59 -0
  43. data/lib/riemann/tools/health.rb +478 -0
  44. data/lib/riemann/tools/kvm.rb +23 -0
  45. data/lib/riemann/tools/memcached.rb +38 -0
  46. data/lib/riemann/tools/net.rb +105 -0
  47. data/lib/riemann/tools/nginx_status.rb +86 -0
  48. data/lib/riemann/tools/ntp.rb +42 -0
  49. data/lib/riemann/tools/portcheck.rb +45 -0
  50. data/lib/riemann/tools/proc.rb +109 -0
  51. data/lib/riemann/tools/riemann_client_wrapper.rb +43 -0
  52. data/lib/riemann/tools/uptime_parser.tab.rb +323 -0
  53. data/lib/riemann/tools/varnish.rb +55 -0
  54. data/lib/riemann/tools/version.rb +1 -1
  55. data/lib/riemann/tools/zookeeper.rb +40 -0
  56. data/lib/riemann/tools.rb +31 -52
  57. data/riemann-tools.gemspec +8 -2
  58. data/tools/riemann-aws/{Rakefile.rb → Rakefile} +8 -9
  59. data/tools/riemann-aws/bin/riemann-aws-billing +4 -83
  60. data/tools/riemann-aws/bin/riemann-aws-rds-status +4 -50
  61. data/tools/riemann-aws/bin/riemann-aws-sqs-status +4 -40
  62. data/tools/riemann-aws/bin/riemann-aws-status +4 -67
  63. data/tools/riemann-aws/bin/riemann-elb-metrics +4 -163
  64. data/tools/riemann-aws/bin/riemann-s3-list +4 -78
  65. data/tools/riemann-aws/bin/riemann-s3-status +4 -95
  66. data/tools/riemann-aws/lib/riemann/tools/aws/billing.rb +87 -0
  67. data/tools/riemann-aws/lib/riemann/tools/aws/elb_metrics.rb +163 -0
  68. data/tools/riemann-aws/lib/riemann/tools/aws/rds_status.rb +63 -0
  69. data/tools/riemann-aws/lib/riemann/tools/aws/s3_list.rb +82 -0
  70. data/tools/riemann-aws/lib/riemann/tools/aws/s3_status.rb +97 -0
  71. data/tools/riemann-aws/lib/riemann/tools/aws/sqs_status.rb +45 -0
  72. data/tools/riemann-aws/lib/riemann/tools/aws/status.rb +74 -0
  73. data/tools/riemann-chronos/{Rakefile.rb → Rakefile} +8 -9
  74. data/tools/riemann-chronos/bin/riemann-chronos +3 -139
  75. data/tools/riemann-chronos/lib/riemann/tools/chronos.rb +157 -0
  76. data/tools/riemann-docker/{Rakefile.rb → Rakefile} +7 -8
  77. data/tools/riemann-docker/bin/riemann-docker +4 -213
  78. data/tools/riemann-docker/lib/riemann/tools/docker.rb +200 -0
  79. data/tools/riemann-elasticsearch/{Rakefile.rb → Rakefile} +8 -9
  80. data/tools/riemann-elasticsearch/bin/riemann-elasticsearch +3 -161
  81. data/tools/riemann-elasticsearch/lib/riemann/tools/elasticsearch.rb +170 -0
  82. data/tools/riemann-marathon/{Rakefile.rb → Rakefile} +8 -9
  83. data/tools/riemann-marathon/bin/riemann-marathon +3 -142
  84. data/tools/riemann-marathon/lib/riemann/tools/marathon.rb +159 -0
  85. data/tools/riemann-mesos/{Rakefile.rb → Rakefile} +8 -9
  86. data/tools/riemann-mesos/bin/riemann-mesos +3 -126
  87. data/tools/riemann-mesos/lib/riemann/tools/mesos.rb +142 -0
  88. data/tools/riemann-munin/{Rakefile.rb → Rakefile} +7 -8
  89. data/tools/riemann-munin/bin/riemann-munin +3 -32
  90. data/tools/riemann-munin/lib/riemann/tools/munin.rb +37 -0
  91. data/tools/riemann-rabbitmq/{Rakefile.rb → Rakefile} +8 -9
  92. data/tools/riemann-rabbitmq/bin/riemann-rabbitmq +3 -264
  93. data/tools/riemann-rabbitmq/lib/riemann/tools/rabbitmq.rb +269 -0
  94. data/tools/riemann-riak/{Rakefile.rb → Rakefile} +7 -8
  95. data/tools/riemann-riak/bin/riemann-riak +3 -326
  96. data/tools/riemann-riak/bin/riemann-riak-keys +0 -1
  97. data/tools/riemann-riak/bin/riemann-riak-ring +0 -1
  98. data/tools/riemann-riak/lib/riemann/tools/riak.rb +317 -0
  99. metadata +112 -16
  100. data/.travis.yml +0 -31
  101. data/tools/riemann-riak/riak_status/key_count.erl +0 -13
  102. data/tools/riemann-riak/riak_status/riak_status.rb +0 -152
  103. data/tools/riemann-riak/riak_status/ringready.erl +0 -9
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'riemann/tools'
4
+
5
+ # Gathers nginx status stub statistics and submits them to Riemann.
6
+ # See http://wiki.nginx.org/HttpStubStatusModule for configuring Nginx appropriately
7
+ module Riemann
8
+ module Tools
9
+ class 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,
16
+ default: %w[active accepted handled requests reading writing waiting]
17
+ opt :active_warning, 'Active connections warning threshold', default: 0
18
+ opt :active_critical, 'Active connections critical threshold', default: 0
19
+ opt :reading_warning, 'Reading connections warning threshold', default: 0
20
+ opt :reading_critical, 'Reading connections critical threshold', default: 0
21
+ opt :writing_warning, 'Writing connections warning threshold', default: 0
22
+ opt :writing_critical, 'Writing connections critical threshold', default: 0
23
+ opt :waiting_warning, 'Waiting connections warning threshold', default: 0
24
+ opt :waiting_critical, 'Waiting connections critical threshold', default: 0
25
+
26
+ def initialize
27
+ @uri = URI.parse(opts[:uri])
28
+
29
+ # sample response:
30
+ #
31
+ # Active connections: 1
32
+ # server accepts handled requests
33
+ # 39 39 39
34
+ # Reading: 0 Writing: 1 Waiting: 0
35
+ @keys = %w[active accepted handled requests reading writing waiting]
36
+ @re = /Active connections: (\d+) \n.+\n (\d+) (\d+) (\d+) \nReading: (\d+) Writing: (\d+) Waiting: (\d+)/m
37
+ end
38
+
39
+ def state(key, value)
40
+ if opts.key? "#{key}_critical".to_sym
41
+ critical_threshold = opts["#{key}_critical".to_sym]
42
+ return 'critical' if critical_threshold.positive? && (value >= critical_threshold)
43
+ end
44
+
45
+ if opts.key? "#{key}_warning".to_sym
46
+ warning_threshold = opts["#{key}_warning".to_sym]
47
+ return 'warning' if warning_threshold.positive? && (value >= warning_threshold)
48
+ end
49
+
50
+ 'ok'
51
+ end
52
+
53
+ def tick
54
+ response = nil
55
+ begin
56
+ response = ::Net::HTTP.get(@uri)
57
+ rescue StandardError => e
58
+ report(
59
+ service: 'nginx health',
60
+ state: 'critical',
61
+ description: "Connection error: #{e.class} - #{e.message}",
62
+ )
63
+ end
64
+
65
+ return if response.nil?
66
+
67
+ report(
68
+ service: 'nginx health',
69
+ state: 'ok',
70
+ description: 'Nginx status connection ok',
71
+ )
72
+
73
+ values = @re.match(response).to_a[1, 7].map(&:to_i)
74
+
75
+ @keys.zip(values).each do |key, value|
76
+ report({
77
+ service: "nginx #{key}",
78
+ metric: value,
79
+ state: state(key, value),
80
+ tags: ['nginx'],
81
+ })
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'riemann/tools'
4
+
5
+ # Reports NTP stats to Riemann.
6
+ module Riemann
7
+ module Tools
8
+ class Ntp
9
+ include Riemann::Tools
10
+
11
+ def initialize
12
+ @hostname = `hostname`.chomp
13
+ @ostype = `uname -s`.chomp.downcase
14
+ abort 'WARNING: macOS not explicitly supported. Exiting.' if @ostype == 'darwin'
15
+ end
16
+
17
+ def tick
18
+ stats = `ntpq -p -n`
19
+ stats.each_line do |stat|
20
+ m = stat.split
21
+ next if m.grep(/^===/).any? || m.grep(/^remote/).any?
22
+
23
+ @ntp_host = m[0].gsub('*', '').gsub('-', '').gsub('+', '')
24
+ send('delay', m[7])
25
+ send('offset', m[8])
26
+ send('jitter', m[9])
27
+ end
28
+ end
29
+
30
+ def send(type, metric)
31
+ report(
32
+ host: @hostname,
33
+ service: "ntp peer #{@ntp_host} #{type}",
34
+ metric: metric.to_f,
35
+ state: 'ok',
36
+ description: "ntp peer #{@ntp_host} #{type}",
37
+ tags: ['ntp'],
38
+ )
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'riemann/tools'
4
+
5
+ # Checks for open tcp ports.
6
+ # (c) Max Voit 2017
7
+ module Riemann
8
+ module Tools
9
+ class 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
+ @ports.each do |thisport|
23
+ # try opening tcp connection with 5s timeout;
24
+ # if this fails, the port is considered closed
25
+ portopen = begin
26
+ Socket.tcp(@hostname, thisport, connect_timeout: 5) { true }
27
+ rescue StandardError
28
+ false
29
+ end
30
+ state = if portopen
31
+ 'ok'
32
+ else
33
+ 'critical'
34
+ end
35
+ report(
36
+ host: @hostname.to_s,
37
+ service: "port #{thisport}",
38
+ state: state.to_s,
39
+ tags: ['portcheck'],
40
+ )
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'riemann/tools'
4
+
5
+ # Reports running process count to riemann.
6
+ module Riemann
7
+ module Tools
8
+ class Proc
9
+ include Riemann::Tools
10
+
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: 65_536
14
+
15
+ def initialize
16
+ @limits = { critical: { min: opts[:proc_min_critical], max: opts[:proc_max_critical] } }
17
+
18
+ abort 'FATAL: specify a process regular expression, see --help for usage' unless opts[:proc_regex]
19
+
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
+
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
33
+
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]) || (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
+ next if m.nil?
58
+
59
+ pid, rss, vsize, state, cputime, start, command = m.captures
60
+ start_s = DateTime.parse(start, 'Mmm DD HH:MM:ss YYYY').to_time.to_i
61
+ cputime_s = DateTime.parse(cputime, '%H:%M:%S')
62
+ cputime_seconds = (cputime_s.hour * 3600) + (cputime_s.minute * 60) + cputime_s.second
63
+ running = 0
64
+ case state[0]
65
+ when 'R'
66
+ state_s = 'ok'
67
+ running = 1
68
+ when 'S'
69
+ state_s = 'ok'
70
+ when 'I'
71
+ state_s = 'warning'
72
+ when 'T', 'U', 'Z'
73
+ state_s = 'critical'
74
+ else
75
+ state_s = 'unknown'
76
+ end
77
+ report(
78
+ service: "proc #{pid}-#{start_s}/rss",
79
+ state: state_s.to_s,
80
+ metric: rss.to_f,
81
+ description: command,
82
+ )
83
+ report(
84
+ service: "proc #{pid}-#{start_s}/vsize",
85
+ state: state_s.to_s,
86
+ metric: vsize.to_f,
87
+ description: command,
88
+ )
89
+ report(
90
+ service: "proc #{pid}-#{start_s}/running",
91
+ state: state_s.to_s,
92
+ metric: running.to_f,
93
+ description: command,
94
+ )
95
+ report(
96
+ service: "proc #{pid}-#{start_s}/cputime",
97
+ state: state_s.to_s,
98
+ metric: cputime_seconds,
99
+ description: command,
100
+ )
101
+ end
102
+ end
103
+
104
+ def tick
105
+ @check.call
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'singleton'
4
+
5
+ require 'riemann/client'
6
+
7
+ module Riemann
8
+ module Tools
9
+ class RiemannClientWrapper
10
+ include Singleton
11
+
12
+ def initialize
13
+ @client = nil
14
+ end
15
+
16
+ def configure(options)
17
+ return self unless @client.nil?
18
+
19
+ r = Riemann::Client.new(
20
+ host: options[:host],
21
+ port: options[:port],
22
+ timeout: options[:timeout],
23
+ ssl: options[:tls],
24
+ key_file: options[:tls_key],
25
+ cert_file: options[:tls_cert],
26
+ ca_file: options[:tls_ca_cert],
27
+ ssl_verify: options[:tls_verify],
28
+ )
29
+
30
+ @client = if options[:tcp] || options[:tls]
31
+ r.tcp
32
+ else
33
+ r
34
+ end
35
+ self
36
+ end
37
+
38
+ def <<(event)
39
+ @client << event
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,323 @@
1
+ #
2
+ # DO NOT MODIFY!!!!
3
+ # This file is automatically generated by Racc 1.6.0
4
+ # from Racc grammar file "".
5
+ #
6
+
7
+ require 'racc/parser.rb'
8
+
9
+
10
+ require 'strscan'
11
+
12
+ module Riemann
13
+ module Tools
14
+ class UptimeParser < Racc::Parser
15
+
16
+ module_eval(<<'...end uptime_parser.y/module_eval...', 'uptime_parser.y', 43)
17
+
18
+ def parse(text)
19
+ s = StringScanner.new(text)
20
+ @tokens = []
21
+
22
+ until s.eos? do
23
+ case
24
+ when s.scan(/\n/) then # ignore
25
+ when s.scan(/\s+/) then # ignore
26
+
27
+ when s.scan(/:/) then @tokens << [':', s.matched]
28
+ when s.scan(/,/) then @tokens << [',', s.matched]
29
+ when s.scan(/\d+[,.]\d+/) then @tokens << [:FLOAT, s.matched.sub(',', '.').to_f]
30
+ when s.scan(/\d+/) then @tokens << [:INTEGER, s.matched.to_i]
31
+ when s.scan(/AM/) then @tokens << [:AM, s.matched]
32
+ when s.scan(/PM/) then @tokens << [:PM, s.matched]
33
+ when s.scan(/up/) then @tokens << [:UP, s.matched]
34
+ when s.scan(/days?/) then @tokens << [:DAYS, s.matched]
35
+ when s.scan(/hrs?/) then @tokens << [:HRS, s.matched]
36
+ when s.scan(/mins?/) then @tokens << [:MINS, s.matched]
37
+ when s.scan(/secs?/) then @tokens << [:SECS, s.matched]
38
+ when s.scan(/users?/) then @tokens << [:USERS, s.matched]
39
+ when s.scan(/load averages?:/) then @tokens << [:LOAD_AVERAGES, s.matched]
40
+ else
41
+ raise s.rest
42
+ end
43
+ end
44
+
45
+ do_parse
46
+ end
47
+
48
+ def next_token
49
+ @tokens.shift
50
+ end
51
+ ...end uptime_parser.y/module_eval...
52
+ ##### State transition tables begin ###
53
+
54
+ racc_action_table = [
55
+ 29, 30, 24, 26, 27, 28, 26, 27, 28, 40,
56
+ 41, 25, 31, 3, 25, 4, 6, 7, 8, 9,
57
+ 15, 16, 18, 23, 32, 33, 34, 35, 36, 38,
58
+ 39, 42, 43, 44, 45 ]
59
+
60
+ racc_action_check = [
61
+ 16, 16, 15, 15, 15, 15, 23, 23, 23, 39,
62
+ 39, 15, 16, 0, 23, 1, 2, 3, 4, 5,
63
+ 6, 7, 9, 10, 17, 18, 24, 25, 31, 32,
64
+ 38, 40, 41, 43, 44 ]
65
+
66
+ racc_action_pointer = [
67
+ 2, 15, 12, 3, 18, 6, 9, 10, nil, 11,
68
+ 12, nil, nil, nil, nil, -3, -2, 11, 16, nil,
69
+ nil, nil, nil, 0, 13, 16, nil, nil, nil, nil,
70
+ nil, 17, 19, nil, nil, nil, nil, nil, 18, -3,
71
+ 19, 20, nil, 20, 22, nil ]
72
+
73
+ racc_action_default = [
74
+ -22, -22, -22, -22, -22, -22, -22, -22, 46, -22,
75
+ -22, -10, -11, -12, -13, -22, -2, -22, -22, -6,
76
+ -7, -8, -9, -22, -22, -22, -16, -17, -18, -3,
77
+ -4, -22, -22, -19, -14, -15, -5, -1, -22, -22,
78
+ -22, -22, -20, -22, -22, -21 ]
79
+
80
+ racc_goto_table = [
81
+ 11, 12, 13, 14, 19, 20, 21, 22, 1, 2,
82
+ 5, 17, 37, 10 ]
83
+
84
+ racc_goto_check = [
85
+ 7, 8, 9, 10, 7, 8, 9, 10, 1, 2,
86
+ 3, 4, 5, 6 ]
87
+
88
+ racc_goto_pointer = [
89
+ nil, 8, 9, 8, 2, -20, 7, -6, -5, -4,
90
+ -3 ]
91
+
92
+ racc_goto_default = [
93
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
94
+ nil ]
95
+
96
+ racc_reduce_table = [
97
+ 0, 0, :racc_error,
98
+ 6, 16, :_reduce_1,
99
+ 3, 17, :_reduce_none,
100
+ 4, 17, :_reduce_none,
101
+ 4, 17, :_reduce_none,
102
+ 5, 17, :_reduce_none,
103
+ 3, 18, :_reduce_6,
104
+ 3, 18, :_reduce_7,
105
+ 3, 18, :_reduce_8,
106
+ 3, 18, :_reduce_9,
107
+ 2, 18, :_reduce_10,
108
+ 2, 18, :_reduce_11,
109
+ 2, 18, :_reduce_12,
110
+ 2, 18, :_reduce_13,
111
+ 3, 21, :_reduce_14,
112
+ 3, 22, :_reduce_15,
113
+ 2, 23, :_reduce_16,
114
+ 2, 24, :_reduce_17,
115
+ 2, 25, :_reduce_18,
116
+ 2, 19, :_reduce_none,
117
+ 4, 20, :_reduce_20,
118
+ 6, 20, :_reduce_21 ]
119
+
120
+ racc_reduce_n = 22
121
+
122
+ racc_shift_n = 46
123
+
124
+ racc_token_table = {
125
+ false => 0,
126
+ :error => 1,
127
+ :AM => 2,
128
+ :PM => 3,
129
+ :UP => 4,
130
+ :DAYS => 5,
131
+ :HRS => 6,
132
+ :MINS => 7,
133
+ :SECS => 8,
134
+ :USERS => 9,
135
+ :LOAD_AVERAGES => 10,
136
+ :INTEGER => 11,
137
+ :FLOAT => 12,
138
+ "," => 13,
139
+ ":" => 14 }
140
+
141
+ racc_nt_base = 15
142
+
143
+ racc_use_result_var = true
144
+
145
+ Racc_arg = [
146
+ racc_action_table,
147
+ racc_action_check,
148
+ racc_action_default,
149
+ racc_action_pointer,
150
+ racc_goto_table,
151
+ racc_goto_check,
152
+ racc_goto_default,
153
+ racc_goto_pointer,
154
+ racc_nt_base,
155
+ racc_reduce_table,
156
+ racc_token_table,
157
+ racc_shift_n,
158
+ racc_reduce_n,
159
+ racc_use_result_var ]
160
+
161
+ Racc_token_to_s_table = [
162
+ "$end",
163
+ "error",
164
+ "AM",
165
+ "PM",
166
+ "UP",
167
+ "DAYS",
168
+ "HRS",
169
+ "MINS",
170
+ "SECS",
171
+ "USERS",
172
+ "LOAD_AVERAGES",
173
+ "INTEGER",
174
+ "FLOAT",
175
+ "\",\"",
176
+ "\":\"",
177
+ "$start",
178
+ "target",
179
+ "time",
180
+ "uptime",
181
+ "users",
182
+ "load_averages",
183
+ "uptime_days",
184
+ "uptime_hr_min",
185
+ "uptime_hr",
186
+ "uptime_min",
187
+ "uptime_sec" ]
188
+
189
+ Racc_debug_parser = false
190
+
191
+ ##### State transition tables end #####
192
+
193
+ # reduce 0 omitted
194
+
195
+ module_eval(<<'.,.,', 'uptime_parser.y', 4)
196
+ def _reduce_1(val, _values, result)
197
+ result = { uptime: val[1], users: val[3], load_averages: val[5] }
198
+ result
199
+ end
200
+ .,.,
201
+
202
+ # reduce 2 omitted
203
+
204
+ # reduce 3 omitted
205
+
206
+ # reduce 4 omitted
207
+
208
+ # reduce 5 omitted
209
+
210
+ module_eval(<<'.,.,', 'uptime_parser.y', 11)
211
+ def _reduce_6(val, _values, result)
212
+ result = val[1] + val[2]
213
+ result
214
+ end
215
+ .,.,
216
+
217
+ module_eval(<<'.,.,', 'uptime_parser.y', 12)
218
+ def _reduce_7(val, _values, result)
219
+ result = val[1] + val[2]
220
+ result
221
+ end
222
+ .,.,
223
+
224
+ module_eval(<<'.,.,', 'uptime_parser.y', 13)
225
+ def _reduce_8(val, _values, result)
226
+ result = val[1] + val[2]
227
+ result
228
+ end
229
+ .,.,
230
+
231
+ module_eval(<<'.,.,', 'uptime_parser.y', 14)
232
+ def _reduce_9(val, _values, result)
233
+ result = val[1] + val[2]
234
+ result
235
+ end
236
+ .,.,
237
+
238
+ module_eval(<<'.,.,', 'uptime_parser.y', 15)
239
+ def _reduce_10(val, _values, result)
240
+ result = val[1]
241
+ result
242
+ end
243
+ .,.,
244
+
245
+ module_eval(<<'.,.,', 'uptime_parser.y', 16)
246
+ def _reduce_11(val, _values, result)
247
+ result = val[1]
248
+ result
249
+ end
250
+ .,.,
251
+
252
+ module_eval(<<'.,.,', 'uptime_parser.y', 17)
253
+ def _reduce_12(val, _values, result)
254
+ result = val[1]
255
+ result
256
+ end
257
+ .,.,
258
+
259
+ module_eval(<<'.,.,', 'uptime_parser.y', 18)
260
+ def _reduce_13(val, _values, result)
261
+ result = val[1]
262
+ result
263
+ end
264
+ .,.,
265
+
266
+ module_eval(<<'.,.,', 'uptime_parser.y', 20)
267
+ def _reduce_14(val, _values, result)
268
+ result = val[0] * 86400
269
+ result
270
+ end
271
+ .,.,
272
+
273
+ module_eval(<<'.,.,', 'uptime_parser.y', 22)
274
+ def _reduce_15(val, _values, result)
275
+ result = val[0] * 3600 + val[2] * 60
276
+ result
277
+ end
278
+ .,.,
279
+
280
+ module_eval(<<'.,.,', 'uptime_parser.y', 24)
281
+ def _reduce_16(val, _values, result)
282
+ result = val[0] * 3600
283
+ result
284
+ end
285
+ .,.,
286
+
287
+ module_eval(<<'.,.,', 'uptime_parser.y', 26)
288
+ def _reduce_17(val, _values, result)
289
+ result = val[0] * 60
290
+ result
291
+ end
292
+ .,.,
293
+
294
+ module_eval(<<'.,.,', 'uptime_parser.y', 28)
295
+ def _reduce_18(val, _values, result)
296
+ result = val[0]
297
+ result
298
+ end
299
+ .,.,
300
+
301
+ # reduce 19 omitted
302
+
303
+ module_eval(<<'.,.,', 'uptime_parser.y', 32)
304
+ def _reduce_20(val, _values, result)
305
+ result = { 1 => val[1], 5 => val[2], 15 => val[3] }
306
+ result
307
+ end
308
+ .,.,
309
+
310
+ module_eval(<<'.,.,', 'uptime_parser.y', 33)
311
+ def _reduce_21(val, _values, result)
312
+ result = { 1 => val[1], 5 => val[3], 15 => val[5] }
313
+ result
314
+ end
315
+ .,.,
316
+
317
+ def _reduce_none(val, _values, result)
318
+ val[0]
319
+ end
320
+
321
+ end # class UptimeParser
322
+ end # module Tools
323
+ end # module Riemann
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'open3'
4
+ require 'riemann/tools'
5
+
6
+ # Reports varnish stats to Riemann.
7
+ module Riemann
8
+ module Tools
9
+ class 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
+ @vstats = if @ver >= 4
21
+ ['MAIN.sess_conn',
22
+ 'MAIN.sess_drop ',
23
+ 'MAIN.client_req',
24
+ 'MAIN.cache_hit',
25
+ 'MAIN.cache_miss',]
26
+ else
27
+ %w[client_conn
28
+ client_drop
29
+ client_req
30
+ cache_hit
31
+ cache_miss]
32
+ end
33
+ end
34
+
35
+ def tick
36
+ stats = if @ver >= 4
37
+ `varnishstat -1 -f #{@vstats.join(' -f ')}`
38
+ else
39
+ `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..].join(' ').to_s,
49
+ tags: ['varnish'],
50
+ )
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end