riemann-postgresql 0.1.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.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +4 -0
  4. data/bin/riemann-postgresql +81 -0
  5. metadata +74 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 26b1d0ec04347119f73404441fe6f68f58ab4919
4
+ data.tar.gz: 5656878affd0d2318bd4cc663f380f65f7dc3714
5
+ SHA512:
6
+ metadata.gz: 52cbc74ed7143562f3219a09e3db4ee179cdab3834139d9c2a0852af96d45d0bbf7572776e85c5ff92a6feb5e5229dc5e6916b2b03da4644fb38c633f7cdb703
7
+ data.tar.gz: 3043419b741ac4a63c3e5a7b2714975fb340c811d92695d940b76106a12bde74fee8a73ac46f86d3648726056c888f3aa9cdf2532ccf61ed28c29bb4a3a1264a
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2011 Kyle Kingsbury
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ Riemann PostgreSQL
2
+ =============
3
+
4
+ PostgreSQL Riemann client.
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Reports PostgreSQL statistics to Riemann.
4
+ # http://www.postgresql.org/docs/9.2/static/monitoring-stats.html
5
+
6
+ require 'riemann/tools'
7
+
8
+ class Riemann::Tools::PostgreSQL
9
+ include Riemann::Tools
10
+ require 'pg'
11
+
12
+ opt :postgresql_host, "PostgreSQL Server Hostname", :type => String, :default => "localhost"
13
+ opt :postgresql_port, "PostgreSQL Server Port", :default => 5432
14
+ opt :postgresql_username, "Authenticated username", :type => String, :default => "postgres"
15
+ opt :postgresql_password, "User's password", :type => String, :default => "postgres"
16
+ opt :postgresql_database, "Database to connect", :type => String, :default => "postgres"
17
+
18
+ def initialize
19
+ begin
20
+ @conn = PG.connect(:host => opts[:postgresql_host],
21
+ :port => opts[:postgresql_port],
22
+ :user => opts[:postgresql_username],
23
+ :password => opts[:postgresql_password],
24
+ :dbname => opts[:postgresql_database])
25
+ rescue
26
+ PG::Error
27
+ puts "Error: Unable to connect with PostgreSQL server."
28
+ exit 1
29
+ end
30
+ end
31
+
32
+ def tick
33
+ @conn.transaction do
34
+
35
+ # General DB statistics.
36
+ @conn.exec("DECLARE general CURSOR FOR SELECT pg_stat_database.*, pg_database_size \
37
+ (pg_database.datname) AS size FROM pg_database JOIN pg_stat_database ON \
38
+ pg_database.datname = pg_stat_database.datname WHERE pg_stat_database.datname \
39
+ NOT IN ('template0', 'template1', 'postgres')")
40
+
41
+ result = @conn.exec("FETCH ALL IN general")
42
+
43
+ keys = result.fields.collect.to_a
44
+ result.values.collect do |row|
45
+ vals = row.collect.to_a
46
+ vals.each_with_index {|val, index|
47
+ if index > 1
48
+ report(
49
+ :host => opts[:postgresql_host].dup,
50
+ :service => "DB #{vals[1]} #{keys[index]}",
51
+ :metric => vals[index].to_f,
52
+ :state => 'ok',
53
+ :description => "PostgreSQL DB #{keys[index]}".gsub("_", " "),
54
+ :tags => ['postgresql']
55
+ )
56
+ end
57
+ }
58
+ end
59
+
60
+ # Each DB specific connection counts.
61
+ @conn.exec("DECLARE connection CURSOR FOR SELECT datname, count(datname) FROM pg_stat_activity \
62
+ GROUP BY pg_stat_activity.datname")
63
+
64
+ result = @conn.exec("FETCH ALL in connection")
65
+ result.values.collect do |row|
66
+ vals = row.collect.to_a
67
+ report(
68
+ :host => opts[:postgresql_host].dup,
69
+ :service => "DB #{vals[0]} connections",
70
+ :metric => vals[1].to_f,
71
+ :state => 'ok',
72
+ :description => "PostgreSQL DB Connections",
73
+ :tags => ['postgresql']
74
+ )
75
+ end
76
+
77
+ end
78
+ end
79
+ end
80
+
81
+ Riemann::Tools::PostgreSQL.run
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: riemann-postgresql
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Pradeep Chhetri
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: riemann-tools
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: pg
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.17.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.17.1
41
+ description:
42
+ email: pradeep.chhetri89@gmail.com
43
+ executables:
44
+ - riemann-postgresql
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - bin/riemann-postgresql
49
+ - LICENSE
50
+ - README.md
51
+ homepage: https://github.com/riemann/riemann-postgresql
52
+ licenses: []
53
+ metadata: {}
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: 2.0.0
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project: riemann-postgresql
70
+ rubygems_version: 2.0.14
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: PostgreSQL Riemann Client
74
+ test_files: []