sensu-plugins-statful 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 264ccfabcd5eb485366a3357ae094fa8a70c628e
4
+ data.tar.gz: 6f8f768dd02937ee0da6bbdd41633b0ae25b2583
5
+ SHA512:
6
+ metadata.gz: c26c6693b53cb1c9c1918cccbc7b8cb68ae347cd4e253493e7faffda2f6a33c34f46d31d485ac12c71d90441a5deb4d8d12ea93051a22a297b3978d5c484a8cd
7
+ data.tar.gz: e93b020d6b49d5f695d73b75993cdfe707d51419e320fc240eea39b7df555efa2bfc2dd484430b65abfcf15f9fff04621e1f9de54712c7f4ec75feea8a1e848e
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Mindera
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ ## Sensu-Plugins-Statful
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/sensu-plugins-statful.svg)](http://badge.fury.io/rb/sensu-plugins-statful)
4
+
5
+ ## Functionality
6
+
7
+ ## Files
8
+ * bin/metrics-statful.rb
9
+
10
+ ## Usage
11
+
12
+ **metrics-statful**
13
+ ```
14
+ {
15
+ "metrics-statful": {
16
+ "client": {
17
+ "transport": "http",
18
+ "token": "my_token",
19
+ "dryRun": true
20
+ },
21
+ "handler": {
22
+ "status": true,
23
+ "logging": true
24
+ }
25
+ }
26
+ }
27
+ ```
28
+
29
+ The example above will allow you to test the handler without actually ingest metrics into Statful - it will print the potential metrics to stdout.
30
+
31
+ ### Client
32
+
33
+ The client section is used to configure the statful client that will ingest metrics into Statful.
34
+
35
+ The configuration is the same as the statful-ruby-client detailed [here](https://github.com/statful/statful-client-ruby/blob/master/README.md#reference).
36
+
37
+ Please note that the `flush_size` option will always be overwritten to `1` in order to actually ingest metrics since the sensu handler isn't long lived.
38
+
39
+ ### Handler
40
+
41
+ The handler section is used to configure the behaviour of the handler itself as described in the table below:
42
+
43
+ | Option | Description | Type | Default | Required |
44
+ |:---|:---|:---|:---|:---|
45
+ | _status_ | Defines if a metrics with the value of the check status should be sent. | `Boolean` | `false` | **NO** |
46
+ | _logging_ | Defines the handler should log the statful client messages to the log. | `Boolean` | `false` | **NO** |
47
+
48
+ ## Installation
49
+
50
+ [Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
51
+
52
+ ## Authors
53
+
54
+ [Mindera - Software Craft](https://github.com/Mindera)
55
+
56
+ ## License
57
+
58
+ Statful sensu plugins are available under the MIT license. See the [LICENSE](https://raw.githubusercontent.com/statful/sensu-plugins-statful/master/LICENSE) file for more information.
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # metrics-statful.rb
4
+ #
5
+ # DESCRIPTION:
6
+ # Sensu handler to ingest metrics into statful (https://statful.com/).
7
+ #
8
+ # PLATFORMS:
9
+ # Linux
10
+ #
11
+ # DEPENDENCIES:
12
+ # gem: sensu-plugin
13
+ # gem: statful-client
14
+ #
15
+
16
+ require 'sensu-handler'
17
+ require 'statful-client'
18
+
19
+ require_relative '../lib/logger_mixin.rb'
20
+
21
+ class SensuMetricsStatful < Sensu::Handler
22
+ def initialize
23
+ super
24
+
25
+ @client_config = settings['metrics-statful']['client']
26
+
27
+ # Always flush on every metric since the sensu's handler isn't long lived
28
+ @client_config['flush_size'] = 1
29
+
30
+ @handler_config = settings['metrics-statful']['handler']
31
+
32
+ if logging?
33
+ # Log to stdout in order to be sent to sensu's log
34
+ @client_config['logger'] = Logger.new(STDOUT)
35
+ end
36
+
37
+ @statful = StatfulClient.new(@client_config)
38
+ end
39
+
40
+ def filter; end
41
+
42
+ def handle
43
+ check = @event['check']
44
+
45
+ check_metric = check['name']
46
+ check_timestamp = check['timestamp']
47
+ check_status = check['status']
48
+
49
+ if status_unknown?
50
+ if ingest_status?
51
+ ingest_status("status.#{check_metric}", check_status, check_timestamp)
52
+ end
53
+ else
54
+ if ingest_status?
55
+ ingest_status("status.#{check_metric}", check_status, check_timestamp)
56
+ end
57
+
58
+ begin
59
+ require_relative "../lib/parsers/#{check_metric}.rb"
60
+ check_value = Statful::Parser.parse(check['output'])
61
+ ingest_output("output.#{check_metric}", check_value, check_timestamp)
62
+ rescue LoadError
63
+ # Do not spam the log with unsupported checks messages
64
+ # puts "Check #{check_metric} not supported"
65
+ exit
66
+ end
67
+ end
68
+ end
69
+
70
+ private
71
+
72
+ def logging?
73
+ @handler_config['logging'].nil? ? false : @handler_config['logging']
74
+ end
75
+
76
+ def status_unknown?
77
+ @event['check']['status'] == 3
78
+ end
79
+
80
+ def ingest_status?
81
+ @handler_config['status'].nil? ? false : @handler_config['status']
82
+ end
83
+
84
+ def ingest_status(metric, status, timestamp)
85
+ @statful.put(metric, status, { :timestamp => timestamp });
86
+ end
87
+
88
+ def ingest_output(metric, value, timestamp)
89
+ @statful.put(metric, value, { :timestamp => timestamp });
90
+ end
91
+ end
@@ -0,0 +1,9 @@
1
+ require 'logger'
2
+
3
+ # Logger mixin to be injected on the statful client
4
+ # This is needed in order to get dryrun to log to stdout
5
+ class Logger
6
+ def debug(msg)
7
+ puts msg
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+
2
+ module Statful
3
+ class Parser
4
+ # Parses the check_cpu output and returns the total percentage of cpu in use
5
+ def self.parse(output)
6
+ # Output example:
7
+ # CheckCPU TOTAL OK: total=19.19 user=17.17 nice=0.0 system=1.01 idle=80.81 iowait=0.0 irq=0.0 softirq=1.01 steal=0.0 guest=0.0
8
+
9
+ if !output.nil?
10
+ output.split(' ')[3].split('=')[1]
11
+ else
12
+ puts 'Check output is nil'
13
+ exit
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+
2
+ module Statful
3
+ class Parser
4
+ # Parses the check_keepalive output and returns the number of seconds since the last client keepalive
5
+ def self.parse(output)
6
+ # Output example:
7
+ # Keepalive sent from client -117 seconds ago
8
+
9
+ if !output.nil?
10
+ output.split(' ')[4].to_i.abs
11
+ else
12
+ puts 'Check output is nil'
13
+ exit
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+
2
+ module Statful
3
+ class Parser
4
+ # Parses the check_memory_percent output and returns the percentage of memory in use
5
+ def self.parse(output)
6
+ # Output example:
7
+ # MEM OK - system memory usage: 6%
8
+
9
+ if !output.nil?
10
+ output.split(' ').last.split('%')[0]
11
+ else
12
+ puts 'Check output is nil'
13
+ exit
14
+ end
15
+ end
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sensu-plugins-statful
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Miguel Fonseca
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: statful-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sensu-plugin
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Statful plugins for sensu (https://www.statful.com)
56
+ email: miguel.fonseca@mindera.com
57
+ executables:
58
+ - metrics-statful.rb
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - LICENSE
63
+ - README.md
64
+ - bin/metrics-statful.rb
65
+ - lib/logger_mixin.rb
66
+ - lib/parsers/check_cpu.rb
67
+ - lib/parsers/check_keepalive.rb
68
+ - lib/parsers/check_memory_percent.rb
69
+ homepage: https://github.com/statful/sensu-plugins-statful
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.5.1
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Statful plugins for sensu
93
+ test_files: []