newrelic_postgres_plugin 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/newrelic_postgres_plugin/agent.rb +62 -51
- data/lib/newrelic_postgres_plugin.rb +1 -1
- data/newrelic_postgres_plugin.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49e0f69488f29a73417c293ccc51c0157f1c91be
|
4
|
+
data.tar.gz: eac1744679e6e7a36a1a87461d407cf66fcfaab5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a8dab6c229fd5806e70d2114e9ffe697339daf62575d4c49a3ff76c5dad23278d6f4221ffd2fbf2de3ccd47e2ffb99feee30f4697c2c4644d0eb4062cd78695
|
7
|
+
data.tar.gz: e84d2b09ea7a8e81dbe04f5a69dd9a9245a6a4677f2e6ad212110137169051d502f3eed6084a2b0f47fb0c8438cecd5687b619ea0d2a6d082c20e596a0de0692
|
@@ -7,51 +7,6 @@ require 'pg'
|
|
7
7
|
|
8
8
|
module NewRelic::PostgresPlugin
|
9
9
|
|
10
|
-
BACKEND_QUERY = %Q(
|
11
|
-
SELECT count(*) - ( SELECT count(*) FROM pg_stat_activity WHERE
|
12
|
-
#{
|
13
|
-
if nine_two?
|
14
|
-
"state <> 'idle'"
|
15
|
-
else
|
16
|
-
"current_query <> '<IDLE>'"
|
17
|
-
end
|
18
|
-
}
|
19
|
-
) AS backends_active, ( SELECT count(*) FROM pg_stat_activity WHERE
|
20
|
-
#{
|
21
|
-
if nine_two?
|
22
|
-
"AND state = 'idle'"
|
23
|
-
else
|
24
|
-
"AND current_query = '<IDLE>'"
|
25
|
-
end
|
26
|
-
}
|
27
|
-
) AS backends_idle FROM pg_stat_activity;
|
28
|
-
)
|
29
|
-
DATABASE_QUERY = %Q(
|
30
|
-
SELECT * FROM pg_stat_database;
|
31
|
-
)
|
32
|
-
BGWRITER_QUERY = %Q(
|
33
|
-
SELECT * FROM pg_stat_bgwriter;
|
34
|
-
)
|
35
|
-
INDEX_COUNT_QUERY = %Q(
|
36
|
-
SELECT count(1) as indexes FROM pg_class WHERE relkind = 'i';
|
37
|
-
)
|
38
|
-
INDEX_HIT_RATE_QUERY = %Q(
|
39
|
-
SELECT
|
40
|
-
'index hit rate' AS name,
|
41
|
-
(sum(idx_blks_hit)) / sum(idx_blks_hit + idx_blks_read) AS ratio
|
42
|
-
FROM pg_statio_user_indexes
|
43
|
-
UNION ALL
|
44
|
-
SELECT
|
45
|
-
'cache hit rate' AS name,
|
46
|
-
sum(heap_blks_hit) / (sum(heap_blks_hit) + sum(heap_blks_read)) AS ratio
|
47
|
-
FROM pg_statio_user_tables;
|
48
|
-
)
|
49
|
-
INDEX_SIZE_QUERY = %Q(
|
50
|
-
SELECT pg_size_pretty(sum(relpages*8192)) AS size
|
51
|
-
FROM pg_class
|
52
|
-
WHERE reltype = 0;
|
53
|
-
)
|
54
|
-
|
55
10
|
# Register and run the agent
|
56
11
|
def self.run
|
57
12
|
# Register this agent.
|
@@ -63,6 +18,7 @@ module NewRelic::PostgresPlugin
|
|
63
18
|
|
64
19
|
|
65
20
|
class Agent < NewRelic::Plugin::Agent::Base
|
21
|
+
|
66
22
|
agent_guid 'com.boundless.postgres'
|
67
23
|
agent_version '1.0.0'
|
68
24
|
agent_config_options :host, :port, :user, :password, :dbname, :sslmode
|
@@ -126,14 +82,14 @@ module NewRelic::PostgresPlugin
|
|
126
82
|
|
127
83
|
|
128
84
|
def report_backend_metrics
|
129
|
-
@connection.exec(
|
85
|
+
@connection.exec(backend_query) do |result|
|
130
86
|
report_metric "Backends/Active", 'queries', result[0]['backends_active']
|
131
87
|
report_metric "Backends/Idle", 'queries', result[0]['backends_idle']
|
132
88
|
end
|
133
89
|
end
|
134
90
|
|
135
91
|
def report_database_metrics
|
136
|
-
@connection.exec(
|
92
|
+
@connection.exec(database_query) do |result|
|
137
93
|
result.each do |row|
|
138
94
|
database_name = row['datname']
|
139
95
|
report_metric "Database/#{database_name}/Backends", '', row['numbackends'].to_i
|
@@ -152,25 +108,80 @@ module NewRelic::PostgresPlugin
|
|
152
108
|
end
|
153
109
|
|
154
110
|
def report_bgwriter_metrics
|
155
|
-
@connection.exec(
|
111
|
+
@connection.exec(bgwriter_query) do |result|
|
156
112
|
report_derived_metric "Background Writer/Checkpoints/Scheduled", 'checkpoints', result[0]['checkpoints_timed'].to_i
|
157
113
|
report_derived_metric "Background Writer/Checkpoints/Requested", 'checkpoints', result[0]['checkpoints_requests'].to_i
|
158
114
|
end
|
159
115
|
end
|
160
116
|
|
161
117
|
def report_index_metrics
|
162
|
-
@connection.exec(
|
118
|
+
@connection.exec(index_count_query) do |result|
|
163
119
|
report_metric "Indexes/Total", 'indexes', result[0]['indexes'].to_i
|
164
120
|
report_metric "Indexes/Disk Utilization", 'bytes', result[0]['size_indexes'].to_f
|
165
121
|
end
|
166
|
-
@connection.exec(
|
122
|
+
@connection.exec(index_hit_rate_query) do |result|
|
167
123
|
report_metric "Indexes/Hit Rate", '%', result[0]['ratio'].to_f
|
168
124
|
report_metric "Indexes/Cache Hit Rate", '%', result[1]['ratio'].to_f
|
169
125
|
end
|
170
|
-
@connection.exec(
|
126
|
+
@connection.exec(index_size_query) do |result|
|
171
127
|
report_metric "Indexes/Size", 'bytes', result[0]['size'].to_f
|
172
128
|
end
|
173
129
|
end
|
174
130
|
|
131
|
+
def backend_query
|
132
|
+
%Q(
|
133
|
+
SELECT count(*) - ( SELECT count(*) FROM pg_stat_activity WHERE
|
134
|
+
#{
|
135
|
+
if nine_two?
|
136
|
+
"state <> 'idle'"
|
137
|
+
else
|
138
|
+
"current_query <> '<IDLE>'"
|
139
|
+
end
|
140
|
+
}
|
141
|
+
) AS backends_active, ( SELECT count(*) FROM pg_stat_activity WHERE
|
142
|
+
#{
|
143
|
+
if nine_two?
|
144
|
+
"AND state = 'idle'"
|
145
|
+
else
|
146
|
+
"AND current_query = '<IDLE>'"
|
147
|
+
end
|
148
|
+
}
|
149
|
+
) AS backends_idle FROM pg_stat_activity;
|
150
|
+
)
|
151
|
+
end
|
152
|
+
|
153
|
+
def database_query
|
154
|
+
"SELECT * FROM pg_stat_database;"
|
155
|
+
end
|
156
|
+
|
157
|
+
def bgwriter_query
|
158
|
+
"SELECT * FROM pg_stat_bgwriter;"
|
159
|
+
end
|
160
|
+
|
161
|
+
def index_count_query
|
162
|
+
"SELECT count(1) as indexes FROM pg_class WHERE relkind = 'i';"
|
163
|
+
|
164
|
+
def index_hit_rate_query
|
165
|
+
%Q(
|
166
|
+
SELECT
|
167
|
+
'index hit rate' AS name,
|
168
|
+
(sum(idx_blks_hit)) / sum(idx_blks_hit + idx_blks_read) AS ratio
|
169
|
+
FROM pg_statio_user_indexes
|
170
|
+
UNION ALL
|
171
|
+
SELECT
|
172
|
+
'cache hit rate' AS name,
|
173
|
+
sum(heap_blks_hit) / (sum(heap_blks_hit) + sum(heap_blks_read)) AS ratio
|
174
|
+
FROM pg_statio_user_tables;
|
175
|
+
)
|
176
|
+
end
|
177
|
+
|
178
|
+
def index_size_query
|
179
|
+
%Q(
|
180
|
+
SELECT pg_size_pretty(sum(relpages*8192)) AS size
|
181
|
+
FROM pg_class
|
182
|
+
WHERE reltype = 0;
|
183
|
+
)
|
184
|
+
end
|
185
|
+
|
175
186
|
end
|
176
187
|
end
|
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
|
|
13
13
|
## If your rubyforge_project name is different, then edit it and comment out
|
14
14
|
## the sub! line in the Rakefile
|
15
15
|
s.name = 'newrelic_postgres_plugin'
|
16
|
-
s.version = '0.1.
|
16
|
+
s.version = '0.1.1'
|
17
17
|
s.date = '2013-06-20'
|
18
18
|
s.rubyforge_project = 'newrelic_postgres_plugin'
|
19
19
|
|