mirror of
https://github.com/prometheus-community/postgres_exporter
synced 2025-01-08 07:20:00 +00:00
Remove unit from setting because of Aurora
Signed-off-by: Angus Dippenaar <angusdippenaar@gmail.com>
This commit is contained in:
parent
d0a3aa991a
commit
be30859417
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user