1
0
Fork 0
mirror of https://github.com/Luzifer/elb-instance-status.git synced 2024-12-23 03:11:20 +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" "sync"
"time" "time"
"github.com/Luzifer/rconfig"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/prometheus/client_golang/prometheus" "github.com/robfig/cron/v3"
"github.com/robfig/cron"
"golang.org/x/net/context" "golang.org/x/net/context"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
"github.com/Luzifer/rconfig/v2"
) )
var ( var (
@ -126,8 +126,9 @@ func main() {
r := mux.NewRouter() r := mux.NewRouter()
r.HandleFunc("/status", handleELBHealthCheck) r.HandleFunc("/status", handleELBHealthCheck)
r.Handle("/metrics", prometheus.Handler()) if err := http.ListenAndServe(cfg.Listen, r); err != nil {
http.ListenAndServe(cfg.Listen, r) log.Fatalf("Unable to listen: %s", err)
}
} }
func spawnChecks() { func spawnChecks() {
@ -140,7 +141,6 @@ func spawnChecks() {
func executeAndRegisterCheck(ctx context.Context, checkID string) { func executeAndRegisterCheck(ctx context.Context, checkID string) {
check := checks[checkID] check := checks[checkID]
start := time.Now()
cmd := exec.Command("/bin/bash", "-e", "-o", "pipefail", "-c", check.Command) cmd := exec.Command("/bin/bash", "-e", "-o", "pipefail", "-c", check.Command)
cmd.Stderr = newPrefixedLogger(os.Stderr, checkID+":STDERR") cmd.Stderr = newPrefixedLogger(os.Stderr, checkID+":STDERR")
@ -188,13 +188,6 @@ func executeAndRegisterCheck(ctx context.Context, checkID string) {
lastResultRegistered = time.Now() 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() 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-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)) res.Header().Set("X-Last-Result-Registered-At", lastResultRegistered.Format(time.RFC1123))
if healthy { if healthy {
currentStatusCode.Set(http.StatusOK)
res.WriteHeader(http.StatusOK) res.WriteHeader(http.StatusOK)
} else { } else {
currentStatusCode.Set(http.StatusInternalServerError)
res.WriteHeader(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)
}