forked from sensu-plugins/sensu-plugins-php-fpm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matt Jones
committed
Feb 17, 2015
0 parents
commit 38959e4
Showing
17 changed files
with
455 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/.bundle/ | ||
/.yardoc | ||
/Gemfile.lock | ||
/_yardoc/ | ||
/coverage/ | ||
/doc/ | ||
/pkg/ | ||
/spec/reports/ | ||
/tmp/ | ||
*.bundle | ||
*.so | ||
*.o | ||
*.a | ||
mkmf.log | ||
.vagrant/* | ||
.DS_Store | ||
.idea/* | ||
*.gem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
MethodLength: | ||
Max: 200 | ||
|
||
LineLength: | ||
Max: 160 | ||
|
||
FileName: | ||
Enabled: false | ||
|
||
PerceivedComplexity: | ||
Enabled: false | ||
|
||
CyclomaticComplexity: | ||
Enabled: false | ||
|
||
ClassLength: | ||
Enabled: false | ||
|
||
IfUnlessModifier: | ||
Enabled: false | ||
|
||
RegexpLiteral: | ||
Enabled: false | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
language: ruby | ||
cache: | ||
- bundler | ||
install: | ||
- bundle install | ||
rvm: | ||
- 1.9.3 | ||
- 2.0 | ||
- 2.1 | ||
notifications: | ||
email: | ||
recipients: | ||
- mattjones@yieldbot.com | ||
on_success: change | ||
on_failure: always | ||
|
||
script: | ||
- 'bundle exec rake default' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#### 0.0.1.alpha.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[Development Documentation](http://sensu-plugins.github.io/development/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source 'https://rubygems.org' | ||
|
||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2015 devops@yieldbot.com | ||
|
||
MIT License | ||
|
||
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: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
## Sensu-Plugins-php-fpm | ||
|
||
[](https://travis-ci.org/sensu-plugins/sensu-plugins-php-fpm) | ||
[](http://badge.fury.io/rb/sensu-plugins-php-fpm) | ||
[](https://codeclimate.com/github/sensu-plugins/sensu-plugins-php-fpm) | ||
[](https://codeclimate.com/github/sensu-plugins/sensu-plugins-php-fpm) | ||
[](https://gemnasium.com/sensu-plugins/sensu-plugins-php-fpm) | ||
|
||
## Functionality | ||
|
||
## Files | ||
* bin/check-php-fpm | ||
* bin/metrics-php-fpm | ||
|
||
## Usage | ||
|
||
## Installation | ||
|
||
Add the public key (if you haven’t already) as a trusted certificate | ||
|
||
``` | ||
gem cert --add <(curl -Ls https://raw.githubusercontent.com/sensu-plugins/sensu-plugins.github.io/master/certs/sensu-plugins.pem) | ||
gem install sensu-plugins-php-fpm -P MediumSecurity | ||
``` | ||
|
||
You can also download the key from /certs/ within each repository. | ||
|
||
#### Rubygems | ||
|
||
`gem install sensu-plugins-php-fpm` | ||
|
||
#### Bundler | ||
|
||
Add *sensu-plugins-disk-checks* to your Gemfile and run `bundle install` or `bundle update` | ||
|
||
#### Chef | ||
|
||
Using the Sensu **sensu_gem** LWRP | ||
``` | ||
sensu_gem 'sensu-plugins-php-fpm' do | ||
options('--prerelease') | ||
version '0.0.1' | ||
end | ||
``` | ||
|
||
Using the Chef **gem_package** resource | ||
``` | ||
gem_package 'sensu-plugins-php-fpm' do | ||
options('--prerelease') | ||
version '0.0.1' | ||
end | ||
``` | ||
|
||
## Notes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require 'bundler/gem_tasks' | ||
require 'rspec/core/rake_task' | ||
require 'yard' | ||
require 'github/markup' | ||
require 'rubocop/rake_task' | ||
require 'redcarpet' | ||
require 'yard/rake/yardoc_task' | ||
|
||
desc 'Don\'t run Rubocop for unsupported versions' | ||
begin | ||
if RUBY_VERSION >= '2.0.0' | ||
args = [:spec, :make_bin_executable, :yard, :rubocop] | ||
else | ||
args = [:spec, :make_bin_executable, :yard] | ||
end | ||
end | ||
|
||
YARD::Rake::YardocTask.new do |t| | ||
OTHER_PATHS = %w() | ||
t.files = ['lib/**/*.rb', 'bin/**/*.rb', OTHER_PATHS] | ||
t.options = %w(--markup-provider=redcarpet --markup=markdown --main=README.md --files CHANGELOG.md) | ||
end | ||
|
||
Rubocop::RakeTask.new | ||
|
||
RSpec::Core::RakeTask.new(:spec) do |r| | ||
r.pattern = FileList['**/**/*_spec.rb'] | ||
end | ||
|
||
desc 'Make all plugins executable' | ||
task :make_bin_executable do | ||
`chmod -R +x bin/***/*.rb` | ||
end | ||
|
||
task default: args |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# -*- mode: ruby -*- | ||
# vi: set ft=ruby : | ||
|
||
VAGRANTFILE_API_VERSION = '2' | ||
|
||
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | ||
|
||
config.vm.box = 'chef/centos-6.6' | ||
config.vm.box_download_checksum = true | ||
config.vm.box_download_checksum_type = 'md5' | ||
config.vm.hostname = 'sensu-plugins-dev' | ||
|
||
script = <<EOF | ||
sudo yum update -y | ||
sudo yum groupinstall -y development | ||
sudo yum install -y vim nano | ||
#sudo yum install -y ImagicMagic ImageMagick-devel mysql-devel # needed for bundle install | ||
gpg2 --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3 | ||
curl -L get.rvm.io | bash -s stable | ||
source /home/vagrant/.rvm/scripts/rvm | ||
rvm reload | ||
#rvm install 1.9.3 | ||
rvm install 2.1.4 | ||
#rvm install 2.0.0 | ||
#rvm use 1.9.3@sensu_plugins --create | ||
#rvm use 2.0.0@sensu_plugins --create | ||
rvm use 2.1.4@sensu_plugins --create | ||
rvm use 2.1.4@sensu_plugins --default | ||
EOF | ||
|
||
config.vm.provision 'shell', inline: script, privileged: false | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
This check use a nginx config in default vhost like : | ||
|
||
``` | ||
set $pool "www-data"; | ||
if ($arg_pool) { | ||
set $pool $arg_pool; | ||
} | ||
location ~ "/fpm-(status|ping)" { | ||
include /etc/nginx/fastcgi_params; | ||
fastcgi_pass unix:/var/run/php-$pool.sock; | ||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | ||
access_log off; | ||
allow 127.0.0.1; | ||
deny all; | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/usr/bin/env ruby | ||
# | ||
# Check PHP-FPM | ||
# === | ||
# | ||
# DESCRIPTION: | ||
# This plugin retrives php-fpm status, parse the default "pong response" | ||
# | ||
# PLATFORMS: | ||
# all | ||
# | ||
# DEPENDENCIES: | ||
# sensu-plugin Ruby gem | ||
# php-fpm ping configuration | ||
# | ||
# Released under the same terms as Sensu (the MIT license); see LICENSE | ||
# for details. | ||
|
||
require 'rubygems' if RUBY_VERSION < '1.9.0' | ||
require 'sensu-plugin/check/cli' | ||
require 'net/http' | ||
require 'uri' | ||
require 'socket' | ||
|
||
class CheckPHPFpm < Sensu::Plugin::Check::CLI | ||
option :pool, | ||
short: '-p POOL', | ||
long: '--pool POOL', | ||
description: 'Full POOL name to fpm ping page, example: https://yoursite.com/fpm-ping?pool=POOL', | ||
default: 'www-data' | ||
|
||
option :hostname, | ||
short: '-h HOSTNAME', | ||
long: '--host HOSTNAME', | ||
description: 'Nginx hostname', | ||
default: 'localhost' | ||
|
||
option :port, | ||
short: '-P PORT', | ||
long: '--port PORT', | ||
description: 'Nginx port', | ||
default: '80' | ||
|
||
option :path, | ||
short: '-q PATH', | ||
long: '--statspath PATH', | ||
description: 'Path to your fpm ping', | ||
default: 'fpm-ping?pool=' | ||
|
||
option :scheme, | ||
description: 'Metric naming scheme, text to prepend to metric', | ||
short: '-s SCHEME', | ||
long: '--scheme SCHEME', | ||
default: 'http://' | ||
|
||
option :response, | ||
description: 'Reponse of ping', | ||
short: '-r RESPONSE', | ||
long: '--response RESPONSE', | ||
default: 'pong' | ||
|
||
def run | ||
config[:url] = config[:scheme] + config[:hostname].to_s + ':' + config[:port].to_s + '/' + config[:path].to_s + config[:pool].to_s | ||
config[:fqdn] = Socket.gethostname | ||
uri = URI.parse(config[:url]) | ||
|
||
request = Net::HTTP::Get.new(uri.request_uri) | ||
http = Net::HTTP.new(uri.host, uri.port) | ||
response = http.request(request) | ||
|
||
if response.code == '200' | ||
if response.body == config[:response] | ||
ok "#{config[:response]}" | ||
else | ||
critical "#{response.body} instead of #{config[:response]}" | ||
end | ||
else | ||
critical "Error, http response code: #{response.code}" | ||
end | ||
|
||
# be safe | ||
critical 'unknown error' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/usr/bin/env ruby | ||
# | ||
# Pull php-fpm metrics from php-fpm status page | ||
# === | ||
# | ||
# Requires `crack` gem to parse xml. | ||
# | ||
# Copyright 2014 Ilari Makela ilari at i28.fi | ||
# | ||
# Released under the same terms as Sensu (the MIT license); see LICENSE | ||
# for details. | ||
|
||
require 'rubygems' if RUBY_VERSION < '1.9.0' | ||
require 'sensu-plugin/metric/cli' | ||
require 'net/https' | ||
require 'uri' | ||
require 'crack' | ||
|
||
class PhpfpmMetrics < Sensu::Plugin::Metric::CLI::Graphite | ||
option :url, | ||
short: '-u URL', | ||
long: '--url URL', | ||
description: 'Full URL to php-fpm status page, example: http://yoursite.com/php-fpm-status' | ||
|
||
option :scheme, | ||
description: 'Metric naming scheme, text to prepend to metric', | ||
short: '-s SCHEME', | ||
long: '--scheme SCHEME', | ||
default: "#{Socket.gethostname}.php_fpm" | ||
|
||
def run | ||
found = false | ||
attempts = 0 | ||
# #YELLOW | ||
until found || attempts >= 10 # rubocop:disable Style/Next | ||
attempts += 1 | ||
if config[:url] | ||
uri = URI.parse(config[:url]) | ||
http = Net::HTTP.new(uri.host, uri.port) | ||
if uri.scheme == 'https' | ||
http.use_ssl = true | ||
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | ||
end | ||
request = Net::HTTP::Get.new(uri.request_uri + '?xml') | ||
response = http.request(request) | ||
if response.code == '200' | ||
found = true | ||
elsif !response.header['location'].nil? | ||
config[:url] = response.header['location'] | ||
end | ||
end | ||
end # until | ||
|
||
stats = Crack::XML.parse(response.body) | ||
stat = %w(start_since accepted_conn listen_queue \ | ||
max_listen_queue \ | ||
listen_queue_len \ | ||
idle_processes \ | ||
active_processes \ | ||
total_processes \ | ||
max_active_processes \ | ||
max_children_reached \ | ||
slow_requests) | ||
stat.each do |name| | ||
output "#{config[:scheme]}.#{name}", stats['status'][name] | ||
end | ||
ok | ||
end | ||
end |
Oops, something went wrong.