sensu-checks-php-fpm 0.2.5

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 01eb287a1d8b7e3b20090ca44459426c31399851
4
+ data.tar.gz: c2fb910700c4dc37dae20a2b3f839efbd64ff5d5
5
+ SHA512:
6
+ metadata.gz: e799966d5b7bf79e53fb185013d4bd1eb9bc28a2efe63b9ec40f6ec83939bd510c83848c1fc7e1e63f80c4a05ef7c635d026acb888d1a66e6c711a43b43698a7
7
+ data.tar.gz: 395a703bdb80213407c94c13560a380772507bcf5d2db9f80aecf9deac81cf153781755a079be726c7902a9bb59044083ca3136836e2f6337f17b9c3684e37c5
data/LICENSE ADDED
@@ -0,0 +1,16 @@
1
+ A modified MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Dirk Gustke
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ Neither the Software, nor any derivative product, shall be used to operate weapons
10
+
11
+ Neither the Software, nor any derivative product, shall be used for any military use
12
+
13
+ Neither the Software, nor any derivative product, shall be used for any use by intelligence agencies
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+
@@ -0,0 +1,134 @@
1
+ # sensu-checks-php-fpm
2
+
3
+ Check your php-fpm setup over sockets or on their direct ip/port combination.
4
+ So you avoid checking nginx, apache, XYZ along with the check.
5
+
6
+ ## DEPENDENCIES
7
+
8
+ Testing the sockets directly depends on `libfcgi0ldbl`
9
+
10
+
11
+ ## INSTALLATION
12
+
13
+ This gem will give an actual installation explanation, as the default sensu plugins miss it and the sensu documentation lacks any detailed explanation.
14
+
15
+ If this gem is listed in rubygems.org, you can just go ahead and do
16
+ ```
17
+ sensu-install -p sensu-check-php-fpm
18
+ ```
19
+
20
+ If this gem is not listed there, you can still install it; the hard way.
21
+ ```
22
+ git clone git@github.com:vmpublishing/sensu-checks-php-fpm [SOME_PATH]
23
+ cd [SOME_PATH]
24
+ /opt/sensu/embedded/bin/gem build *.gemspec
25
+ /opt/sensu/embedded/bin/gem install *.gem
26
+ ```
27
+
28
+ Alter `/opt/sensu/embedded/bin/gem` to the path to the gem-file sensu uses on your machine.
29
+
30
+
31
+ ## USAGE
32
+
33
+ ### ping check
34
+
35
+ #### Parameters
36
+
37
+ | name | parameter_name | default value | required | description |
38
+ |------|----------------|---------------|----------|-------------|
39
+ | hostname | -h, --host | | yes, unless socket is set | This sets the "Host: " HTTP header for the request |
40
+ | port | -P, --port | 80 | no | The port of php-fpm to connect to |
41
+ | address | -a, --address | localhost | no | The address of php-fpm to connect to. Hostname or IP |
42
+ | query_string | -q, --query-string | no | Optional query string to send along with the path (ie. 'pool=some_pool&sticky_flag=foo' ) |
43
+ | ping_path | -p, --ping-path | /ping | no | The configured path, where the ping resides. Check your pool config. |
44
+ | response | -r, --response | pong | no | The configured response to the ping request |
45
+ | request_timeout | -t, --request-timeout | 60 | no | HTTP request timeout. When the sensu timeout is greater than this and this timeout is reached, it will produce a critical error |
46
+ | socket | -s, --socket | nil | no | Check ping over the socket, instead over http. This renders 'hostname', 'port', 'address' and 'request_timeout' useless |
47
+
48
+ #### sample json config file for sockets
49
+ ```
50
+ {
51
+ "checks": {
52
+ "check_php_fpm_ping": {
53
+ "command": "check-php-fpm-ping.rb -s /var/run/php-fpm.sock -p /ping",
54
+ "standalone": true,
55
+ "subscribers": ["all"],
56
+ "interval": 10,
57
+ "timeout": 120,
58
+ "ttl": 180
59
+ }
60
+ }
61
+ }
62
+ ```
63
+
64
+ #### sample json config file for http
65
+ ```
66
+ {
67
+ "checks": {
68
+ "check_php_fpm_ping": {
69
+ "command": "check-php-fpm-ping.rb -a 127.0.0.1 -P 5678 -h www.example.com -p /ping -t 60",
70
+ "standalone": true,
71
+ "subscribers": ["all"],
72
+ "interval": 10,
73
+ "timeout": 120,
74
+ "ttl": 180
75
+ }
76
+ }
77
+ }
78
+ ```
79
+
80
+ ### metrics
81
+
82
+ #### Parameters
83
+
84
+ | name | parameter_name | default value | required | description |
85
+ |------|----------------|---------------|----------|-------------|
86
+ | hostname | -h, --host | | yes, unless socket is set | This sets the "Host: " HTTP header for the request |
87
+ | port | -P, --port | 80 | no | The port of php-fpm to connect to |
88
+ | address | -a, --address | localhost | no | The address of php-fpm to connect to. Hostname or IP |
89
+ | query_string | -q, --query-string | no | Optional query string to send along with the path (ie. 'pool=some_pool&sticky_flag=foo') |
90
+ | status_path | -p, --ping-path | /status | no | The configured path, where the status resides. Check your pool config. |
91
+ | request_timeout | -t, --request-timeout | 60 | no | HTTP request timeout. When the sensu timeout is greater than this and this timeout is reached, it will produce a critical error |
92
+ | socket | -s, --socket | nil | no | Check ping over the socket, instead over http. This renders 'hostname', 'port', 'address' and 'request_timeout' useless |
93
+ | scheme | -C, --scheme | [hostname].php-fpm | no | Metric naming scheme, text to prepend to metric and scheme_append |
94
+ | scheme_append | -S, --scheme_append | nil | no | Set a string that will be placed right after the host identification and the script identification but before the measurements (ie. hostname.php-fpm.scheme_append.slow_requests) |
95
+
96
+ #### sample json config file for sockets
97
+ ```
98
+ {
99
+ "metrics": {
100
+ "metric_php_fpm_status": {
101
+ "type": "metric",
102
+ "command": "metric-php-fpm-status.rb -s /var/run/php-fpm.sock -p /status",
103
+ "standalone": true,
104
+ "subscribers": ["all"],
105
+ "interval": 10,
106
+ "timeout": 120,
107
+ "ttl": 180
108
+ }
109
+ }
110
+ }
111
+ ```
112
+
113
+ #### sample json config file for http
114
+ ```
115
+ {
116
+ "metrics": {
117
+ "metric_php_fpm_status": {
118
+ "type": "metric",
119
+ "command": "metric-php-fpm-status.rb -a 127.0.0.1 -P 5678 -h www.example.com -p /ping -t 60",
120
+ "standalone": true,
121
+ "subscribers": ["all"],
122
+ "interval": 10,
123
+ "timeout": 120,
124
+ "ttl": 180
125
+ }
126
+ }
127
+ }
128
+ ```
129
+
130
+
131
+ ## CONTRIBUTING
132
+
133
+ Bug reports and pull requests are welcome on GitHub at https://github.com/vmpublishing/sensu-checks-php-fpm.
134
+
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'sensu-plugin/check/cli'
4
+ require 'net/http'
5
+
6
+
7
+ class CheckPhpFpmPing < Sensu::Plugin::Check::CLI
8
+
9
+ option :hostname,
10
+ short: '-h HOSTNAME',
11
+ long: '--host HOSTNAME',
12
+ description: 'This sets the "Host: " parameter of the HTTP-Request, not the address (ie. www.example.com). When not using sockets, this is required!',
13
+ default: ''
14
+
15
+ option :port,
16
+ short: '-P PORT',
17
+ long: '--port PORT',
18
+ description: 'The php-fpm port to check',
19
+ default: '80'
20
+
21
+ option :address,
22
+ short: '-a ADDRESS',
23
+ long: '--address ADDRESS',
24
+ description: "The php-fpm address to check. examples: '127.0.0.1' or 'localhost'",
25
+ default: 'localhost'
26
+
27
+ option :query_string,
28
+ short: '-q ARGUMENTS',
29
+ long: '--query-string ARGUMENTS',
30
+ description: "optional query string to send (ie: 'pool=some_pool&stick_flag=13')",
31
+ default: ''
32
+
33
+ option :ping_path,
34
+ short: '-p PATH',
35
+ long: '--ping-path PATH',
36
+ description: 'The configured path for the ping test in your php-fpm.ini / pool*.ini',
37
+ default: '/ping'
38
+
39
+ option :response,
40
+ short: '-r RESPONSE',
41
+ long: '--response RESPONSE',
42
+ description: 'The expected response on the ping request',
43
+ default: 'pong'
44
+
45
+ option :socket,
46
+ short: '-s SOCKET',
47
+ long: '--soclet SOCKET',
48
+ description: 'Request ping over socket. This renders :hostname, :port, :address and :request_timeout useless',
49
+ default: nil
50
+
51
+ option :request_timeout,
52
+ short: '-t TIMEOUT',
53
+ long: '--request-timeout TIMEOUT',
54
+ description: 'Set the connect timeout to X',
55
+ default: '60'
56
+
57
+ def run
58
+
59
+ if config[:socket] # do something completely different on this flag
60
+ response = `SCRIPT_NAME=#{config[:ping_path]} SCRIPT_FILENAME=#{config[:ping_path]} QUERY_STRING=#{config[:query_string]} REQUEST_METHOD=GET cgi-fcgi -bind -connect #{config[:socket]}`
61
+ response_body = response.split("\r\n\r\n")[1]
62
+ if config[:response] == response_body
63
+ ok "PHP-FPM said '#{response_body}'"
64
+ else
65
+ critical "PHP-FPM said '#{response.body}' instead of '#{config[:response]}'"
66
+ end
67
+ else # ok, do the http stuff
68
+ uri = URI("http://#{config[:hostname]}#{config[:ping_path]}?#{config[:query_string]}") # actually hostname does not matter at this point, as it is overwritten
69
+
70
+ response = Net::HTTP.start(config[:address], config[:port], read_timeout: config[:request_timeout].to_i) do |http|
71
+ request = Net::HTTP::Get.new(uri)
72
+ request['Host'] = config[:hostname] # it matters here
73
+
74
+ http.request(request)
75
+ end
76
+
77
+ if '200' == response.code
78
+ if config[:response] == response.body
79
+ ok "PHP-FPM said '#{response.body}'"
80
+ else
81
+ critical "PHP-FPM said '#{response.body}' instead of '#{config[:response]}'"
82
+ end
83
+ else
84
+ critical "Expected 200, #{response.code} found"
85
+ end # response.code
86
+
87
+ end # http section
88
+
89
+ rescue Net::ReadTimeout => e
90
+ critical "PHP-FPM request timeout: '#{e.message}'"
91
+ end # def run
92
+
93
+ end # class
94
+
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'sensu-plugin/metric/cli'
4
+ require 'net/http'
5
+
6
+
7
+ class MetricPhpFpmStatus < Sensu::Plugin::Metric::CLI::Graphite
8
+
9
+ option :hostname,
10
+ short: '-h HOSTNAME',
11
+ long: '--host HOSTNAME',
12
+ description: 'This sets the "Host: " parameter of the HTTP-Request, not the address (ie. www.example.com). When not using sockets, this is required!',
13
+ default: ''
14
+
15
+ option :port,
16
+ short: '-P PORT',
17
+ long: '--port PORT',
18
+ description: 'The php-fpm port to check',
19
+ default: '80'
20
+
21
+ option :address,
22
+ short: '-a ADDRESS',
23
+ long: '--address ADDRESS',
24
+ description: "The php-fpm address to check. examples: '127.0.0.1' or 'localhost'",
25
+ default: 'localhost'
26
+
27
+ option :query_string,
28
+ short: '-q ARGUMENTS',
29
+ long: '--query-string ARGUMENTS',
30
+ description: "optional query string to send (ie: 'pool=some_pool&stick_flag=13')",
31
+ default: ''
32
+
33
+ option :status_path,
34
+ short: '-p PATH',
35
+ long: '--ping-path PATH',
36
+ description: 'The configured path for the ping test in your php-fpm.ini / pool*.ini',
37
+ default: '/status'
38
+
39
+ option :socket,
40
+ short: '-s SOCKET',
41
+ long: '--soclet SOCKET',
42
+ description: 'Request ping over socket. This renders :hostname, :port, :address and :request_timeout useless',
43
+ default: nil
44
+
45
+ option :request_timeout,
46
+ short: '-t TIMEOUT',
47
+ long: '--request-timeout TIMEOUT',
48
+ description: 'Set the connect timeout to X',
49
+ default: '60'
50
+
51
+ option :scheme,
52
+ short: '-C SCHEME',
53
+ long: '--scheme SCHEME',
54
+ description: 'Metric naming scheme, text to prepend to metric and scheme_append',
55
+ default: "#{Socket.gethostname}.php-fpm"
56
+
57
+ option :scheme_append,
58
+ short: '-S APPEND_STRING',
59
+ long: '--scheme-append APPEND_STRING',
60
+ description: 'Set a string that will be placed right after the host identification and the script identification but before the measurements',
61
+ default: nil
62
+
63
+
64
+ def run
65
+
66
+ body = if config[:socket] # do something completely different on this flag
67
+
68
+ response = `SCRIPT_NAME=#{config[:status_path]} SCRIPT_FILENAME=#{config[:status_path]} QUERY_STRING=#{config[:query_string]} REQUEST_METHOD=GET cgi-fcgi -bind -connect #{config[:socket]}`
69
+ response.split("\r\n\r\n")[1]
70
+
71
+ else # ok, do the http stuff
72
+
73
+ uri = URI("http://#{config[:hostname]}#{config[:status_path]}?#{config[:query_string]}") # actually hostname does not matter at this point, as it is overwritten
74
+
75
+ response = Net::HTTP.start(config[:address], config[:port], read_timeout: config[:request_timeout].to_i) do |http|
76
+ request = Net::HTTP::Get.new(uri)
77
+ request['Host'] = config[:hostname] # it matters here
78
+
79
+ http.request(request)
80
+ end
81
+ response.body
82
+
83
+ end # end http section
84
+
85
+ accepted_fields = %w(
86
+ start_since
87
+ accepted_conn
88
+ listen_queue
89
+ max_listen_queue
90
+ listen_queue_len
91
+ idle_processes
92
+ active_processes
93
+ total_processes
94
+ max_active_processes
95
+ max_children_reached
96
+ slow_requests
97
+ )
98
+ body.gsub("\r", '').split("\n").each do |status_line|
99
+ field_name, field_value = status_line.split(':').map(&:strip).map{|value| value.gsub(' ', '_')}
100
+ next unless accepted_fields.include?(field_name)
101
+
102
+ if config[:scheme_append]
103
+ output "#{config[:scheme]}.#{config[:scheme_append]}.#{field_name}", field_value
104
+ else
105
+ output "#{config[:scheme]}.#{field_name}", field_value
106
+ end
107
+ end
108
+
109
+ ok
110
+ rescue Net::ReadTimeout => e # it's the job of the check to determine errors, so do nothing
111
+ end # def run
112
+
113
+ end # class
114
+
@@ -0,0 +1,2 @@
1
+ require 'sensu-checks-php-fpm/version.rb'
2
+
@@ -0,0 +1,10 @@
1
+ module SensuChecksPhpFpm
2
+ module Version
3
+ MAJOR = 0
4
+ MINOR = 2
5
+ PATCH = 5
6
+
7
+ VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
+ end
9
+ end
10
+
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sensu-checks-php-fpm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.5
5
+ platform: ruby
6
+ authors:
7
+ - vmpublishing development
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sensu-plugin
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: sensu gem to check php-fpm directly, without nginx or apache, using socket
56
+ [or possibly ip]. Also support for multiple pools. Also support for http (if you
57
+ really want to)
58
+ email:
59
+ - dev@vmpublishing.com
60
+ executables:
61
+ - metric-php-fpm-status.rb
62
+ - check-php-fpm-ping.rb
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - LICENSE
67
+ - README.md
68
+ - bin/check-php-fpm-ping.rb
69
+ - bin/metric-php-fpm-status.rb
70
+ - lib/sensu-checks-php-fpm.rb
71
+ - lib/sensu-checks-php-fpm/version.rb
72
+ homepage: https://github.com/vmpublishing/sensu-checks-php-fpm
73
+ licenses:
74
+ - Nonstandard
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.5.1
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: sensu gem to check php-fpm directly, without nginx or apache, using socket
96
+ [or possibly ip]
97
+ test_files: []