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

Cleanup metric handling

parent 3aa4d594
No related branches found
No related tags found
No related merge requests found
Pipeline #2567 passed
...@@ -16,6 +16,8 @@ var queueGauge = promauto.NewGaugeVec( ...@@ -16,6 +16,8 @@ var queueGauge = promauto.NewGaugeVec(
}, },
[]string{"state"}, []string{"state"},
) )
var queueGaugeQueued = queueGauge.WithLabelValues("queued")
var queueGaugeInProgress = queueGauge.WithLabelValues("inProgress")
var imageCounter = promauto.NewCounterVec( var imageCounter = promauto.NewCounterVec(
prometheus.CounterOpts{ prometheus.CounterOpts{
...@@ -24,6 +26,8 @@ var imageCounter = promauto.NewCounterVec( ...@@ -24,6 +26,8 @@ var imageCounter = promauto.NewCounterVec(
}, },
[]string{"result"}, []string{"result"},
) )
var imageCounterSuccess = imageCounter.WithLabelValues("success")
var imageCounterFailure = imageCounter.WithLabelValues("failure")
var imageProcessDuration = promauto.NewCounter(prometheus.CounterOpts{ var imageProcessDuration = promauto.NewCounter(prometheus.CounterOpts{
Name: "imghost_process_duration", Name: "imghost_process_duration",
...@@ -47,7 +51,7 @@ func main() { ...@@ -47,7 +51,7 @@ func main() {
}) })
go serveQueue(client, config.ImageQueue, func(value string) { go serveQueue(client, config.ImageQueue, func(value string) {
queueGauge.WithLabelValues("queued").Dec() queueGaugeQueued.Dec()
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) {
queueGauge.WithLabelValues("in_progress").Inc() queueGaugeInProgress.Inc()
defer queueGauge.WithLabelValues("in_progress").Dec() defer queueGaugeInProgress.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 {
imageCounter.WithLabelValues("error").Inc() imageCounterFailure.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 {
imageCounter.WithLabelValues("success").Inc() imageCounterSuccess.Inc()
returnResult(config, client, Result{ returnResult(config, client, Result{
Id: image.Id, Id: image.Id,
Success: true, Success: true,
......
...@@ -11,7 +11,7 @@ func serveQueue(client *redis.Client, queue string, function func(value string)) ...@@ -11,7 +11,7 @@ func serveQueue(client *redis.Client, queue string, function func(value string))
element := client.BLPop(0, fmt.Sprintf("queue:%s", queue)) element := client.BLPop(0, fmt.Sprintf("queue:%s", queue))
if len(element.Val()) == 2 { if len(element.Val()) == 2 {
value := element.Val()[1] value := element.Val()[1]
queueGauge.Inc() queueGaugeQueued.Inc()
go function(value) go function(value)
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment