Skip to content

Commit 7c1f8f2

Browse files
Add postgresql.temp.io metric (#41365)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Add `postgresql.temp.io` metric. --------- Co-authored-by: Nico Stewart <[email protected]>
1 parent 54c3545 commit 7c1f8f2

29 files changed

+529
-10
lines changed

.chloggen/pg-temp-bytes.yaml

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: Add 'postgresql.temp.io' metric
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: [41365]
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: The metric emits the amount of data written to temporary files.
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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ type databaseStats struct {
190190
transactionCommitted int64
191191
transactionRollback int64
192192
deadlocks int64
193+
tempIo int64
193194
tempFiles int64
194195
tupUpdated int64
195196
tupReturned int64
@@ -202,7 +203,7 @@ type databaseStats struct {
202203

203204
func (c *postgreSQLClient) getDatabaseStats(ctx context.Context, databases []string) (map[databaseName]databaseStats, error) {
204205
query := filterQueryByDatabases(
205-
"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",
206+
"SELECT datname, xact_commit, xact_rollback, deadlocks, temp_files, temp_bytes, tup_updated, tup_returned, tup_fetched, tup_inserted, tup_deleted, blks_hit, blks_read FROM pg_stat_database",
206207
databases,
207208
false,
208209
)
@@ -217,8 +218,8 @@ func (c *postgreSQLClient) getDatabaseStats(ctx context.Context, databases []str
217218

218219
for rows.Next() {
219220
var datname string
220-
var transactionCommitted, transactionRollback, deadlocks, tempFiles, tupUpdated, tupReturned, tupFetched, tupInserted, tupDeleted, blksHit, blksRead int64
221-
err = rows.Scan(&datname, &transactionCommitted, &transactionRollback, &deadlocks, &tempFiles, &tupUpdated, &tupReturned, &tupFetched, &tupInserted, &tupDeleted, &blksHit, &blksRead)
221+
var transactionCommitted, transactionRollback, deadlocks, tempIo, tempFiles, tupUpdated, tupReturned, tupFetched, tupInserted, tupDeleted, blksHit, blksRead int64
222+
err = rows.Scan(&datname, &transactionCommitted, &transactionRollback, &deadlocks, &tempFiles, &tempIo, &tupUpdated, &tupReturned, &tupFetched, &tupInserted, &tupDeleted, &blksHit, &blksRead)
222223
if err != nil {
223224
errs = multierr.Append(errs, err)
224225
continue
@@ -228,6 +229,7 @@ func (c *postgreSQLClient) getDatabaseStats(ctx context.Context, databases []str
228229
transactionCommitted: transactionCommitted,
229230
transactionRollback: transactionRollback,
230231
deadlocks: deadlocks,
232+
tempIo: tempIo,
231233
tempFiles: tempFiles,
232234
tupUpdated: tupUpdated,
233235
tupReturned: tupReturned,

receiver/postgresqlreceiver/documentation.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,14 @@ The number of sequential scans.
315315
| ---- | ----------- | ---------- | ----------------------- | --------- |
316316
| {sequential_scan} | Sum | Int | Cumulative | true |
317317

318+
### postgresql.temp.io
319+
320+
Total amount of data written to temporary files by queries.
321+
322+
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
323+
| ---- | ----------- | ---------- | ----------------------- | --------- |
324+
| By | Sum | Int | Cumulative | true |
325+
318326
### postgresql.temp_files
319327

320328
The number of temp files.

receiver/postgresqlreceiver/integration_test.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ func integrationTest(name string, databases []string, pgVersion string) func(*te
9696
rCfg.Insecure = true
9797
rCfg.Metrics.PostgresqlWalDelay.Enabled = true
9898
rCfg.Metrics.PostgresqlDeadlocks.Enabled = true
99+
rCfg.Metrics.PostgresqlTempIo.Enabled = true
99100
rCfg.Metrics.PostgresqlTempFiles.Enabled = true
100101
rCfg.Metrics.PostgresqlTupUpdated.Enabled = true
101102
rCfg.Metrics.PostgresqlTupReturned.Enabled = true
@@ -110,7 +111,41 @@ func integrationTest(name string, databases []string, pgVersion string) func(*te
110111
scraperinttest.WithExpectedFile(expectedFile),
111112
scraperinttest.WithCompareOptions(
112113
pmetrictest.IgnoreResourceMetricsOrder(),
113-
pmetrictest.IgnoreMetricValues(),
114+
pmetrictest.IgnoreMetricValues(
115+
"postgresql.backends",
116+
"postgresql.bgwriter.buffers.allocated",
117+
"postgresql.bgwriter.buffers.writes",
118+
"postgresql.bgwriter.checkpoint.count",
119+
"postgresql.bgwriter.duration",
120+
"postgresql.bgwriter.maxwritten",
121+
"postgresql.blks_hit",
122+
"postgresql.blks_read",
123+
"postgresql.blocks_read",
124+
"postgresql.commits",
125+
"postgresql.connection.max",
126+
"postgresql.database.count",
127+
"postgresql.database.locks",
128+
"postgresql.db_size",
129+
"postgresql.deadlocks",
130+
"postgresql.index.scans",
131+
"postgresql.index.size",
132+
"postgresql.operations",
133+
"postgresql.replication.data_delay",
134+
"postgresql.rollbacks",
135+
"postgresql.rows",
136+
"postgresql.sequential_scans",
137+
"postgresql.table.count",
138+
"postgresql.table.size",
139+
"postgresql.table.vacuum.count",
140+
"postgresql.tup_deleted",
141+
"postgresql.tup_fetched",
142+
"postgresql.tup_inserted",
143+
"postgresql.tup_returned",
144+
"postgresql.tup_updated",
145+
"postgresql.wal.age",
146+
"postgresql.wal.delay",
147+
"postgresql.wal.lag",
148+
),
114149
pmetrictest.IgnoreSubsequentDataPoints("postgresql.backends"),
115150
pmetrictest.IgnoreMetricDataPointsOrder(),
116151
pmetrictest.IgnoreStartTimestamp(),

receiver/postgresqlreceiver/internal/metadata/generated_config.go

Lines changed: 4 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: 2 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_metrics.go

Lines changed: 63 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_metrics_test.go

Lines changed: 17 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/testdata/config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ all_set:
5353
enabled: true
5454
postgresql.table.vacuum.count:
5555
enabled: true
56+
postgresql.temp.io:
57+
enabled: true
5658
postgresql.temp_files:
5759
enabled: true
5860
postgresql.tup_deleted:
@@ -139,6 +141,8 @@ none_set:
139141
enabled: false
140142
postgresql.table.vacuum.count:
141143
enabled: false
144+
postgresql.temp.io:
145+
enabled: false
142146
postgresql.temp_files:
143147
enabled: false
144148
postgresql.tup_deleted:

receiver/postgresqlreceiver/metadata.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,14 @@ metrics:
411411
value_type: int
412412
monotonic: true
413413
aggregation_temporality: cumulative
414+
postgresql.temp.io:
415+
enabled: false
416+
description: Total amount of data written to temporary files by queries.
417+
unit: By
418+
sum:
419+
value_type: int
420+
monotonic: true
421+
aggregation_temporality: cumulative
414422
postgresql.wal.age:
415423
description: Age of the oldest WAL file.
416424
extended_documentation: |

0 commit comments

Comments
 (0)