Skip to content

Commit 8f07959

Browse files
chan-tim-sumosbylica-splunk
authored andcommitted
[receiver/postgresqlreceiver] Added new postgresql metrics to acheive parity with Telegraf (open-telemetry#36528)
1 parent e66becd commit 8f07959

27 files changed

+3110
-4
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: postgresqlreceiver
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Added new postgresql metrics to acheive parity with Telegraf
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [36528]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

receiver/postgresqlreceiver/client.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,34 @@ type databaseStats struct {
134134
transactionRollback int64
135135
deadlocks int64
136136
tempFiles int64
137+
tupUpdated int64
138+
tupReturned int64
139+
tupFetched int64
140+
tupInserted int64
141+
tupDeleted int64
142+
blksHit int64
143+
blksRead int64
137144
}
138145

139146
func (c *postgreSQLClient) getDatabaseStats(ctx context.Context, databases []string) (map[databaseName]databaseStats, error) {
140-
query := filterQueryByDatabases("SELECT datname, xact_commit, xact_rollback, deadlocks, temp_files FROM pg_stat_database", databases, false)
147+
query := filterQueryByDatabases(
148+
"SELECT datname, xact_commit, xact_rollback, deadlocks, temp_files, tup_updated, tup_returned, tup_fetched, tup_inserted, tup_deleted, blks_hit, blks_read FROM pg_stat_database",
149+
databases,
150+
false,
151+
)
152+
141153
rows, err := c.client.QueryContext(ctx, query)
142154
if err != nil {
143155
return nil, err
144156
}
157+
145158
var errs error
146159
dbStats := map[databaseName]databaseStats{}
160+
147161
for rows.Next() {
148162
var datname string
149-
var transactionCommitted, transactionRollback, deadlocks, tempFiles int64
150-
err = rows.Scan(&datname, &transactionCommitted, &transactionRollback, &deadlocks, &tempFiles)
163+
var transactionCommitted, transactionRollback, deadlocks, tempFiles, tupUpdated, tupReturned, tupFetched, tupInserted, tupDeleted, blksHit, blksRead int64
164+
err = rows.Scan(&datname, &transactionCommitted, &transactionRollback, &deadlocks, &tempFiles, &tupUpdated, &tupReturned, &tupFetched, &tupInserted, &tupDeleted, &blksHit, &blksRead)
151165
if err != nil {
152166
errs = multierr.Append(errs, err)
153167
continue
@@ -158,6 +172,13 @@ func (c *postgreSQLClient) getDatabaseStats(ctx context.Context, databases []str
158172
transactionRollback: transactionRollback,
159173
deadlocks: deadlocks,
160174
tempFiles: tempFiles,
175+
tupUpdated: tupUpdated,
176+
tupReturned: tupReturned,
177+
tupFetched: tupFetched,
178+
tupInserted: tupInserted,
179+
tupDeleted: tupDeleted,
180+
blksHit: blksHit,
181+
blksRead: blksRead,
161182
}
162183
}
163184
}

receiver/postgresqlreceiver/documentation.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,22 @@ metrics:
253253
enabled: true
254254
```
255255
256+
### postgresql.blks_hit
257+
258+
Number of times disk blocks were found already in the buffer cache.
259+
260+
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
261+
| ---- | ----------- | ---------- | ----------------------- | --------- |
262+
| {blks_hit} | Sum | Int | Cumulative | true |
263+
264+
### postgresql.blks_read
265+
266+
Number of disk blocks read in this database.
267+
268+
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
269+
| ---- | ----------- | ---------- | ----------------------- | --------- |
270+
| {blks_read} | Sum | Int | Cumulative | true |
271+
256272
### postgresql.database.locks
257273
258274
The number of database locks.
@@ -293,6 +309,46 @@ The number of temp files.
293309
| ---- | ----------- | ---------- | ----------------------- | --------- |
294310
| {temp_file} | Sum | Int | Cumulative | true |
295311
312+
### postgresql.tup_deleted
313+
314+
Number of rows deleted by queries in the database.
315+
316+
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
317+
| ---- | ----------- | ---------- | ----------------------- | --------- |
318+
| {tup_deleted} | Sum | Int | Cumulative | true |
319+
320+
### postgresql.tup_fetched
321+
322+
Number of rows fetched by queries in the database.
323+
324+
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
325+
| ---- | ----------- | ---------- | ----------------------- | --------- |
326+
| {tup_fetched} | Sum | Int | Cumulative | true |
327+
328+
### postgresql.tup_inserted
329+
330+
Number of rows inserted by queries in the database.
331+
332+
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
333+
| ---- | ----------- | ---------- | ----------------------- | --------- |
334+
| {tup_inserted} | Sum | Int | Cumulative | true |
335+
336+
### postgresql.tup_returned
337+
338+
Number of rows returned by queries in the database.
339+
340+
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
341+
| ---- | ----------- | ---------- | ----------------------- | --------- |
342+
| {tup_returned} | Sum | Int | Cumulative | true |
343+
344+
### postgresql.tup_updated
345+
346+
Number of rows updated by queries in the database.
347+
348+
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
349+
| ---- | ----------- | ---------- | ----------------------- | --------- |
350+
| {tup_updated} | Sum | Int | Cumulative | true |
351+
296352
### postgresql.wal.delay
297353
298354
Time between flushing recent WAL locally and receiving notification that the standby server has completed an operation with it.

receiver/postgresqlreceiver/integration_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ func integrationTest(name string, databases []string) func(*testing.T) {
7979
rCfg.Metrics.PostgresqlWalDelay.Enabled = true
8080
rCfg.Metrics.PostgresqlDeadlocks.Enabled = true
8181
rCfg.Metrics.PostgresqlTempFiles.Enabled = true
82+
rCfg.Metrics.PostgresqlTupUpdated.Enabled = true
83+
rCfg.Metrics.PostgresqlTupReturned.Enabled = true
84+
rCfg.Metrics.PostgresqlTupFetched.Enabled = true
85+
rCfg.Metrics.PostgresqlTupInserted.Enabled = true
86+
rCfg.Metrics.PostgresqlTupDeleted.Enabled = true
87+
rCfg.Metrics.PostgresqlBlksHit.Enabled = true
88+
rCfg.Metrics.PostgresqlBlksRead.Enabled = true
8289
rCfg.Metrics.PostgresqlSequentialScans.Enabled = true
8390
rCfg.Metrics.PostgresqlDatabaseLocks.Enabled = true
8491
}),

receiver/postgresqlreceiver/internal/metadata/generated_config.go

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/postgresqlreceiver/internal/metadata/generated_config_test.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)