Skip to content

Commit

Permalink
Added blocks hit and blocks read metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
chan-tim-sumo committed Nov 27, 2024
1 parent 01215f8 commit 28d739e
Show file tree
Hide file tree
Showing 22 changed files with 1,373 additions and 113 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: []
10 changes: 7 additions & 3 deletions receiver/postgresqlreceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,13 @@ type databaseStats struct {
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, tup_updated, tup_returned, tup_fetched, tup_inserted, tup_deleted FROM pg_stat_database",
"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,
)
Expand All @@ -158,8 +160,8 @@ func (c *postgreSQLClient) getDatabaseStats(ctx context.Context, databases []str

for rows.Next() {
var datname string
var transactionCommitted, transactionRollback, deadlocks, tempFiles, tupUpdated, tupReturned, tupFetched, tupInserted, tupDeleted int64
err = rows.Scan(&datname, &transactionCommitted, &transactionRollback, &deadlocks, &tempFiles, &tupUpdated, &tupReturned, &tupFetched, &tupInserted, &tupDeleted)
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 @@ -175,6 +177,8 @@ func (c *postgreSQLClient) getDatabaseStats(ctx context.Context, databases []str
tupFetched: tupFetched,
tupInserted: tupInserted,
tupDeleted: tupDeleted,
blksHit: blksHit,
blksRead: blksRead,
}
}
}
Expand Down
99 changes: 56 additions & 43 deletions receiver/postgresqlreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,49 +214,6 @@ Number of times a table has manually been vacuumed.
| ---- | ----------- | ---------- | ----------------------- | --------- |
| {vacuums} | Sum | Int | Cumulative | true |
<<<<<<< HEAD
=======
### 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 |
>>>>>>> a560b922dd (Added new postgresql metrics to acheive parity with Telegraf)
### 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.age
Age of the oldest WAL file.
Expand Down Expand Up @@ -296,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 @@ -336,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
3 changes: 2 additions & 1 deletion receiver/postgresqlreceiver/generated_package_test.go

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

2 changes: 2 additions & 0 deletions receiver/postgresqlreceiver/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ func integrationTest(name string, databases []string) func(*testing.T) {
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
24 changes: 13 additions & 11 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 28d739e

Please sign in to comment.