1
0
mirror of https://github.com/prometheus-community/postgres_exporter.git synced 2025-04-19 23:22:18 +03:00

31 lines
916 B
Go

package collector
import (
"regexp"
"github.com/blang/semver"
"errors"
"fmt"
"github.com/prometheus/client_golang/prometheus"
)
// Regex used to get the "short-version" from the postgres version field.
var versionRegex = regexp.MustCompile(`^\w+ ((\d+)(\.\d+)?(\.\d+)?)`)
// Parses the version of postgres into the short version string we can use to
// match behaviors.
func parseVersion(versionString string) (semver.Version, error) {
submatches := versionRegex.FindStringSubmatch(versionString)
if len(submatches) > 1 {
return semver.ParseTolerant(submatches[1])
}
return semver.Version{},
errors.New(fmt.Sprintln("Could not find a postgres version in string:", versionString))
}
// newDesc handles making a new metric description
func newDesc(subsystem, name, help string) *prometheus.Desc {
return prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, name),
help, nil, nil,
)
}