-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql_exporter.yml
More file actions
308 lines (288 loc) · 9.65 KB
/
Copy pathsql_exporter.yml
File metadata and controls
308 lines (288 loc) · 9.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# SQL Exporter Configuration for pg_stat_monitor Metrics
# https://github.com/burningalchemist/sql_exporter
#
# This replaces the deprecated postgres-exporter custom queries feature
# with the dedicated, purpose-built sql_exporter tool.
# Global settings
global:
# Scrape timeout
scrape_timeout: 10s
# Minimum interval between collecting metrics from the same target
min_interval: 0s
# Maximum number of open connections to any one target
max_connections: 3
# Maximum number of idle connections to any one target
max_idle_connections: 3
# Target configuration
target:
# Data source name (will be overridden by environment variable)
data_source_name: 'postgresql://api:password@postgres:5432/ilmanhinta?sslmode=disable'
# Link to collectors
collectors: [pg_stat_monitor]
# Collector definitions
collectors:
# Collector for pg_stat_monitor detailed metrics
- collector_name: pg_stat_monitor
# Metrics definitions
metrics:
# Detailed query statistics by database, user, and command type
- metric_name: pg_stat_monitor_calls_total
type: counter
help: 'Number of times queries were executed'
key_labels:
- database
- username
- command_type
values: [calls]
query: |
SELECT
datname as database,
username,
COALESCE(cmd_type_text, 'UNKNOWN') as command_type,
SUM(calls) as calls
FROM pg_stat_monitor
WHERE datname IS NOT NULL
GROUP BY datname, username, cmd_type_text
- metric_name: pg_stat_monitor_exec_time_milliseconds_total
type: counter
help: 'Total execution time in milliseconds'
key_labels:
- database
- username
- command_type
values: [total_exec_time]
query: |
SELECT
datname as database,
username,
COALESCE(cmd_type_text, 'UNKNOWN') as command_type,
SUM(total_exec_time) as total_exec_time
FROM pg_stat_monitor
WHERE datname IS NOT NULL
GROUP BY datname, username, cmd_type_text
- metric_name: pg_stat_monitor_mean_exec_time_milliseconds
type: gauge
help: 'Average execution time in milliseconds'
key_labels:
- database
- username
- command_type
values: [mean_exec_time]
query: |
SELECT
datname as database,
username,
COALESCE(cmd_type_text, 'UNKNOWN') as command_type,
AVG(mean_exec_time) as mean_exec_time
FROM pg_stat_monitor
WHERE datname IS NOT NULL
GROUP BY datname, username, cmd_type_text
- metric_name: pg_stat_monitor_max_exec_time_milliseconds
type: gauge
help: 'Maximum execution time in milliseconds'
key_labels:
- database
- username
- command_type
values: [max_exec_time]
query: |
SELECT
datname as database,
username,
COALESCE(cmd_type_text, 'UNKNOWN') as command_type,
MAX(max_exec_time) as max_exec_time
FROM pg_stat_monitor
WHERE datname IS NOT NULL
GROUP BY datname, username, cmd_type_text
- metric_name: pg_stat_monitor_rows_total
type: counter
help: 'Total number of rows retrieved or affected'
key_labels:
- database
- username
- command_type
values: [rows]
query: |
SELECT
datname as database,
username,
COALESCE(cmd_type_text, 'UNKNOWN') as command_type,
SUM(rows) as rows
FROM pg_stat_monitor
WHERE datname IS NOT NULL
GROUP BY datname, username, cmd_type_text
- metric_name: pg_stat_monitor_shared_blks_hit_total
type: counter
help: 'Shared blocks cache hits'
key_labels:
- database
- username
- command_type
values: [shared_blks_hit]
query: |
SELECT
datname as database,
username,
COALESCE(cmd_type_text, 'UNKNOWN') as command_type,
SUM(shared_blks_hit) as shared_blks_hit
FROM pg_stat_monitor
WHERE datname IS NOT NULL
GROUP BY datname, username, cmd_type_text
- metric_name: pg_stat_monitor_shared_blks_read_total
type: counter
help: 'Shared blocks read from disk'
key_labels:
- database
- username
- command_type
values: [shared_blks_read]
query: |
SELECT
datname as database,
username,
COALESCE(cmd_type_text, 'UNKNOWN') as command_type,
SUM(shared_blks_read) as shared_blks_read
FROM pg_stat_monitor
WHERE datname IS NOT NULL
GROUP BY datname, username, cmd_type_text
- metric_name: pg_stat_monitor_cpu_user_time_seconds_total
type: counter
help: 'CPU user time in seconds'
key_labels:
- database
- username
- command_type
values: [cpu_user_time]
query: |
SELECT
datname as database,
username,
COALESCE(cmd_type_text, 'UNKNOWN') as command_type,
SUM(cpu_user_time) as cpu_user_time
FROM pg_stat_monitor
WHERE datname IS NOT NULL
GROUP BY datname, username, cmd_type_text
- metric_name: pg_stat_monitor_cpu_sys_time_seconds_total
type: counter
help: 'CPU system time in seconds'
key_labels:
- database
- username
- command_type
values: [cpu_sys_time]
query: |
SELECT
datname as database,
username,
COALESCE(cmd_type_text, 'UNKNOWN') as command_type,
SUM(cpu_sys_time) as cpu_sys_time
FROM pg_stat_monitor
WHERE datname IS NOT NULL
GROUP BY datname, username, cmd_type_text
# Summary metrics by command type
- metric_name: pg_stat_monitor_unique_queries
type: gauge
help: 'Number of unique queries by command type'
key_labels:
- command_type
values: [unique_queries]
query: |
SELECT
cmd_type_text as command_type,
COUNT(DISTINCT pgsm_query_id) as unique_queries
FROM pg_stat_monitor
WHERE cmd_type_text IS NOT NULL
GROUP BY cmd_type_text
- metric_name: pg_stat_monitor_summary_calls_total
type: counter
help: 'Total number of query executions by command type'
key_labels:
- command_type
values: [total_calls]
query: |
SELECT
cmd_type_text as command_type,
SUM(calls) as total_calls
FROM pg_stat_monitor
WHERE cmd_type_text IS NOT NULL
GROUP BY cmd_type_text
- metric_name: pg_stat_monitor_summary_time_milliseconds_total
type: counter
help: 'Total execution time in milliseconds by command type'
key_labels:
- command_type
values: [total_time_ms]
query: |
SELECT
cmd_type_text as command_type,
SUM(total_exec_time) as total_time_ms
FROM pg_stat_monitor
WHERE cmd_type_text IS NOT NULL
GROUP BY cmd_type_text
- metric_name: pg_stat_monitor_summary_avg_time_milliseconds
type: gauge
help: 'Average execution time in milliseconds by command type'
key_labels:
- command_type
values: [avg_time_ms]
query: |
SELECT
cmd_type_text as command_type,
AVG(mean_exec_time) as avg_time_ms
FROM pg_stat_monitor
WHERE cmd_type_text IS NOT NULL
GROUP BY cmd_type_text
- metric_name: pg_stat_monitor_summary_rows_total
type: counter
help: 'Total rows affected by command type'
key_labels:
- command_type
values: [total_rows]
query: |
SELECT
cmd_type_text as command_type,
SUM(rows) as total_rows
FROM pg_stat_monitor
WHERE cmd_type_text IS NOT NULL
GROUP BY cmd_type_text
- metric_name: pg_stat_monitor_summary_cache_hits_total
type: counter
help: 'Total cache hits by command type'
key_labels:
- command_type
values: [cache_hits]
query: |
SELECT
cmd_type_text as command_type,
SUM(shared_blks_hit) as cache_hits
FROM pg_stat_monitor
WHERE cmd_type_text IS NOT NULL
GROUP BY cmd_type_text
- metric_name: pg_stat_monitor_summary_disk_reads_total
type: counter
help: 'Total disk reads by command type'
key_labels:
- command_type
values: [disk_reads]
query: |
SELECT
cmd_type_text as command_type,
SUM(shared_blks_read) as disk_reads
FROM pg_stat_monitor
WHERE cmd_type_text IS NOT NULL
GROUP BY cmd_type_text
# Overall cache hit ratio
- metric_name: pg_stat_monitor_cache_hit_ratio_percent
type: gauge
help: 'Overall cache hit ratio percentage'
values: [cache_hit_ratio_percent]
query: |
SELECT
ROUND(
CASE
WHEN (SUM(shared_blks_hit) + SUM(shared_blks_read)) > 0
THEN (SUM(shared_blks_hit)::numeric / (SUM(shared_blks_hit) + SUM(shared_blks_read)) * 100)
ELSE 0
END, 2
) as cache_hit_ratio_percent
FROM pg_stat_monitor