Skip to content
Snippets Groups Projects
Verified Commit 3aa4d594 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Cleanup metric handling

parent 397e9eea
Branches
Tags v1.0.39
No related merge requests found
Pipeline #2566 failed
...@@ -9,37 +9,21 @@ import ( ...@@ -9,37 +9,21 @@ import (
"net/http" "net/http"
) )
var queueGauge = promauto.NewGauge(prometheus.GaugeOpts{ var queueGauge = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: "imghost_waiting_images", Name: "imghost_waiting_images",
Help: "The number of waiting image events", Help: "The number of waiting image events",
ConstLabels: map[string]string{
"state": "queued",
}, },
}) []string{"state"},
)
var inProgressGauge = promauto.NewGauge(prometheus.GaugeOpts{
Name: "imghost_waiting_images",
Help: "The number of image events in progress",
ConstLabels: map[string]string{
"state": "in_progress",
},
})
var imageCounterSuccess = promauto.NewCounter(prometheus.CounterOpts{ var imageCounter = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "imghost_processed_images_total", Name: "imghost_processed_images_total",
Help: "The total number of successfully processed image events", Help: "The total number of successfully processed image events",
ConstLabels: map[string]string{
"success": "true",
}, },
}) []string{"result"},
)
var imageCounterFailure = promauto.NewCounter(prometheus.CounterOpts{
Name: "imghost_processed_images_total",
Help: "The total number of errored image events",
ConstLabels: map[string]string{
"success": "false",
},
})
var imageProcessDuration = promauto.NewCounter(prometheus.CounterOpts{ var imageProcessDuration = promauto.NewCounter(prometheus.CounterOpts{
Name: "imghost_process_duration", Name: "imghost_process_duration",
...@@ -63,8 +47,7 @@ func main() { ...@@ -63,8 +47,7 @@ func main() {
}) })
go serveQueue(client, config.ImageQueue, func(value string) { go serveQueue(client, config.ImageQueue, func(value string) {
queueGauge.Dec() queueGauge.WithLabelValues("queued").Dec()
inProgressGauge.Inc()
ProcessImage(&config, client, value) ProcessImage(&config, client, value)
}) })
if err := http.ListenAndServe(":2112", nil); err != nil { if err := http.ListenAndServe(":2112", nil); err != nil {
......
...@@ -14,8 +14,8 @@ func trackTime(start time.Time, function func(time.Duration)) { ...@@ -14,8 +14,8 @@ func trackTime(start time.Time, function func(time.Duration)) {
} }
func ProcessImage(config *Config, client *redis.Client, value string) { func ProcessImage(config *Config, client *redis.Client, value string) {
inProgressGauge.Inc() queueGauge.WithLabelValues("in_progress").Inc()
defer inProgressGauge.Dec() defer queueGauge.WithLabelValues("in_progress").Dec()
defer trackTime(time.Now(), func(duration time.Duration) { defer trackTime(time.Now(), func(duration time.Duration) {
imageProcessDuration.Add(float64(duration.Milliseconds())) imageProcessDuration.Add(float64(duration.Milliseconds()))
}) })
...@@ -35,14 +35,14 @@ func ProcessImage(config *Config, client *redis.Client, value string) { ...@@ -35,14 +35,14 @@ func ProcessImage(config *Config, client *redis.Client, value string) {
} }
if len(errors) != 0 { if len(errors) != 0 {
imageCounterFailure.Inc() imageCounter.WithLabelValues("error").Inc()
returnResult(config, client, Result{ returnResult(config, client, Result{
Id: image.Id, Id: image.Id,
Success: false, Success: false,
Errors: errorMessages, Errors: errorMessages,
}) })
} else { } else {
imageCounterSuccess.Inc() imageCounter.WithLabelValues("success").Inc()
returnResult(config, client, Result{ returnResult(config, client, Result{
Id: image.Id, Id: image.Id,
Success: true, Success: true,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment