Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed lableName in stat_io and stat_slru collector #113

Merged
merged 1 commit into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions internal/collector/postgres_stat_io.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,103 +53,104 @@ type postgresStatIOCollector struct {

// NewPostgresStatIOCollector returns a new Collector exposing postgres pg_stat_io stats.
func NewPostgresStatIOCollector(constLabels labels, settings model.CollectorSettings) (Collector, error) {
var labels = []string{"backend_type", "object", "context"}
var labelNames = []string{"backend_type", "object", "context"}

return &postgresStatIOCollector{
labelNames: labelNames,
reads: newBuiltinTypedDesc(
descOpts{"postgres", "stat_io", "reads", "Number of read operations, each of the size specified in op_bytes.", 0},
prometheus.GaugeValue,
labels, constLabels,
labelNames, constLabels,
settings.Filters,
),
readTime: newBuiltinTypedDesc(
descOpts{"postgres", "stat_io", "read_time", "Time spent in read operations in milliseconds (if track_io_timing is enabled, otherwise zero)", 0},
prometheus.GaugeValue,
labels, constLabels,
labelNames, constLabels,
settings.Filters,
),
writes: newBuiltinTypedDesc(
descOpts{"postgres", "stat_io", "writes", "Number of write operations, each of the size specified in op_bytes.", 0},
prometheus.GaugeValue,
labels, constLabels,
labelNames, constLabels,
settings.Filters,
),
writeTime: newBuiltinTypedDesc(
descOpts{"postgres", "stat_io", "write_time", "Time spent in write operations in milliseconds (if track_io_timing is enabled, otherwise zero)", 0},
prometheus.GaugeValue,
labels, constLabels,
labelNames, constLabels,
settings.Filters,
),
writebacks: newBuiltinTypedDesc(
descOpts{"postgres", "stat_io", "writebacks", "Number of units of size op_bytes which the process requested the kernel write out to permanent storage.", 0},
prometheus.GaugeValue,
labels, constLabels,
labelNames, constLabels,
settings.Filters,
),
writebackTime: newBuiltinTypedDesc(
descOpts{"postgres", "stat_io", "writeback_time", "Time spent in writeback operations in milliseconds (if track_io_timing is enabled, otherwise zero). ", 0},
prometheus.GaugeValue,
labels, constLabels,
labelNames, constLabels,
settings.Filters,
),
extends: newBuiltinTypedDesc(
descOpts{"postgres", "stat_io", "extends", "Number of relation extend operations, each of the size specified in op_bytes.", 0},
prometheus.GaugeValue,
labels, constLabels,
labelNames, constLabels,
settings.Filters,
),
extendTime: newBuiltinTypedDesc(
descOpts{"postgres", "stat_io", "extend_time", "Time spent in extend operations in milliseconds (if track_io_timing is enabled, otherwise zero)", 0},
prometheus.GaugeValue,
labels, constLabels,
labelNames, constLabels,
settings.Filters,
),
hits: newBuiltinTypedDesc(
descOpts{"postgres", "stat_io", "hits", "The number of times a desired block was found in a shared buffer.", 0},
prometheus.GaugeValue,
labels, constLabels,
labelNames, constLabels,
settings.Filters,
),
evictions: newBuiltinTypedDesc(
descOpts{"postgres", "stat_io", "evictions", "Number of times a block has been written out from a shared or local buffer in order to make it available for another use.", 0},
prometheus.GaugeValue,
labels, constLabels,
labelNames, constLabels,
settings.Filters,
),
reuses: newBuiltinTypedDesc(
descOpts{"postgres", "stat_io", "reuses", "The number of times an existing buffer in a size-limited ring buffer outside of shared buffers was reused as part of an I/O operation in the bulkread, bulkwrite, or vacuum contexts.", 0},
prometheus.GaugeValue,
labels, constLabels,
labelNames, constLabels,
settings.Filters,
),
fsyncs: newBuiltinTypedDesc(
descOpts{"postgres", "stat_io", "fsyncs", "Number of fsync calls. These are only tracked in context normal.", 0},
prometheus.GaugeValue,
labels, constLabels,
labelNames, constLabels,
settings.Filters,
),
fsyncTime: newBuiltinTypedDesc(
descOpts{"postgres", "stat_io", "fsync_time", "Time spent in fsync operations in milliseconds (if track_io_timing is enabled, otherwise zero)", 0},
prometheus.GaugeValue,
labels, constLabels,
labelNames, constLabels,
settings.Filters,
),
readBytes: newBuiltinTypedDesc(
descOpts{"postgres", "stat_io", "read_bytes", "Number of read, in bytes.", 0},
prometheus.GaugeValue,
labels, constLabels,
labelNames, constLabels,
settings.Filters,
),
writeBytes: newBuiltinTypedDesc(
descOpts{"postgres", "stat_io", "write_bytes", "Number of write, in bytes.", 0},
prometheus.GaugeValue,
labels, constLabels,
labelNames, constLabels,
settings.Filters,
),
extendBytes: newBuiltinTypedDesc(
descOpts{"postgres", "stat_io", "extend_bytes", "Number of relation extend, in bytes.", 0},
prometheus.GaugeValue,
labels, constLabels,
labelNames, constLabels,
settings.Filters,
),
}, nil
Expand All @@ -174,7 +175,7 @@ func (c *postgresStatIOCollector) Update(config Config, ch chan<- prometheus.Met
if err != nil {
log.Warnf("get pg_stat_io failed: %s; skip", err)
} else {
stats := parsePostgresStatIO(res, []string{"backend_type", "object", "context"})
stats := parsePostgresStatIO(res, c.labelNames)

for _, stat := range stats {
ch <- c.reads.newConstMetric(stat.Reads, stat.BackendType, stat.IoObject, stat.IoContext)
Expand Down
19 changes: 10 additions & 9 deletions internal/collector/postgres_stat_slru.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,49 +30,50 @@ type postgresStatSlruCollector struct {

// NewPostgresStatSlruCollector returns a new Collector exposing postgres pg_stat_slru stats.
func NewPostgresStatSlruCollector(constLabels labels, settings model.CollectorSettings) (Collector, error) {
var labels = []string{"name"}
var labelNames = []string{"name"}

return &postgresStatSlruCollector{
labelNames: labelNames,
blksZeroed: newBuiltinTypedDesc(
descOpts{"postgres", "stat_slru", "blks_zeroed", "Number of blocks zeroed during initializations.", 0},
prometheus.GaugeValue,
labels, constLabels,
labelNames, constLabels,
settings.Filters,
),
blksHit: newBuiltinTypedDesc(
descOpts{"postgres", "stat_slru", "blks_hit", "Number of times disk blocks were found already in the SLRU, so that a read was not necessary (this only includes hits in the SLRU, not the operating system's file system cache).", 0},
prometheus.GaugeValue,
labels, constLabels,
labelNames, constLabels,
settings.Filters,
),
blksRead: newBuiltinTypedDesc(
descOpts{"postgres", "stat_slru", "blks_read", "Number of disk blocks read for this SLRU.", 0},
prometheus.GaugeValue,
labels, constLabels,
labelNames, constLabels,
settings.Filters,
),
blksWritten: newBuiltinTypedDesc(
descOpts{"postgres", "stat_slru", "blks_written", "Number of disk blocks written for this SLRU.", 0},
prometheus.GaugeValue,
labels, constLabels,
labelNames, constLabels,
settings.Filters,
),
blksExists: newBuiltinTypedDesc(
descOpts{"postgres", "stat_slru", "blks_exists", "Number of blocks checked for existence for this SLRU.", 0},
prometheus.GaugeValue,
labels, constLabels,
labelNames, constLabels,
settings.Filters,
),
flushes: newBuiltinTypedDesc(
descOpts{"postgres", "stat_slru", "flushes", "Number of flushes of dirty data for this SLRU.", 0},
prometheus.GaugeValue,
labels, constLabels,
labelNames, constLabels,
settings.Filters,
),
truncates: newBuiltinTypedDesc(
descOpts{"postgres", "stat_slru", "truncates", "Number of truncates for this SLRU.", 0},
prometheus.GaugeValue,
labels, constLabels,
labelNames, constLabels,
settings.Filters,
),
}, nil
Expand All @@ -97,7 +98,7 @@ func (c *postgresStatSlruCollector) Update(config Config, ch chan<- prometheus.M
if err != nil {
log.Warnf("get pg_stat_slru failed: %s; skip", err)
} else {
stats := parsePostgresStatSlru(res, []string{"name"})
stats := parsePostgresStatSlru(res, c.labelNames)

for _, stat := range stats {
ch <- c.blksZeroed.newConstMetric(stat.BlksZeroed, stat.SlruName)
Expand Down