Skip to content

Commit be30859

Browse files
committed
Remove unit from setting because of Aurora
Signed-off-by: Angus Dippenaar <[email protected]>
1 parent d0a3aa9 commit be30859

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

cmd/postgres_exporter/pg_setting.go

+22
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ import (
2323
"github.com/prometheus/client_golang/prometheus"
2424
)
2525

26+
var (
27+
settingUnits = []string{
28+
"ms", "s", "min", "h", "d",
29+
"B", "kB", "MB", "GB", "TB",
30+
}
31+
)
32+
2633
// Query the pg_settings view containing runtime variables
2734
func querySettings(ch chan<- prometheus.Metric, server *Server) error {
2835
level.Debug(logger).Log("msg", "Querying pg_setting view", "server", server)
@@ -93,9 +100,24 @@ func (s *pgSetting) metric(labels prometheus.Labels) prometheus.Metric {
93100
return prometheus.MustNewConstMetric(desc, prometheus.GaugeValue, val)
94101
}
95102

103+
// Removes units from any of the setting values.
104+
// This is mostly because of a irregularity regarding AWS RDS Aurora
105+
// https://github.com/prometheus-community/postgres_exporter/issues/619
106+
func (s *pgSetting) sanitizeValue() {
107+
for _, unit := range settingUnits {
108+
if strings.HasSuffix(s.setting, unit) {
109+
endPos := len(s.setting) - len(unit) - 1
110+
s.setting = s.setting[:endPos]
111+
return
112+
}
113+
}
114+
}
115+
96116
// TODO: fix linter override
97117
// nolint: nakedret
98118
func (s *pgSetting) normaliseUnit() (val float64, unit string, err error) {
119+
s.sanitizeValue()
120+
99121
val, err = strconv.ParseFloat(s.setting, 64)
100122
if err != nil {
101123
return val, unit, fmt.Errorf("Error converting setting %q value %q to float: %s", s.name, s.setting, err)

0 commit comments

Comments
 (0)