Skip to content

Commit

Permalink
Add reload metrics from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksontj committed Feb 9, 2021
1 parent caea922 commit 0950012
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions cmd/promxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/jessevdk/go-flags"
"github.com/julienschmidt/httprouter"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/log"
"github.com/prometheus/common/model"
Expand All @@ -54,7 +55,16 @@ import (
)

var (
reloadTime = prometheus.NewGauge(prometheus.GaugeOpts{
configSuccess = promauto.NewGauge(prometheus.GaugeOpts{
Name: "prometheus_config_last_reload_successful",
Help: "Whether the last configuration reload attempt was successful.",
})
configSuccessTime = promauto.NewGauge(prometheus.GaugeOpts{
Name: "prometheus_config_last_reload_success_timestamp_seconds",
Help: "Timestamp of the last successful configuration reload.",
})

reloadTime = promauto.NewGauge(prometheus.GaugeOpts{
Name: "process_reload_time_seconds",
Help: "Last reload (SIGHUP) time of the process since unix epoch in seconds.",
})
Expand Down Expand Up @@ -106,7 +116,16 @@ func (c *cliOpts) ToFlags() map[string]string {

var opts cliOpts

func reloadConfig(noStepSuqueryInterval *safePromQLNoStepSubqueryInterval, rls ...proxyconfig.Reloadable) error {
func reloadConfig(noStepSuqueryInterval *safePromQLNoStepSubqueryInterval, rls ...proxyconfig.Reloadable) (err error) {
defer func() {
if err == nil {
configSuccess.Set(1)
configSuccessTime.SetToCurrentTime()
} else {
configSuccess.Set(0)
}
}()

cfg, err := proxyconfig.ConfigFromFile(opts.ConfigFile)
if err != nil {
return fmt.Errorf("error loading cfg: %v", err)
Expand Down Expand Up @@ -136,8 +155,6 @@ func main() {
defer close(sigs)
signal.Notify(sigs, syscall.SIGHUP, syscall.SIGTERM, syscall.SIGINT)

prometheus.MustRegister(reloadTime)

reloadables := make([]proxyconfig.Reloadable, 0)

parser := flags.NewParser(&opts, flags.Default)
Expand Down Expand Up @@ -389,6 +406,9 @@ func main() {
logrus.Fatalf("Error loading config: %s", err)
}

configSuccess.Set(1)
configSuccessTime.SetToCurrentTime()

close(reloadReady)

// Set up access logger
Expand Down

0 comments on commit 0950012

Please sign in to comment.