From 92a3cbaae0d17d134634be6559422598455972c5 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Mon, 2 May 2022 16:10:12 +0200 Subject: [PATCH] Breaking: Remove prometheus support Signed-off-by: Knut Ahlers --- main.go | 21 ++++++--------------- metrics.go | 50 -------------------------------------------------- 2 files changed, 6 insertions(+), 65 deletions(-) delete mode 100644 metrics.go diff --git a/main.go b/main.go index e6bf8e5..736f209 100644 --- a/main.go +++ b/main.go @@ -14,12 +14,12 @@ import ( "sync" "time" - "github.com/Luzifer/rconfig" "github.com/gorilla/mux" - "github.com/prometheus/client_golang/prometheus" - "github.com/robfig/cron" + "github.com/robfig/cron/v3" "golang.org/x/net/context" "gopkg.in/yaml.v2" + + "github.com/Luzifer/rconfig/v2" ) var ( @@ -126,8 +126,9 @@ func main() { r := mux.NewRouter() r.HandleFunc("/status", handleELBHealthCheck) - r.Handle("/metrics", prometheus.Handler()) - http.ListenAndServe(cfg.Listen, r) + if err := http.ListenAndServe(cfg.Listen, r); err != nil { + log.Fatalf("Unable to listen: %s", err) + } } func spawnChecks() { @@ -140,7 +141,6 @@ func spawnChecks() { func executeAndRegisterCheck(ctx context.Context, checkID string) { check := checks[checkID] - start := time.Now() cmd := exec.Command("/bin/bash", "-e", "-o", "pipefail", "-c", check.Command) cmd.Stderr = newPrefixedLogger(os.Stderr, checkID+":STDERR") @@ -188,13 +188,6 @@ func executeAndRegisterCheck(ctx context.Context, checkID string) { lastResultRegistered = time.Now() - if success { - checkPassing.WithLabelValues(checkID).Set(1) - } else { - checkPassing.WithLabelValues(checkID).Set(0) - } - checkExecutionTime.WithLabelValues(checkID).Observe(float64(time.Since(start).Nanoseconds()) / float64(time.Microsecond)) - checkResultsLock.Unlock() } @@ -224,10 +217,8 @@ func handleELBHealthCheck(res http.ResponseWriter, r *http.Request) { res.Header().Set("X-Collection-Parsed-In", strconv.FormatInt(time.Since(start).Nanoseconds()/int64(time.Microsecond), 10)+"ms") res.Header().Set("X-Last-Result-Registered-At", lastResultRegistered.Format(time.RFC1123)) if healthy { - currentStatusCode.Set(http.StatusOK) res.WriteHeader(http.StatusOK) } else { - currentStatusCode.Set(http.StatusInternalServerError) res.WriteHeader(http.StatusInternalServerError) } diff --git a/metrics.go b/metrics.go deleted file mode 100644 index 7059664..0000000 --- a/metrics.go +++ /dev/null @@ -1,50 +0,0 @@ -package main - -import ( - "log" - "os" - - "github.com/prometheus/client_golang/prometheus" -) - -var ( - checkPassing *prometheus.GaugeVec - checkExecutionTime *prometheus.SummaryVec - currentStatusCode prometheus.Gauge - - dynamicLabels = []string{"check_id"} -) - -func init() { - hostname, err := os.Hostname() - if err != nil { - log.Fatalf("Unable to determine own hostname: %s", err) - } - - co := prometheus.GaugeOpts{ - Subsystem: "elb_instance_status", - ConstLabels: prometheus.Labels{"hostname": hostname}, - } - - co.Name = "check_passing" - co.Help = "Bit showing whether the check PASSed (=1) or FAILed (=0), WARNs are also reported as FAILs" - - cp := prometheus.NewGaugeVec(co, dynamicLabels) - - co.Name = "status_code" - co.Help = "Contains the current HTTP status code the ELB is seeing" - - csc := prometheus.NewGauge(co) - - cet := prometheus.NewSummaryVec(prometheus.SummaryOpts{ - Namespace: co.Namespace, - Subsystem: co.Subsystem, - ConstLabels: co.ConstLabels, - Name: "check_execution_time", - Help: "Timespan in µs the execution of the check took", - }, dynamicLabels) - - checkPassing = prometheus.MustRegisterOrGet(cp).(*prometheus.GaugeVec) - currentStatusCode = prometheus.MustRegisterOrGet(csc).(prometheus.Gauge) - checkExecutionTime = prometheus.MustRegisterOrGet(cet).(*prometheus.SummaryVec) -}