sensu-plugins-nginx 2.0.0 → 2.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 05d1419977c60acb91e63b663fcc053cf8e76649
4
- data.tar.gz: 2b0476465460a7a844d5db59192f88af53590328
3
+ metadata.gz: 476205e6bed938636daf2e723fdca5d0547eadd5
4
+ data.tar.gz: 24104bf3d8f97424618621b661c752f22dee69a0
5
5
  SHA512:
6
- metadata.gz: c35f35a6c7a717e6a41feab1ebfd51aea9e8700a9f22cfdc6ec66584a57420771462475a21af709838aa304f6a6251a479ab86b802e31cbd2f84d7c368bdcd74
7
- data.tar.gz: 66050a2c8581f4806e9e539bd6057117d72d32d328e9a001fca7ed2faddc7e1dc138c9456b100d0e400d12637093aaf2d0178c2adf11d15f0edfe992a3b5ab02
6
+ metadata.gz: 95133fd68e7d3834c3c0e84cc18a78fea12f496a2720e0081c26e4d0ed4563f1f3f09ae476e57017a28b23f900e3ad4ea26a9b5b24491b697d56c2ac0108e722
7
+ data.tar.gz: 338d1d7f21e436e95fd277223e710c2451dc66551c15bda7ad412ff2b0ca576a35b29ac9a1740a1f4fa5c7142f98788adf6327993de03dbfb7351ac0cf37ca4d
data/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [2.1.0] - 2017-02-28
9
+ ### Added
10
+ - add `check-nginx-status` plugin (@hany)
11
+
8
12
  ## [2.0.0] - 2016-05-24
9
13
  ### Changed
10
14
  - remove support for rubies < 2.0
@@ -56,7 +60,8 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
56
60
  ## 0.0.1 - 2015-02-11 **YANKED**
57
61
  - initial stable release
58
62
 
59
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-nginx/compare/2.0.0...HEAD
63
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-nginx/compare/2.1.0...HEAD
64
+ [2.1.0]: https://github.com/sensu-plugins/sensu-plugins-nginx/compare/2.0.0...2.1.0
60
65
  [2.0.0]: https://github.com/sensu-plugins/sensu-plugins-nginx/compare/1.0.0...2.0.0
61
66
  [1.0.0]: https://github.com/sensu-plugins/sensu-plugins-nginx/compare/0.0.6...1.0.0
62
67
  [0.0.6]: https://github.com/sensu-plugins/sensu-plugins-nginx/compare/0.0.5...0.0.6
data/README.md CHANGED
@@ -10,11 +10,15 @@
10
10
 
11
11
  **metrics-nginx**
12
12
 
13
- Fetch the nginx status page and convert the response into graphite metrics
13
+ Fetch the nginx status page and convert the response into metrics
14
+
15
+ **check-nginx-status**
16
+
17
+ Check nginx statistics
14
18
 
15
19
  ## Files
16
20
  * bin/metrics-nginx.rb
17
- Get the nginx metrics from the status page url for use with Graphite
21
+ * bin/check-nginx-status.rb
18
22
 
19
23
  ## Usage
20
24
 
