sensu-plugins-graylog 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/CHANGELOG.md +30 -3
- data/README.md +4 -0
- data/bin/check-graylog-buffers.py +4 -51
- data/bin/check-graylog-buffers.rb +159 -4
- data/bin/check-graylog2-alive.rb +15 -5
- data/bin/metrics-graylog.py +5 -41
- data/bin/metrics-graylog.rb +128 -4
- data/lib/sensu-plugins-graylog/version.rb +2 -2
- metadata +44 -30
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
NjRhZDZlNDViZmYyNzZjNDdhNzRlNzUyOTY1ODE3NmY3ZDA0MTk4Ng==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 34875fc3e0b9379938f61e3dd91ee152958883a6
|
4
|
+
data.tar.gz: 7fa8d94e8e8626bf49adc3c3b81e6f3b8baeaff1
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
NjRjYjI3ZTdiMGYwZDllNjYxNjJmYzEyZDkxZTk5MThiZTNiOWZjZjk3NTA3
|
11
|
-
ODY3OTBhZjA4OTIyY2Q3ZDY3ZWYzMGFkMTIwYWZiOGNmM2UzNzk=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MThlMmY1Yjg3MWRmODg5NjY2NDE2ZDRjNDBmMjA1YTZkODU2ZDczZTQzN2Iz
|
14
|
-
ZDU0Yjk2YWU5YmI0MzA5ODhjYThkZjdjODUzNGU3MWIzOTE2YjQ2MzgyYWYw
|
15
|
-
NmU4MTQ5ZmYwYTJkOTc0ZDNmNjU2MWNhMDY1Zjk3NTY1ZWQxNjI=
|
6
|
+
metadata.gz: 99751c6798ac9b26cf7a22e214e39cf215eae6af28977b707a9e62c0736b554da2d9e97f840171add79f73f75eb63d221428c7bfccf9fa720205ea290487b21f
|
7
|
+
data.tar.gz: ded6b4ad2ea4ebf9af0e88362527d7cbea3cc4bfa52e180608e36ac912792e4cb2a1aabfb2372b5c058b4ab637a6eb6977526a24910004cbf9ed5f3123eb48f4
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,36 @@
|
|
1
|
-
#Change Log
|
1
|
+
# Change Log
|
2
2
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
3
3
|
|
4
4
|
This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
|
5
5
|
|
6
6
|
## [Unreleased]
|
7
7
|
|
8
|
+
|
9
|
+
## [1.0.0] - 2017-03-15
|
10
|
+
This release drops support for Ruby 1.9.3 and converts `check-graylog-buffers` and `metrics-graylog`
|
11
|
+
from Python to Ruby. The Ruby versions were written to behave like the Python versions but as always testing
|
12
|
+
in your environment is encouraged.
|
13
|
+
|
14
|
+
### Changed
|
15
|
+
- update check-graylog2-alive.rb to accept an `--apipath` argument to specify the path of the transport api
|
16
|
+
- update -alive lifecycle check because there are now multiple valid lifecyle states
|
17
|
+
- drop ruby 1.9.3 support; add 2.3.0
|
18
|
+
- update sensu-plugin dep to '~> 1.2'
|
19
|
+
- add some tests, this pulled in webmock to mock restclient calls
|
20
|
+
- update readme
|
21
|
+
- check-graylog-buffers
|
22
|
+
- port python to ruby
|
23
|
+
- py file is now a binstub for rb file
|
24
|
+
- add version support for pre/post 2.1.0 buffer metrics
|
25
|
+
- add apipath support
|
26
|
+
- add tests
|
27
|
+
- metrics-graylog
|
28
|
+
- port python to ruby
|
29
|
+
- py file is now a binstub for rb file
|
30
|
+
- add --all flag for more stats (still some work to do here)
|
31
|
+
- add apipath support
|
32
|
+
- add tests
|
33
|
+
|
8
34
|
## [0.1.0] - 2016-01-29
|
9
35
|
### Added
|
10
36
|
- add new checks for graylog buffers and kafka journal
|
@@ -18,6 +44,7 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
|
|
18
44
|
### Added
|
19
45
|
- initial release
|
20
46
|
|
21
|
-
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-graylog/compare/
|
22
|
-
[0.
|
47
|
+
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-graylog/compare/1.0.0...HEAD
|
48
|
+
[1.0.0]: https://github.com/sensu-plugins/sensu-plugins-graylog/compare/0.1.0...1.0.0
|
49
|
+
[0.1.0]: https://github.com/sensu-plugins/sensu-plugins-graylog/compare/0.0.2...0.1.0
|
23
50
|
[0.0.2]: https://github.com/sensu-plugins/sensu-plugins-graylog/compare/0.0.1...0.0.2
|
data/README.md
CHANGED
@@ -7,6 +7,7 @@
|
|
7
7
|
[![Dependency Status](https://gemnasium.com/sensu-plugins/sensu-plugins-graylog.svg)](https://gemnasium.com/sensu-plugins/sensu-plugins-graylog)
|
8
8
|
|
9
9
|
## Functionality
|
10
|
+
This plugin provides availability monitoring and metrics collection for the [Graylog](https://www.graylog.org/) log management system.
|
10
11
|
|
11
12
|
## Files
|
12
13
|
* bin/check-graylog2-alive.rb
|
@@ -20,3 +21,6 @@
|
|
20
21
|
[Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
|
21
22
|
|
22
23
|
## Notes
|
24
|
+
- If you want a limited access user for monitoring purposes please see the [Graylog FAQ](http://docs.graylog.org/en/latest/pages/faq.html#how-can-i-create-a-restricted-user-to-check-internal-graylog-metrics-in-my-monitoring-system+)
|
25
|
+
- Users may further obfuscate their credentials by creating an [Access Token](http://docs.graylog.org/en/latest/pages/configuration/rest_api.html?highlight=access%20tokens#creating-and-using-access-token) to use instead of their normal login credentials.
|
26
|
+
- Note that only an admin may create a token by default. If you want to have a dedicated monitoring user with an access token you will need to create them as a Admin user, create the token, then change the user to the monitoring specific role. You can change the default behavior by granting `users:tokencreate`, `users:tokenlist`, and `users:tokenremove` to a role and adding that role to the monitoring user.
|
@@ -1,56 +1,9 @@
|
|
1
1
|
#!/usr/bin/env python
|
2
2
|
|
3
|
-
import
|
4
|
-
import json
|
3
|
+
import os
|
5
4
|
import sys
|
6
|
-
import getopt
|
7
|
-
import socket
|
8
5
|
|
9
|
-
def main(argv):
|
10
|
-
host = socket.getfqdn()
|
11
|
-
user = "graylog2"
|
12
|
-
password = "mypass"
|
13
|
-
port = "12900"
|
14
|
-
warnThreshold = 80.0
|
15
|
-
critThreshold = 90.0
|
16
|
-
try:
|
17
|
-
opts, args = getopt.getopt(argv, "h:u:p:P:w:c:", ["host=","user=","pass=","port=", "warn=", "crit="])
|
18
|
-
except getopt.GetoptError:
|
19
|
-
print 'flag error'
|
20
|
-
sys.exit(2)
|
21
|
-
for opt, arg in opts:
|
22
|
-
if opt in ("-h", "--host"):
|
23
|
-
host = arg
|
24
|
-
elif opt in ("-u", "--user"):
|
25
|
-
user = arg
|
26
|
-
elif opt in ("-p", "--pass"):
|
27
|
-
password = arg
|
28
|
-
elif opt in ("-P", "--port"):
|
29
|
-
port = arg
|
30
|
-
elif opt in ("-w", "--warn"):
|
31
|
-
warnThreshold = float(arg)
|
32
|
-
elif opt in ("-c", "--crit"):
|
33
|
-
critThreshold = float(arg)
|
34
6
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
authhandler = urllib2.HTTPBasicAuthHandler(passman)
|
39
|
-
opener = urllib2.build_opener(authhandler)
|
40
|
-
urllib2.install_opener(opener)
|
41
|
-
|
42
|
-
pagehandle = urllib2.urlopen('http://'+ host + ':' + port + '/system/buffers')
|
43
|
-
data = json.load(pagehandle)
|
44
|
-
|
45
|
-
if data['buffers']['process']['utilization_percent'] >= warnThreshold:
|
46
|
-
print 'WARNING: process buffer utilization is %.2f%%, threshold is %.2f%%' % (data['buffers']['process']['utilization_percent'], warnThreshold)
|
47
|
-
sys.exit(1)
|
48
|
-
elif data['buffers']['process']['utilization_percent'] >= critThreshold:
|
49
|
-
print 'CRITICAL: process buffer utilization is %.2f%%, threshold is %.2f%%' % (data['buffers']['process']['utilization_percent'], critThreshold)
|
50
|
-
sys.exit(2)
|
51
|
-
else:
|
52
|
-
print 'OK: process buffer utilization is %.2f%%' % data['buffers']['process']['utilization_percent']
|
53
|
-
sys.exit(0)
|
54
|
-
|
55
|
-
if __name__ == "__main__":
|
56
|
-
main(sys.argv[1:])
|
7
|
+
script = os.path.splitext(os.path.abspath( __file__ ))[0]
|
8
|
+
print script
|
9
|
+
os.execv(script + '.rb', sys.argv)
|
@@ -1,6 +1,161 @@
|
|
1
|
-
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
# check-graylog-buffers.rb
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# This plugin checks the the status of the Graylog2 buffers using the
|
7
|
+
# REST API normally available on port 12900
|
8
|
+
#
|
9
|
+
# OUTPUT:
|
10
|
+
# plain text
|
11
|
+
#
|
12
|
+
# PLATFORMS:
|
13
|
+
# Linux
|
14
|
+
#
|
15
|
+
# DEPENDENCIES:
|
16
|
+
# gem: sensu-plugin
|
17
|
+
# gem: json
|
18
|
+
# gem: rest-client
|
19
|
+
#
|
20
|
+
# USAGE:
|
21
|
+
# ./check-graylog-buffers.rb -u admin -p 12345
|
22
|
+
#
|
23
|
+
# NOTES:
|
24
|
+
# This plugin requires a username and password with permission to access
|
25
|
+
# the /system API call in the Graylog2 server. A basic non-admin, reader
|
26
|
+
# only account will do.
|
27
|
+
#
|
28
|
+
# LICENSE:
|
29
|
+
# nathan hruby <nhruby@gmail.com>
|
30
|
+
# SugarCRM
|
31
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
32
|
+
# for details.
|
33
|
+
#
|
2
34
|
|
3
|
-
|
4
|
-
|
35
|
+
require 'sensu-plugin/check/cli'
|
36
|
+
require 'json'
|
37
|
+
require 'rest-client'
|
5
38
|
|
6
|
-
|
39
|
+
class CheckGraylogBuffers < Sensu::Plugin::Check::CLI
|
40
|
+
option :host,
|
41
|
+
description: 'Graylog host',
|
42
|
+
short: '-h',
|
43
|
+
long: '--host HOST',
|
44
|
+
default: 'localhost'
|
45
|
+
|
46
|
+
option :username,
|
47
|
+
description: 'Graylog username',
|
48
|
+
short: '-u',
|
49
|
+
long: '--username USERNAME',
|
50
|
+
default: 'admin',
|
51
|
+
required: true
|
52
|
+
|
53
|
+
option :password,
|
54
|
+
description: 'Graylog password',
|
55
|
+
short: '-p',
|
56
|
+
long: '--password PASSWORD',
|
57
|
+
required: true
|
58
|
+
|
59
|
+
option :port,
|
60
|
+
description: 'Graylog API port',
|
61
|
+
short: '-P',
|
62
|
+
long: '--port PORT',
|
63
|
+
default: '12900'
|
64
|
+
|
65
|
+
option :apipath,
|
66
|
+
description: 'Graylog API path prefix',
|
67
|
+
short: '-a',
|
68
|
+
long: '--apipath /api',
|
69
|
+
default: ''
|
70
|
+
|
71
|
+
option :warn,
|
72
|
+
short: '-w WARNING',
|
73
|
+
long: '--warning',
|
74
|
+
proc: proc(&:to_f),
|
75
|
+
default: 80
|
76
|
+
|
77
|
+
option :crit,
|
78
|
+
short: '-c CRITICAL',
|
79
|
+
long: '--critical',
|
80
|
+
proc: proc(&:to_f),
|
81
|
+
default: 90
|
82
|
+
|
83
|
+
def run
|
84
|
+
version = acquire_version
|
85
|
+
if Gem::Version.new(version) < Gem::Version.new('2.1.0')
|
86
|
+
check_pre_210_buffers
|
87
|
+
else
|
88
|
+
check_210_buffers
|
89
|
+
end
|
90
|
+
rescue => e
|
91
|
+
unknown e.message
|
92
|
+
end
|
93
|
+
|
94
|
+
def call_api(path, postdata = nil)
|
95
|
+
resource = RestClient::Resource.new "http://#{config[:host]}:#{config[:port]}#{config[:apipath]}#{path}", config[:username], config[:password]
|
96
|
+
if !postdata
|
97
|
+
JSON.parse(resource.get)
|
98
|
+
else
|
99
|
+
JSON.parse(resource.post(postdata.to_json, content_type: :json, accept: :json))
|
100
|
+
end
|
101
|
+
rescue Errno::ECONNREFUSED => e
|
102
|
+
critical e.message
|
103
|
+
end
|
104
|
+
|
105
|
+
def acquire_version
|
106
|
+
ret = call_api('/system')
|
107
|
+
ret['version'].split('+')[0]
|
108
|
+
end
|
109
|
+
|
110
|
+
# https://github.com/Graylog2/graylog2-server/commit/0bd45c69f65011b50cb1e101c4a9c2eac97c0266
|
111
|
+
def check_pre_210_buffers
|
112
|
+
ret = call_api('/system/buffers')
|
113
|
+
utilization = ret['buffers']['process']['utilization_percent'].to_f
|
114
|
+
if utilization >= config[:crit]
|
115
|
+
critical format('process buffer utilization is %.2f%%, threshold is %.2f%%', utilization, config[:crit])
|
116
|
+
elsif utilization >= config[:warn]
|
117
|
+
warn format('process buffer utilization is %.2f%%, threshold is %.2f%%', utilization, config[:warn])
|
118
|
+
else
|
119
|
+
ok format('process buffer utilization is %.2f%%', utilization)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def check_210_buffers
|
124
|
+
postdata = {
|
125
|
+
'metrics' => [
|
126
|
+
'org.graylog2.buffers.input.usage',
|
127
|
+
'org.graylog2.buffers.input.size',
|
128
|
+
'org.graylog2.buffers.process.usage',
|
129
|
+
'org.graylog2.buffers.process.size',
|
130
|
+
'org.graylog2.buffers.output.usage',
|
131
|
+
'org.graylog2.buffers.output.size'
|
132
|
+
]
|
133
|
+
}
|
134
|
+
ret = call_api('/system/metrics/multiple', postdata)
|
135
|
+
|
136
|
+
if ret['total'] != 6
|
137
|
+
unkown format('API responded with incorrect number of metrics, got %d expected 6', ret['total'])
|
138
|
+
end
|
139
|
+
|
140
|
+
metric_pct = {}
|
141
|
+
%w(input process output).each do |m|
|
142
|
+
begin
|
143
|
+
usage = ret['metrics'].find { |x| x['full_name'] == "org.graylog2.buffers.#{m}.usage" }
|
144
|
+
size = ret['metrics'].find { |x| x['full_name'] == "org.graylog2.buffers.#{m}.size" }
|
145
|
+
metric_pct[m] = (usage['metric']['value'].to_f / size['metric']['value'].to_f) * 100.0
|
146
|
+
rescue ZeroDivisionError
|
147
|
+
metric_pct[m] = 0.0
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
message = format('buffer utilization is %.2f%%/%.2f%%/%.2f%%', metric_pct['input'], metric_pct['process'], metric_pct['output'])
|
152
|
+
metric_pct.each do |m, p|
|
153
|
+
if p >= config[:crit]
|
154
|
+
critical format('%s buffer exceeds %.2f%%, %s', m, config[:crit], message)
|
155
|
+
elsif p >= config[:warn]
|
156
|
+
warn format('%s buffer exceeds %.2f%%, %s', m, config[:warn], message)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
ok message
|
160
|
+
end
|
161
|
+
end
|
data/bin/check-graylog2-alive.rb
CHANGED
@@ -57,11 +57,17 @@ class CheckGraylog2Alive < Sensu::Plugin::Check::CLI
|
|
57
57
|
required: true
|
58
58
|
|
59
59
|
option :port,
|
60
|
-
description: '
|
60
|
+
description: 'Graylog API port',
|
61
61
|
short: '-P',
|
62
62
|
long: '--port PORT',
|
63
63
|
default: '12900'
|
64
64
|
|
65
|
+
option :apipath,
|
66
|
+
description: 'Graylog API path prefix',
|
67
|
+
short: '-a',
|
68
|
+
long: '--apipath /api',
|
69
|
+
default: ''
|
70
|
+
|
65
71
|
def run
|
66
72
|
res = vhost_alive?
|
67
73
|
|
@@ -79,15 +85,19 @@ class CheckGraylog2Alive < Sensu::Plugin::Check::CLI
|
|
79
85
|
port = config[:port]
|
80
86
|
username = config[:username]
|
81
87
|
password = config[:password]
|
88
|
+
apipath = config[:apipath]
|
89
|
+
|
90
|
+
lifecycle_ok = ['override lb:alive', 'running']
|
82
91
|
|
83
92
|
begin
|
84
|
-
resource = RestClient::Resource.new "http://#{host}:#{port}/system", username, password
|
93
|
+
resource = RestClient::Resource.new "http://#{host}:#{port}#{apipath}/system", username, password
|
85
94
|
# Attempt to parse response (just to trigger parse exception)
|
86
95
|
response = JSON.parse(resource.get)
|
87
|
-
|
88
|
-
|
96
|
+
status_text = "#{response['lifecycle']}/#{response['is_processing']}/#{response['lb_status']}"
|
97
|
+
if lifecycle_ok.include?(response['lifecycle']) && response['is_processing'] && response['lb_status'] == 'alive'
|
98
|
+
{ 'status' => 'ok', 'message' => "Graylog2 server is: #{status_text}" }
|
89
99
|
else
|
90
|
-
{ 'status' => 'critical', 'message' =>
|
100
|
+
{ 'status' => 'critical', 'message' => "Graylog2 server is responding but not healthy: #{status_text}" }
|
91
101
|
end
|
92
102
|
rescue Errno::ECONNREFUSED => e
|
93
103
|
{ 'status' => 'critical', 'message' => e.message }
|
data/bin/metrics-graylog.py
CHANGED
@@ -1,45 +1,9 @@
|
|
1
|
-
#!/usr/bin/python
|
1
|
+
#!/usr/bin/env python
|
2
2
|
|
3
|
-
import
|
4
|
-
import json
|
3
|
+
import os
|
5
4
|
import sys
|
6
|
-
import getopt
|
7
|
-
import socket
|
8
|
-
import time
|
9
5
|
|
10
|
-
def main(argv):
|
11
|
-
host = socket.getfqdn()
|
12
|
-
user = "graylog2"
|
13
|
-
password = "mypass"
|
14
|
-
port = "12900"
|
15
|
-
try:
|
16
|
-
opts, args = getopt.getopt(argv, "h:u:p:P:", ["host=","user=","pass=","port="])
|
17
|
-
except getopt.GetoptError:
|
18
|
-
print 'flag error'
|
19
|
-
sys.exit(2)
|
20
|
-
for opt, arg in opts:
|
21
|
-
if opt in ("-h", "--host"):
|
22
|
-
host = arg
|
23
|
-
elif opt in ("-u", "--user"):
|
24
|
-
user = arg
|
25
|
-
elif opt in ("-p", "--pass"):
|
26
|
-
password = arg
|
27
|
-
elif opt in ("-P", "--port"):
|
28
|
-
port = arg
|
29
6
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
authhandler = urllib2.HTTPBasicAuthHandler(passman)
|
34
|
-
opener = urllib2.build_opener(authhandler)
|
35
|
-
urllib2.install_opener(opener)
|
36
|
-
|
37
|
-
pagehandle = urllib2.urlopen('http://'+ host + ':' + port + '/system/metrics')
|
38
|
-
data = json.load(pagehandle)
|
39
|
-
|
40
|
-
print 'graylog.%s.graylog.kafkajournal.uncommittedMessages %d %d\n' % (host, data['gauges']['org.graylog2.shared.journal.KafkaJournal.uncommittedMessages']['value'], int(time.time()))
|
41
|
-
print 'graylog.%s.graylog.kafkajournal.unflushedMessages %d %d\n' % (host, data['gauges']['org.graylog2.shared.journal.KafkaJournal.unflushedMessages']['value'], int(time.time()))
|
42
|
-
sys.exit(0)
|
43
|
-
|
44
|
-
if __name__ == "__main__":
|
45
|
-
main(sys.argv[1:])
|
7
|
+
script = os.path.splitext(os.path.abspath( __file__ ))[0]
|
8
|
+
print script
|
9
|
+
os.execv(script + '.rb', sys.argv)
|
data/bin/metrics-graylog.rb
CHANGED
@@ -1,6 +1,130 @@
|
|
1
|
-
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# metrics-graylog.rb
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
#
|
7
|
+
# OUTPUT:
|
8
|
+
# metric data
|
9
|
+
#
|
10
|
+
# PLATFORMS:
|
11
|
+
# Linux
|
12
|
+
#
|
13
|
+
# DEPENDENCIES:
|
14
|
+
# gem: sensu-plugin
|
15
|
+
# gem: rest-client
|
16
|
+
# gem: json
|
17
|
+
#
|
18
|
+
# USAGE:
|
19
|
+
# metrics-graylog.rb -u user -p passwd
|
20
|
+
#
|
21
|
+
# NOTES:
|
22
|
+
# Without --all, this script returns two metrics, as the original version of
|
23
|
+
# this script did:
|
24
|
+
#
|
25
|
+
# graylog metric metric name -> sensu metric name
|
26
|
+
# org.graylog2.shared.journal.KafkaJournal.uncommittedMessages -> graylog.HOST.graylog.kafkajournal.uncommittedMessages
|
27
|
+
# org.graylog2.shared.journal.KafkaJournal.unflushedMessages -> graylog.HOST.graylog.kafkajournal.unflushedMessages
|
28
|
+
#
|
29
|
+
# LICENSE:
|
30
|
+
# nathan hruby <nhruby@gmail.com
|
31
|
+
# SugarCRM
|
32
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
33
|
+
# for details.
|
34
|
+
#
|
2
35
|
|
3
|
-
|
4
|
-
|
36
|
+
require 'sensu-plugin/metric/cli'
|
37
|
+
require 'json'
|
38
|
+
require 'rest-client'
|
5
39
|
|
6
|
-
|
40
|
+
class MetricsGraylog < Sensu::Plugin::Metric::CLI::Graphite
|
41
|
+
option :host,
|
42
|
+
description: 'Graylog host',
|
43
|
+
short: '-h',
|
44
|
+
long: '--host HOST',
|
45
|
+
default: 'localhost'
|
46
|
+
|
47
|
+
option :username,
|
48
|
+
description: 'Graylog username',
|
49
|
+
short: '-u',
|
50
|
+
long: '--username USERNAME',
|
51
|
+
default: 'admin',
|
52
|
+
required: true
|
53
|
+
|
54
|
+
option :password,
|
55
|
+
description: 'Graylog password',
|
56
|
+
short: '-p',
|
57
|
+
long: '--password PASSWORD',
|
58
|
+
required: true
|
59
|
+
|
60
|
+
option :port,
|
61
|
+
description: 'Graylog API port',
|
62
|
+
short: '-P',
|
63
|
+
long: '--port PORT',
|
64
|
+
default: '12900'
|
65
|
+
|
66
|
+
option :apipath,
|
67
|
+
description: 'Graylog API path prefix',
|
68
|
+
short: '-a',
|
69
|
+
long: '--apipath /api',
|
70
|
+
default: ''
|
71
|
+
|
72
|
+
option :scheme,
|
73
|
+
description: 'All metric naming scheme',
|
74
|
+
long: '--scheme SCHEME',
|
75
|
+
short: '-s SCHEME',
|
76
|
+
default: "#{Socket.gethostname}.graylog"
|
77
|
+
|
78
|
+
option :all,
|
79
|
+
description: 'Get all metrics',
|
80
|
+
long: '--all',
|
81
|
+
boolean: true,
|
82
|
+
default: false
|
83
|
+
|
84
|
+
def run
|
85
|
+
if config[:all]
|
86
|
+
all_output
|
87
|
+
else
|
88
|
+
original_output
|
89
|
+
end
|
90
|
+
ok
|
91
|
+
rescue => e
|
92
|
+
unknown e.message
|
93
|
+
end
|
94
|
+
|
95
|
+
def acquire_stats
|
96
|
+
resource = RestClient::Resource.new "http://#{config[:host]}:#{config[:port]}#{config[:apipath]}/system/metrics", config[:username], config[:password]
|
97
|
+
JSON.parse(resource.get)
|
98
|
+
rescue Errno::ECONNREFUSED => e
|
99
|
+
critical e.message
|
100
|
+
end
|
101
|
+
|
102
|
+
# XXX: only doing counters and guages since they map nicely to line data
|
103
|
+
# format. Skipping meters, histograms, and timers till I can figure out
|
104
|
+
# sensible representation. I don't want to throw bad data in and then have
|
105
|
+
# to maintain it forever.
|
106
|
+
def all_output
|
107
|
+
data = acquire_stats
|
108
|
+
timestamp = Time.now.to_i
|
109
|
+
# sample line
|
110
|
+
# some-hostname-here.graylog.gauges.org.graylog2.shared.journal.KafkaJournal.writtenMessages 123 1489185301
|
111
|
+
%w( gauges counters ).each do |type|
|
112
|
+
data[type].each do |k, v|
|
113
|
+
# XXX: nrh: this is a random array but I have no idea what it supposed to
|
114
|
+
# contain
|
115
|
+
next if k == 'jvm.threads.deadlocks'
|
116
|
+
output format('%s %2f %d', "#{config[:scheme]}.#{type}.#{k}", v['value'].to_f, timestamp)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def original_output
|
122
|
+
data = acquire_stats
|
123
|
+
timestamp = Time.now.to_i
|
124
|
+
host = Socket.gethostname
|
125
|
+
uncommitted_messages = data['gauges']['org.graylog2.shared.journal.KafkaJournal.uncommittedMessages']['value']
|
126
|
+
unflushed_messages = data['gauges']['org.graylog2.shared.journal.KafkaJournal.unflushedMessages']['value']
|
127
|
+
output format('graylog.%s.graylog.kafkajournal.uncommittedMessages %d %d', host, uncommitted_messages, timestamp)
|
128
|
+
output format('graylog.%s.graylog.kafkajournal.unflushedMessages %d %d', host, unflushed_messages, timestamp)
|
129
|
+
end
|
130
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugins-graylog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sensu-Plugins and contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sensu-plugin
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.2
|
19
|
+
version: '1.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.2
|
26
|
+
version: '1.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rest-client
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -42,130 +42,144 @@ dependencies:
|
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '1.7'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.7'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: codeclimate-test-reporter
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0.4'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0.4'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: github-markup
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - ~>
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '1.3'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - ~>
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1.3'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: pry
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - ~>
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0.10'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - ~>
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0.10'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rubocop
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - ~>
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
103
|
+
version: 0.40.0
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - ~>
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
110
|
+
version: 0.40.0
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: rspec
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - ~>
|
115
|
+
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '3.1'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - ~>
|
122
|
+
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '3.1'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: rake
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- - ~>
|
129
|
+
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '10.0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- - ~>
|
136
|
+
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '10.0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: redcarpet
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- - ~>
|
143
|
+
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
145
|
version: '3.2'
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- - ~>
|
150
|
+
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '3.2'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: yard
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
|
-
- - ~>
|
157
|
+
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
159
|
version: '0.8'
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
|
-
- - ~>
|
164
|
+
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0.8'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: webmock
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '2.3'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '2.3'
|
167
181
|
description: Sensu graylog plugins
|
168
|
-
email: <sensu-users@googlegroups.com>
|
182
|
+
email: "<sensu-users@googlegroups.com>"
|
169
183
|
executables:
|
170
184
|
- check-graylog-buffers.rb
|
171
185
|
- check-graylog2-alive.rb
|
@@ -199,12 +213,12 @@ require_paths:
|
|
199
213
|
- lib
|
200
214
|
required_ruby_version: !ruby/object:Gem::Requirement
|
201
215
|
requirements:
|
202
|
-
- -
|
216
|
+
- - ">="
|
203
217
|
- !ruby/object:Gem::Version
|
204
|
-
version:
|
218
|
+
version: 2.0.0
|
205
219
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
206
220
|
requirements:
|
207
|
-
- -
|
221
|
+
- - ">="
|
208
222
|
- !ruby/object:Gem::Version
|
209
223
|
version: '0'
|
210
224
|
requirements: []
|