Debian Codegraph @

exporter/rdb.go

raw symbols SCIP
1 package exporter
2
3 import (
4 "os"
5 "path/filepath"
6
7 "github.com/prometheus/client_golang/prometheus"
8 log "github.com/sirupsen/logrus"
9 )
10
11 func (e *Exporter) extractRdbFileSizeMetric(ch chan<- prometheus.Metric, configMap map[string]string) {
12 if len(configMap) == 0 {
13 log.Debugf("Config is empty, cannot extract RDB file size")
14 return
15 }
16
17 dir := configMap["dir"]
18 dbfilename := configMap["dbfilename"]
19 if dir == "" || dbfilename == "" {
20 log.Debugf("Failed to find 'dir' or 'dbfilename' in config")
21 return
22 }
23
24 if dbfilename != filepath.Base(dbfilename) || dbfilename == "." || dbfilename == ".." {
25 log.Warnf("dbfilename %q is not a bare filename, skipping RDB size metric", dbfilename)
26 return
27 }
28
29 rdbPath := filepath.Join(dir, dbfilename)
30 log.Debugf("RDB file path: %s", rdbPath)
31
32 fileInfo, err := os.Stat(rdbPath)
33 if err != nil {
34 if os.IsNotExist(err) {
35 log.Debugf("RDB file does not exist: %s", rdbPath)
36
37 // File doesn't exist, report 0
38 e.registerConstMetricGauge(ch, "rdb_current_size_bytes", 0)
39 return
40 }
41 if os.IsPermission(err) {
42 log.Warnf("Permission denied accessing RDB file: %s", rdbPath)
43 return
44 }
45 log.Warnf("Failed to stat RDB file %s: %s", rdbPath, err)
46 return
47 }
48
49 // Verify it's a regular file
50 if !fileInfo.Mode().IsRegular() {
51 log.Warnf("RDB path is not a regular file: %s (mode: %s)", rdbPath, fileInfo.Mode())
52 return
53 }
54
55 e.registerConstMetricGauge(ch, "rdb_current_size_bytes", float64(fileInfo.Size()))
56
57 log.Debugf("RDB file size: %d bytes", fileInfo.Size())
58 }