Remove unit from setting because of Aurora

Signed-off-by: Angus Dippenaar <angusdippenaar@gmail.com>
This commit is contained in:
Angus Dippenaar 2022-03-03 15:31:53 +01:00
parent d0a3aa991a
commit be30859417

View File

@ -23,6 +23,13 @@ import (
"github.com/prometheus/client_golang/prometheus"
)
var (
settingUnits = []string{
"ms", "s", "min", "h", "d",
"B", "kB", "MB", "GB", "TB",
}
)
// Query the pg_settings view containing runtime variables
func querySettings(ch chan<- prometheus.Metric, server *Server) error {
level.Debug(logger).Log("msg", "Querying pg_setting view", "server", server)
@ -93,9 +100,24 @@ func (s *pgSetting) metric(labels prometheus.Labels) prometheus.Metric {
return prometheus.MustNewConstMetric(desc, prometheus.GaugeValue, val)
}
// Removes units from any of the setting values.
// This is mostly because of a irregularity regarding AWS RDS Aurora
// https://github.com/prometheus-community/postgres_exporter/issues/619
func (s *pgSetting) sanitizeValue() {
for _, unit := range settingUnits {
if strings.HasSuffix(s.setting, unit) {
endPos := len(s.setting) - len(unit) - 1
s.setting = s.setting[:endPos]
return
}
}
}
// TODO: fix linter override
// nolint: nakedret
func (s *pgSetting) normaliseUnit() (val float64, unit string, err error) {
s.sanitizeValue()
val, err = strconv.ParseFloat(s.setting, 64)
if err != nil {
return val, unit, fmt.Errorf("Error converting setting %q value %q to float: %s", s.name, s.setting, err)