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 25, 2024
1 parent 01215f8 commit 1f96387
Show file tree
Hide file tree
Showing 17 changed files with 493 additions and 54 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
19 changes: 16 additions & 3 deletions receiver/postgresqlreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@ Number of times the background writer stopped a cleaning scan because it had wri
| ---- | ----------- | ---------- | ----------------------- | --------- |
| 1 | Sum | Int | Cumulative | 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.blocks_read
The number of blocks read.
Expand Down Expand Up @@ -214,8 +230,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.
Expand Down Expand Up @@ -248,7 +262,6 @@ Number of rows returned by queries in the database.
| ---- | ----------- | ---------- | ----------------------- | --------- |
| {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.
Expand Down
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

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 1f96387

Please sign in to comment.