refactor pg_stat_bgwriter metrics into standalone collector
This moves the metrics that are queried from pg_stat_bgwriter into a dedicated collector instead of dynamically generating queries and metrics from a map. It renames some metrics including adding the `_total` suffix on all of the counters to match prometheus standards. This implementation uses QueryRowContext to allow for later addition of context for cancellation. From the Postgres documentation, it states that there is one line per WAL sender process, but it is unclear how to differentiate between them in any meaningful way. When querying the table, there is no column to identify the row, only metrics about bgwriter. Signed-off-by: Joe Adams <github@joeadams.io>
This commit is contained in:
@@ -115,7 +115,12 @@ func main() {
|
||||
|
||||
prometheus.MustRegister(exporter)
|
||||
|
||||
pe, err := collector.NewPostgresCollector(logger, dsn)
|
||||
pe, err := collector.NewPostgresCollector(
|
||||
logger,
|
||||
dsn,
|
||||
[]string{},
|
||||
collector.WithAutoDiscoverDatabases(*autoDiscoverDatabases),
|
||||
)
|
||||
if err != nil {
|
||||
level.Error(logger).Log("msg", "Failed to create PostgresCollector", "err", err.Error())
|
||||
os.Exit(1)
|
||||
|
||||
@@ -163,23 +163,6 @@ func dumpMaps() {
|
||||
}
|
||||
|
||||
var builtinMetricMaps = map[string]intermediateMetricMap{
|
||||
"pg_stat_bgwriter": {
|
||||
map[string]ColumnMapping{
|
||||
"checkpoints_timed": {COUNTER, "Number of scheduled checkpoints that have been performed", nil, nil},
|
||||
"checkpoints_req": {COUNTER, "Number of requested checkpoints that have been performed", nil, nil},
|
||||
"checkpoint_write_time": {COUNTER, "Total amount of time that has been spent in the portion of checkpoint processing where files are written to disk, in milliseconds", nil, nil},
|
||||
"checkpoint_sync_time": {COUNTER, "Total amount of time that has been spent in the portion of checkpoint processing where files are synchronized to disk, in milliseconds", nil, nil},
|
||||
"buffers_checkpoint": {COUNTER, "Number of buffers written during checkpoints", nil, nil},
|
||||
"buffers_clean": {COUNTER, "Number of buffers written by the background writer", nil, nil},
|
||||
"maxwritten_clean": {COUNTER, "Number of times the background writer stopped a cleaning scan because it had written too many buffers", nil, nil},
|
||||
"buffers_backend": {COUNTER, "Number of buffers written directly by a backend", nil, nil},
|
||||
"buffers_backend_fsync": {COUNTER, "Number of times a backend had to execute its own fsync call (normally the background writer handles those even when the backend does its own write)", nil, nil},
|
||||
"buffers_alloc": {COUNTER, "Number of buffers allocated", nil, nil},
|
||||
"stats_reset": {COUNTER, "Time at which these statistics were last reset", nil, nil},
|
||||
},
|
||||
true,
|
||||
0,
|
||||
},
|
||||
"pg_stat_database": {
|
||||
map[string]ColumnMapping{
|
||||
"datid": {LABEL, "OID of a database", nil, nil},
|
||||
|
||||
Reference in New Issue
Block a user