Skip to content

Commit

Permalink
[receiver/postgresqlreceiver] Added new postgresql metrics to acheive…
Browse files Browse the repository at this point in the history
… parity with Telegraf (#36528)
  • Loading branch information
chan-tim-sumo authored Nov 27, 2024
1 parent c674d70 commit adbb96a
Show file tree
Hide file tree
Showing 27 changed files with 3,110 additions and 4 deletions.
27 changes: 27 additions & 0 deletions .chloggen/chan-tim_postgresMetrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: postgresqlreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Added new postgresql metrics to acheive parity with Telegraf

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [36528]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
27 changes: 24 additions & 3 deletions receiver/postgresqlreceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,34 @@ type databaseStats struct {
transactionRollback int64
deadlocks int64
tempFiles int64
tupUpdated int64
tupReturned int64
tupFetched int64
tupInserted int64
tupDeleted int64
blksHit int64
blksRead int64
}

func (c *postgreSQLClient) getDatabaseStats(ctx context.Context, databases []string) (map[databaseName]databaseStats, error) {
query := filterQueryByDatabases("SELECT datname, xact_commit, xact_rollback, deadlocks, temp_files FROM pg_stat_database", databases, false)
query := filterQueryByDatabases(
"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",
databases,
false,
)

rows, err := c.client.QueryContext(ctx, query)
if err != nil {
return nil, err
}

var errs error
dbStats := map[databaseName]databaseStats{}

for rows.Next() {
var datname string
var transactionCommitted, transactionRollback, deadlocks, tempFiles int64
err = rows.Scan(&datname, &transactionCommitted, &transactionRollback, &deadlocks, &tempFiles)
var transactionCommitted, transactionRollback, deadlocks, tempFiles, tupUpdated, tupReturned, tupFetched, tupInserted, tupDeleted, blksHit, blksRead int64
err = rows.Scan(&datname, &transactionCommitted, &transactionRollback, &deadlocks, &tempFiles, &tupUpdated, &tupReturned, &tupFetched, &tupInserted, &tupDeleted, &blksHit, &blksRead)
if err != nil {
errs = multierr.Append(errs, err)
continue
Expand All @@ -158,6 +172,13 @@ func (c *postgreSQLClient) getDatabaseStats(ctx context.Context, databases []str
transactionRollback: transactionRollback,
deadlocks: deadlocks,
tempFiles: tempFiles,
tupUpdated: tupUpdated,
tupReturned: tupReturned,
tupFetched: tupFetched,
tupInserted: tupInserted,
tupDeleted: tupDeleted,
blksHit: blksHit,
blksRead: blksRead,
}
}
}
Expand Down
56 changes: 56 additions & 0 deletions receiver/postgresqlreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,22 @@ metrics:
enabled: true
```
### postgresql.blks_hit
Number of times disk blocks were found already in the buffer cache.
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| {blks_hit} | Sum | Int | Cumulative | true |
### postgresql.blks_read
Number of disk blocks read in this database.
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| {blks_read} | Sum | Int | Cumulative | true |
### postgresql.database.locks
The number of database locks.
Expand Down Expand Up @@ -293,6 +309,46 @@ The number of temp files.
| ---- | ----------- | ---------- | ----------------------- | --------- |
| {temp_file} | Sum | Int | Cumulative | true |
### postgresql.tup_deleted
Number of rows deleted by queries in the database.
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| {tup_deleted} | Sum | Int | Cumulative | true |
### postgresql.tup_fetched
Number of rows fetched by queries in the database.
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| {tup_fetched} | Sum | Int | Cumulative | true |
### postgresql.tup_inserted
Number of rows inserted by queries in the database.
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| {tup_inserted} | Sum | Int | Cumulative | true |
### postgresql.tup_returned
Number of rows returned by queries in the database.
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| {tup_returned} | Sum | Int | Cumulative | true |
### postgresql.tup_updated
Number of rows updated by queries in the database.
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| {tup_updated} | Sum | Int | Cumulative | true |
### postgresql.wal.delay
Time between flushing recent WAL locally and receiving notification that the standby server has completed an operation with it.
Expand Down
7 changes: 7 additions & 0 deletions receiver/postgresqlreceiver/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ func integrationTest(name string, databases []string) func(*testing.T) {
rCfg.Metrics.PostgresqlWalDelay.Enabled = true
rCfg.Metrics.PostgresqlDeadlocks.Enabled = true
rCfg.Metrics.PostgresqlTempFiles.Enabled = true
rCfg.Metrics.PostgresqlTupUpdated.Enabled = true
rCfg.Metrics.PostgresqlTupReturned.Enabled = true
rCfg.Metrics.PostgresqlTupFetched.Enabled = true
rCfg.Metrics.PostgresqlTupInserted.Enabled = true
rCfg.Metrics.PostgresqlTupDeleted.Enabled = true
rCfg.Metrics.PostgresqlBlksHit.Enabled = true
rCfg.Metrics.PostgresqlBlksRead.Enabled = true
rCfg.Metrics.PostgresqlSequentialScans.Enabled = true
rCfg.Metrics.PostgresqlDatabaseLocks.Enabled = true
}),
Expand Down
28 changes: 28 additions & 0 deletions receiver/postgresqlreceiver/internal/metadata/generated_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit adbb96a

Please sign in to comment.