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 17bb5cf
Show file tree
Hide file tree
Showing 16 changed files with 466 additions and 54 deletions.
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 17bb5cf

Please sign in to comment.