Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ is deployed in container environments.
| include-go-runtime-metrics | REDIS_EXPORTER_INCLUDE_GO_RUNTIME_METRICS | Whether to include Go runtime metrics, defaults to false. |
| include-config-metrics | REDIS_EXPORTER_INCL_CONFIG_METRICS | Whether to include all config settings as metrics, defaults to false. |
| include-system-metrics | REDIS_EXPORTER_INCL_SYSTEM_METRICS | Whether to include system metrics like `total_system_memory_bytes`, defaults to false. |
| include-rdb-file-size-metric | REDIS_EXPORTER_INCL_RDB_FILE_SIZE_METRIC | Whether to include RDB file size metric (requires filesystem access to RDB file), defaults to false. |
| include-modules-metrics | REDIS_EXPORTER_INCL_MODULES_METRICS | Whether to collect Redis Modules metrics, defaults to false. |
| include-search-indexes-metrics | REDIS_EXPORTER_INCL_SEARCH_INDEXES_METRICS | Whether to collect Redis Search indexes metrics, defaults to false. |
| check-search-indexes | REDIS_EXPORTER_CHECK_SEARCH_INDEXES | Regex pattern for Redis Search indexes to export metrics from FT.INFO command, defaults to ".*". |
Expand Down
6 changes: 6 additions & 0 deletions exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type Options struct {
ExcludeLatencyHistogramMetrics bool
RedactConfigMetrics bool
InclSystemMetrics bool
InclRdbFileSizeMetric bool
SkipTLSVerification bool
SetClientName bool
IsTile38 bool
Expand Down Expand Up @@ -593,6 +594,7 @@ func NewRedisExporter(uri string, opts Options) (*Exporter, error) {
"stream_radix_tree_keys": {txt: `Radix tree keys count"`, lbls: []string{"db", "stream"}},
"stream_radix_tree_nodes": {txt: `Radix tree nodes count`, lbls: []string{"db", "stream"}},
"up": {txt: "Information about the Redis instance"},
"rdb_current_size_bytes": {txt: "Current RDB file size in bytes"},
} {
e.metricDescriptions[k] = newMetricDescr(opts.Namespace, k, desc.txt, desc.lbls)
}
Expand Down Expand Up @@ -912,5 +914,9 @@ func (e *Exporter) scrapeRedisHost(ch chan<- prometheus.Metric) error {
}
}

if e.options.InclRdbFileSizeMetric {
e.extractRdbFileSizeMetric(ch, c)
}

return nil
}
52 changes: 52 additions & 0 deletions exporter/rdb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package exporter

import (
"os"
"path/filepath"

"github.com/gomodule/redigo/redis"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
)

func (e *Exporter) extractRdbFileSizeMetric(ch chan<- prometheus.Metric, c redis.Conn) {
// Get RDB dir and filename in a single CONFIG GET call.
// CONFIG GET returns a flat array: [key1, value1, key2, value2, ...]
result, err := redis.Values(doRedisCmd(c, e.options.ConfigCommandName, "GET", "dir", "dbfilename"))
if err != nil || len(result) < 4 {
log.Debugf("Failed to get RDB config from CONFIG GET dir dbfilename: %s", err)
return
}

dir, err := redis.String(result[1], nil)
if err != nil {
log.Debugf("Failed to parse RDB directory: %s", err)
return
}
dbfilename, err := redis.String(result[3], nil)
if err != nil {
log.Debugf("Failed to parse RDB filename: %s", err)
return
}

// Construct full path
rdbPath := filepath.Join(dir, dbfilename)
log.Debugf("RDB file path: %s", rdbPath)

// Get file size
fileInfo, err := os.Stat(rdbPath)
if err != nil {
if os.IsNotExist(err) {
log.Debugf("RDB file does not exist: %s", rdbPath)
// File doesn't exist, report 0
e.registerConstMetricGauge(ch, "rdb_current_size_bytes", 0)
return
}
log.Debugf("Failed to stat RDB file %s: %s", rdbPath, err)
return
}

fileSize := float64(fileInfo.Size())
log.Debugf("RDB file size: %d bytes", fileInfo.Size())
e.registerConstMetricGauge(ch, "rdb_current_size_bytes", fileSize)
}
Loading
Loading