@@ -0,0 +1,139 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-nginx-status
4
+ #
5
+ # DESCRIPTION:
6
+ # Sensu Check that fetches Nginx Status
7
+ #
8
+ # OUTPUT:
9
+ # plain text
10
+ #
11
+ # PLATFORMS:
12
+ # Linux
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: sensu-plugin
16
+ #
17
+ # USAGE:
18
+ # You need to enable nginx status
19
+ # https://easyengine.io/tutorials/nginx/status-page/
20
+ # check-nginx-status.rb --help
21
+ #
22
+ # NOTES:
23
+ #
24
+ # LICENSE:
25
+ # Adapted from official metrics-nginx plugin (Pete Shima <me@peteshima.com>)
26
+ # Magic Online http://www.magic.fr @2016 - hanynowsky@gmail.com
27
+ # Released under the same terms as Sensu (the MIT license); see LICENSE for details.
28
+ # Last Modified October 2016
29
+ #
30
+
31
+ require 'net/https'
32
+ require 'uri'
33
+ require 'socket'
34
+ require 'sensu-plugin/check/cli'
35
+
36
+ #
37
+ # Nginx Status Check
38
+ #
39
+ class CheckNginxStatus < Sensu::Plugin::Check::CLI
40
+ option :url,
41
+ short: '-u URL',
42
+ long: '--url URL',
43
+ description: 'Full URL to nginx status page, example: https://yoursite.com/nginx_status This ignores ALL other options'
44
+
45
+ option :hostname,
46
+ short: '-h HOSTNAME',
47
+ long: '--host HOSTNAME', description: 'Nginx hostname', default: 'localhost'
48
+
49
+ option :port,
50
+ short: '-p PORT',
51
+ long: '--port PORT',
52
+ description: 'Nginx port',
53
+ default: '80'
54
+
55
+ option :activecon,
56
+ short: '-a ACTIVE_CONNECTION_THRESHOLD',
57
+ long: '--activecon ACTIVE_CONNECTION_THRESHOLD',
58
+ description: 'Active connections threshold',
59
+ default: 300
60
+
61
+ option :waitingreq,
62
+ short: '-w WAITING_REQUESTS_THRESHOLD',
63
+ long: '--waitingreq WAITING_REQUESTS_THRESHOLD',
64
+ description: 'Waiting requests threshold',
65
+ default: 30
66
+
67
+ option :path,
68
+ short: '-q STATUSPATH',
69
+ long: '--statspath STATUSPATH',
70
+ description: 'Path to your stub status module',
71
+ default: 'nginx_status'
72
+
73
+ option :hostheader,
74
+ long: '--hostheader HOSTHEADER',
75
+ description: 'Set the Host header to this string'
76
+
77
+ #
78
+ # Acquire Nginx Status
79
+ #
80
+ def statutor
81
+ found = false
82
+ attempts = 0
83
+ begin
84
+ until found || attempts >= 10
85
+ attempts += 1
86
+ if config[:url]
87
+ uri = URI.parse(config[:url])
88
+ http = Net::HTTP.new(uri.host, uri.port)
89
+ if uri.scheme == 'https'
90
+ http.use_ssl = true
91
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
92
+ end
93
+ request = Net::HTTP::Get.new(uri.request_uri)
94
+ if config[:hostheader]
95
+ request['Host'] = config[:hostheader]
96
+ end
97
+ response = http.request(request)
98
+ if response.code == '200'
99
+ found = true
100
+ elsif !response.header['location'].nil?
101
+ config[:url] = response.header['location']
102
+ end
103
+ else
104
+ response = Net::HTTP.start(config[:hostname], config[:port]) do |connection|
105
+ request = Net::HTTP::Get.new("/#{config[:path]}")
106
+ connection.request(request)
107
+ end
108
+ end
109
+ return response
110
+ end
111
+ rescue => e
112
+ unknown "Could not fetch Nginx status | #{e.message}"
113
+ end
114
+ end
115
+
116
+ #
117
+ # Main function
118
+ #
119
+ def run
120
+ code = statutor
121
+ #### Metrics
122
+ code.body.split(/\r?\n/).each do |line|
123
+ if line =~ /^Active connections:\s+(\d+)/
124
+ connections = line.match(/^Active connections:\s+(\d+)/).to_a
125
+ if connections[1].to_i > config[:activecon].to_i
126
+ warning "Active connections: #{connections[1]}"
127
+ end
128
+ end
129
+ if line =~ /^Reading:\s+(\d+).*Writing:\s+(\d+).*Waiting:\s+(\d+)/
130
+ queue = line.match(/^Reading:\s+(\d+).*Writing:\s+(\d+).*Waiting:\s+(\d+)/).to_a
131
+ warning "Waiting requests: #{queue[3]}" if queue[3].to_i > config[:waitingreq].to_i
132
+ end
133
+ end
134
+ #####
135
+ ok 'Nginx is Alive and healthy' if code.code.to_i == 200
136
+ warning 'Nginx Status endpoint is mis-configured' if code.code.to_i == 301
137
+ critical 'Nginx is Down'
138
+ end
139
+ end
@@ -1,7 +1,7 @@
1
1
  module SensuPluginsNginx
2
2
  module Version
3
3
  MAJOR = 2
4
- MINOR = 0
4
+ MINOR = 1
5
5
  PATCH = 0
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-nginx
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.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: 2016-05-24 00:00:00.000000000 Z
11
+ date: 2017-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-plugin
@@ -155,6 +155,7 @@ description: |-
155
155
  for metrics collection, including: metrics via `stub_status`.
156
156
  email: "<sensu-users@googlegroups.com>"
157
157
  executables:
158
+ - check-nginx-status.rb
158
159
  - metrics-nginx.rb
159
160
  extensions: []
160
161
  extra_rdoc_files: []
@@ -162,6 +163,7 @@ files:
162
163
  - CHANGELOG.md
163
164
  - LICENSE
164
165
  - README.md
166
+ - bin/check-nginx-status.rb
165
167
  - bin/metrics-nginx.rb
166
168
  - lib/sensu-plugins-nginx.rb
167
169
  - lib/sensu-plugins-nginx/version.rb
@@ -191,9 +193,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
193
  version: '0'
192
194
  requirements: []
193
195
  rubyforge_project:
194
- rubygems_version: 2.5.1
196
+ rubygems_version: 2.4.5
195
197
  signing_key:
196
198
  specification_version: 4
197
199
  summary: Sensu plugins for the NGINX server
198
200
  test_files: []
199
- has_rdoc: