collective-metrics 0.2.1 → 0.2.2

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: 8a1b7942a5478c2d4172906cb5b37a2f6646ab76
4
- data.tar.gz: ed459633992d33f6d2d1378f689c057515ec9c60
3
+ metadata.gz: 16a6befd91bd072a768a156befa6a1aad8237b69
4
+ data.tar.gz: 8c1ae9faca49b5f44933a73f07972164c2fb6644
5
5
  SHA512:
6
- metadata.gz: 6ada75194ab9a260c3d74a5d62a95ddbb5755d9a10d5714fb80012664809d52544f6ceb17cd4596e413e0638ccb9bf8f85e33738ce5876d04ff04184d39680df
7
- data.tar.gz: d7e65e934cb676c39da634e7a0ce3ae9ed1c7db19b8375f8c1598faebceb120486bb10594127abaf3d14cd5b85eb6148677ccb17c037f57732df632c9218bdd6
6
+ metadata.gz: 5b92b6d24fa654e26bf93e012d31be9266d84b291f78283e81b5705314fdaa610d64313fe604dece6ff5b070e937649a9fc22b739e2e9ca63c484de713a4da17
7
+ data.tar.gz: b765a52456d03ceb3a851b394613545dde710ca0ce0bd245cd277aecc3eacc6dcdba13abd3279d8087a8703d0f1422ee1b0c9ab3a28a2865c2ecf4aef294f000
data/README.md CHANGED
@@ -23,6 +23,7 @@ It includes collectors for the following:
23
23
  * Memcached
24
24
  * RabbitMQ (You need to have the management plugin enabled)
25
25
  * MongoDB
26
+ * Postgres
26
27
 
27
28
  ## Installation
28
29
 
data/lib/collective.rb CHANGED
@@ -16,6 +16,7 @@ module Collective
16
16
  autoload :Honeybadger, 'collective/collectors/honeybadger'
17
17
  autoload :Newrelic, 'collective/collectors/newrelic'
18
18
  autoload :PGBouncer, 'collective/collectors/pgbouncer'
19
+ autoload :Postgres, 'collective/collectors/postgres'
19
20
  end
20
21
 
21
22
  class << self
@@ -0,0 +1,42 @@
1
+ module Collective::Collectors
2
+ class Postgres < Collective::Collector
3
+ MEGABYTE = 1024 * 1024
4
+
5
+ requires :pg
6
+
7
+ resolution '600s'
8
+
9
+ collect do
10
+ group "postgres.#{connection_options[:dbname]}" do |group|
11
+ instrument_relation_size_data group
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def instrument_relation_size_data(group)
18
+ begin
19
+ conn = PG.connect(connection_options)
20
+ size_tuples = conn.exec(size_query)
21
+ size_tuples.each do |tuple|
22
+ group.instrument "#{tuple['relation']}.size", (tuple['total_size'].to_f / MEGABYTE).round(2), units: 'MB'
23
+ end
24
+ ensure
25
+ conn.close if conn != nil
26
+ end
27
+ end
28
+
29
+ def size_query
30
+ "SELECT relname AS relation, pg_total_relation_size(C.oid) AS total_size
31
+ FROM pg_class C
32
+ LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
33
+ WHERE nspname NOT IN ('pg_catalog', 'information_schema')
34
+ AND C.relkind <> 'i'
35
+ AND nspname !~ '^pg_toast';"
36
+ end
37
+
38
+ def connection_options
39
+ options[:connection] || {}
40
+ end
41
+ end
42
+ end
@@ -1,3 +1,3 @@
1
1
  module Collective
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: collective-metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric J. Holmes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-25 00:00:00.000000000 Z
11
+ date: 2016-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rufus-scheduler
@@ -155,6 +155,7 @@ files:
155
155
  - lib/collective/collectors/mongodb.rb
156
156
  - lib/collective/collectors/newrelic.rb
157
157
  - lib/collective/collectors/pgbouncer.rb
158
+ - lib/collective/collectors/postgres.rb
158
159
  - lib/collective/collectors/rabbitmq.rb
159
160
  - lib/collective/collectors/redis.rb
160
161
  - lib/collective/collectors/sidekiq.rb