Skip to content

Commit

Permalink
Added rest of tup_ metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
chan-tim-sumo committed Nov 25, 2024
1 parent 4e14290 commit 01215f8
Show file tree
Hide file tree
Showing 14 changed files with 609 additions and 8 deletions.
17 changes: 12 additions & 5 deletions receiver/postgresqlreceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,15 @@ type databaseStats struct {
deadlocks int64
tempFiles int64
tupUpdated int64
tupReturned int64
tupFetched int64
tupInserted int64
tupDeleted int64
}

func (c *postgreSQLClient) getDatabaseStats(ctx context.Context, databases []string) (map[databaseName]databaseStats, error) {
// Modified query to include tup_updated from pg_stat_database
query := filterQueryByDatabases(
"SELECT datname, xact_commit, xact_rollback, deadlocks, temp_files, tup_updated FROM pg_stat_database",
"SELECT datname, xact_commit, xact_rollback, deadlocks, temp_files, tup_updated, tup_returned, tup_fetched, tup_inserted, tup_deleted FROM pg_stat_database",
databases,
false,
)
Expand All @@ -155,8 +158,8 @@ func (c *postgreSQLClient) getDatabaseStats(ctx context.Context, databases []str

for rows.Next() {
var datname string
var transactionCommitted, transactionRollback, deadlocks, tempFiles, tupUpdated int64
err = rows.Scan(&datname, &transactionCommitted, &transactionRollback, &deadlocks, &tempFiles, &tupUpdated)
var transactionCommitted, transactionRollback, deadlocks, tempFiles, tupUpdated, tupReturned, tupFetched, tupInserted, tupDeleted int64
err = rows.Scan(&datname, &transactionCommitted, &transactionRollback, &deadlocks, &tempFiles, &tupUpdated, &tupReturned, &tupFetched, &tupInserted, &tupDeleted)
if err != nil {
errs = multierr.Append(errs, err)
continue
Expand All @@ -167,7 +170,11 @@ func (c *postgreSQLClient) getDatabaseStats(ctx context.Context, databases []str
transactionRollback: transactionRollback,
deadlocks: deadlocks,
tempFiles: tempFiles,
tupUpdated: tupUpdated, // Added field
tupUpdated: tupUpdated,
tupReturned: tupReturned,
tupFetched: tupFetched,
tupInserted: tupInserted,
tupDeleted: tupDeleted,
}
}
}
Expand Down
35 changes: 35 additions & 0 deletions receiver/postgresqlreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,41 @@ 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.
Expand Down
4 changes: 4 additions & 0 deletions receiver/postgresqlreceiver/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ func integrationTest(name string, databases []string) func(*testing.T) {
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.PostgresqlSequentialScans.Enabled = true
rCfg.Metrics.PostgresqlDatabaseLocks.Enabled = true
}),
Expand Down
22 changes: 22 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 01215f8

Please sign in to comment.