Skip to content

Commit

Permalink
Merge pull request #620 from SN9NV/master
Browse files Browse the repository at this point in the history
Sanitize setting values because of Aurora irregularity
  • Loading branch information
sysadmind authored Mar 23, 2022
2 parents a59665c + be30859 commit 7e02b9b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cmd/postgres_exporter/pg_setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7e02b9b

Please sign in to comment.