1
0
Fork 0
mirror of https://github.com/Luzifer/elb-instance-status.git synced 2024-11-08 05:50:06 +00:00

Breaking: Remove prometheus support

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2022-05-02 16:10:12 +02:00
parent cff2b35ca4
commit 92a3cbaae0
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D
2 changed files with 6 additions and 65 deletions

21
main.go
View file

@ -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)
}

View file

@ -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)
}