Skip to content

Commit e3f6ae2

Browse files
committed
initial commit
0 parents  commit e3f6ae2

20 files changed

+1049
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#### 0.0.1.alpha.1

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[Development Documentation](http://sensu-plugins.github.io/development/)

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2015 devops@yieldbot.com
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.

README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
## Sensu-Plugins-disk-checks
2+
3+
[![Build Status](https://travis-ci.org/sensu-plugins/sensu-plugins-postgres.svg?branch=master)][1]
4+
[![Gem Version](https://badge.fury.io/rb/sensu-plugins-postgres.svg)][2]
5+
[![Code Climate](https://codeclimate.com/github/sensu-plugins/sensu-plugins-postgres/badges/gpa.svg)][3]
6+
[![Test Coverage](https://codeclimate.com/github/sensu-plugins/sensu-plugins-postgres/badges/coverage.svg)][4]
7+
[![Dependency Status](https://gemnasium.com/sensu-plugins/sensu-plugins-postgres.svg)][5]
8+
9+
## Functionality
10+
11+
## Files
12+
*
13+
*
14+
*
15+
*
16+
17+
## Usage
18+
19+
## Installation
20+
21+
Add the public key (if you haven’t already) as a trusted certificate
22+
23+
```
24+
gem cert --add <(curl -Ls https://raw.githubusercontent.com/sensu-plugins/sensu-plugins.github.io/master/certs/sensu-plugins.pem)
25+
gem install sensu-plugins-postgres -P MediumSecurity
26+
```
27+
28+
You can also download the key from /certs/ within each repository.
29+
30+
#### Rubygems
31+
32+
`gem install sensu-plugins-postgres`
33+
34+
#### Bundler
35+
36+
Add *sensu-plugins-disk-checks* to your Gemfile and run `bundle install` or `bundle update`
37+
38+
#### Chef
39+
40+
Using the Sensu **sensu_gem** LWRP
41+
```
42+
sensu_gem 'sensu-plugins-postgres' do
43+
options('--prerelease')
44+
version '0.0.1.alpha.4'
45+
end
46+
```
47+
48+
Using the Chef **gem_package** resource
49+
```
50+
gem_package 'sensu-plugins-postgres' do
51+
options('--prerelease')
52+
version '0.0.1.alpha.4'
53+
end
54+
```
55+
56+
## Notes
57+
58+
[1]:[https://travis-ci.org/sensu-plugins/sensu-plugins-postgres]
59+
[2]:[http://badge.fury.io/rb/sensu-plugins-postgres]
60+
[3]:[https://codeclimate.com/github/sensu-plugins/sensu-plugins-postgres]
61+
[4]:[https://codeclimate.com/github/sensu-plugins/sensu-plugins-postgres]
62+
[5]:[https://gemnasium.com/sensu-plugins/sensu-plugins-postgres]

Rakefile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
require 'bundler/gem_tasks'
3+
4+
require 'rspec/core/rake_task'
5+
6+
require 'yard'
7+
8+
require 'github/markup'
9+
10+
require 'rubocop/rake_task'
11+
12+
require 'redcarpet'
13+
14+
require 'yard/rake/yardoc_task'
15+
16+
17+
desc 'Don\'t run Rubocop for unsupported versions'
18+
begin
19+
if RUBY_VERSION >= '2.0.0'
20+
args = [:spec, :make_bin_executable, :yard, :rubocop]
21+
else
22+
args = [:spec, :make_bin_executable, :yard]
23+
end
24+
end
25+
26+
YARD::Rake::YardocTask.new do |t|
27+
OTHER_PATHS = %w()
28+
t.files = ['lib/**/*.rb', 'bin/**/*.rb', OTHER_PATHS]
29+
t.options = %w(--markup-provider=redcarpet --markup=markdown --main=README.md --files CHANGELOG.md)
30+
end
31+
32+
Rubocop::RakeTask.new
33+
34+
RSpec::Core::RakeTask.new(:spec) do |r|
35+
r.pattern = FileList['**/**/*_spec.rb']
36+
end
37+
38+
desc 'Make all plugins executable'
39+
task :make_bin_executable do
40+
`chmod -R +x bin/*`
41+
end
42+
43+
task default: args

Vagrantfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
VAGRANTFILE_API_VERSION = '2'
5+
6+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
7+
8+
config.vm.box = 'chef/centos-6.6'
9+
config.vm.box_download_checksum = true
10+
config.vm.box_download_checksum_type = 'md5'
11+
config.vm.hostname = 'sensu-plugins-dev'
12+
13+
script = <<EOF
14+
sudo yum update -y
15+
sudo yum groupinstall -y development
16+
sudo yum install -y vim nano
17+
#sudo yum install -y ImagicMagic ImageMagick-devel mysql-devel # needed for bundle install
18+
gpg2 --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3
19+
curl -L get.rvm.io | bash -s stable
20+
source /home/vagrant/.rvm/scripts/rvm
21+
rvm reload
22+
#rvm install 1.9.3
23+
rvm install 2.1.4
24+
#rvm install 2.0.0
25+
#rvm use 1.9.3@sensu_plugins --create
26+
#rvm use 2.0.0@sensu_plugins --create
27+
rvm use 2.1.4@sensu_plugins --create
28+
rvm use 2.1.4@sensu_plugins --default
29+
EOF
30+
31+
config.vm.provision 'shell', inline: script, privileged: false
32+
end

bin/postgres-alive.rb

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env ruby
2+
#
3+
# Postgres Alive Plugin
4+
#
5+
# This plugin attempts to login to postgres with provided credentials.
6+
#
7+
# Copyright 2012 Lewis Preson & Tom Bassindale
8+
#
9+
# Released under the same terms as Sensu (the MIT license); see LICENSE
10+
# for details.
11+
12+
require 'rubygems' if RUBY_VERSION < '1.9.0'
13+
require 'sensu-plugin/check/cli'
14+
require 'pg'
15+
16+
class CheckPostgres < Sensu::Plugin::Check::CLI
17+
option :user,
18+
description: 'Postgres User',
19+
short: '-u USER',
20+
long: '--user USER'
21+
22+
option :password,
23+
description: 'Postgres Password',
24+
short: '-p PASS',
25+
long: '--password PASS'
26+
27+
option :hostname,
28+
description: 'Hostname to login to',
29+
short: '-h HOST',
30+
long: '--hostname HOST'
31+
32+
option :database,
33+
description: 'Database schema to connect to',
34+
short: '-d DATABASE',
35+
long: '--database DATABASE',
36+
default: 'test'
37+
38+
option :port,
39+
description: 'Database port',
40+
short: '-P PORT',
41+
long: '--port PORT',
42+
default: 5432
43+
44+
def run
45+
con = PG::Connection.new(config[:hostname], config[:port], nil, nil, config[:database], config[:user], config[:password])
46+
res = con.exec('select version();')
47+
info = res.first
48+
49+
ok "Server version: #{info}"
50+
rescue PG::Error => e
51+
critical "Error message: #{e.error.split("\n").first}"
52+
ensure
53+
con.close if con
54+
end
55+
end

bin/postgres-connections-metric.rb

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env ruby
2+
#
3+
# Postgres Connection Metrics
4+
# ===
5+
#
6+
# Dependencies
7+
# -----------
8+
# - Ruby gem `pg`
9+
#
10+
#
11+
# Copyright 2012 Kwarter, Inc <platforms@kwarter.com>
12+
# Author Gilles Devaux <gilles.devaux@gmail.com>
13+
#
14+
# Released under the same terms as Sensu (the MIT license); see LICENSE
15+
# for details.
16+
17+
require 'rubygems' if RUBY_VERSION < '1.9.0'
18+
require 'sensu-plugin/metric/cli'
19+
require 'pg'
20+
require 'socket'
21+
22+
class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
23+
option :user,
24+
description: 'Postgres User',
25+
short: '-u USER',
26+
long: '--user USER'
27+
28+
option :password,
29+
description: 'Postgres Password',
30+
short: '-p PASS',
31+
long: '--password PASS'
32+
33+
option :hostname,
34+
description: 'Hostname to login to',
35+
short: '-h HOST',
36+
long: '--hostname HOST',
37+
default: 'localhost'
38+
39+
option :port,
40+
description: 'Database port',
41+
short: '-P PORT',
42+
long: '--port PORT',
43+
default: 5432
44+
45+
option :db,
46+
description: 'Database name',
47+
short: '-d DB',
48+
long: '--db DB',
49+
default: 'postgres'
50+
51+
option :scheme,
52+
description: 'Metric naming scheme, text to prepend to $queue_name.$metric',
53+
long: '--scheme SCHEME',
54+
default: "#{Socket.gethostname}.postgresql"
55+
56+
def run
57+
timestamp = Time.now.to_i
58+
59+
con = PG::Connection.new(config[:hostname], config[:port], nil, nil, 'postgres', config[:user], config[:password])
60+
request = [
61+
'select count(*), waiting from pg_stat_activity',
62+
"where datname = '#{config[:db]}' group by waiting"
63+
]
64+
65+
metrics = {
66+
active: 0,
67+
waiting: 0
68+
}
69+
con.exec(request.join(' ')) do |result|
70+
result.each do |row|
71+
if row['waiting']
72+
metrics[:waiting] = row['count']
73+
else
74+
metrics[:active] = row['count']
75+
end
76+
end
77+
end
78+
79+
metrics.each do |metric, value|
80+
output "#{config[:scheme]}.connections.#{config[:db]}.#{metric}", value, timestamp
81+
end
82+
83+
ok
84+
end
85+
end

bin/postgres-dbsize-metric.rb

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env ruby
2+
#
3+
# Postgres DBSize Metrics
4+
# ===
5+
#
6+
# Dependencies
7+
# -----------
8+
# - Ruby gem `pg`
9+
#
10+
#
11+
# Copyright 2012 Kwarter, Inc <platforms@kwarter.com>
12+
# Author Gilles Devaux <gilles.devaux@gmail.com>
13+
#
14+
# Released under the same terms as Sensu (the MIT license); see LICENSE
15+
# for details.
16+
17+
require 'rubygems' if RUBY_VERSION < '1.9.0'
18+
require 'sensu-plugin/metric/cli'
19+
require 'pg'
20+
require 'socket'
21+
22+
class PostgresStatsDBMetrics < Sensu::Plugin::Metric::CLI::Graphite
23+
option :user,
24+
description: 'Postgres User',
25+
short: '-u USER',
26+
long: '--user USER'
27+
28+
option :password,
29+
description: 'Postgres Password',
30+
short: '-p PASS',
31+
long: '--password PASS'
32+
33+
option :hostname,
34+
description: 'Hostname to login to',
35+
short: '-h HOST',
36+
long: '--hostname HOST',
37+
default: 'localhost'
38+
39+
option :port,
40+
description: 'Database port',
41+
short: '-P PORT',
42+
long: '--port PORT',
43+
default: 5432
44+
45+
option :db,
46+
description: 'Database name',
47+
short: '-d DB',
48+
long: '--db DB',
49+
default: 'postgres'
50+
51+
option :scheme,
52+
description: 'Metric naming scheme, text to prepend to $queue_name.$metric',
53+
long: '--scheme SCHEME',
54+
default: "#{Socket.gethostname}.postgresql"
55+
56+
def run
57+
timestamp = Time.now.to_i
58+
59+
con = PG::Connection.new(config[:hostname], config[:port], nil, nil, 'postgres', config[:user], config[:password])
60+
request = [
61+
"select pg_database_size('#{config[:db]}')"
62+
]
63+
64+
con.exec(request.join(' ')) do |result|
65+
result.each do |row|
66+
output "#{config[:scheme]}.size.#{config[:db]}", row['pg_database_size'], timestamp
67+
end
68+
end
69+
70+
ok
71+
end
72+
end

0 commit comments

Comments
 (0)