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
Branches
No related tags found
No related merge requests found
Pipeline #2567 passed
......@@ -16,6 +16,8 @@ var queueGauge = promauto.NewGaugeVec(
},
[]string{"state"},
)
var queueGaugeQueued = queueGauge.WithLabelValues("queued")
var queueGaugeInProgress = queueGauge.WithLabelValues("inProgress")
var imageCounter = promauto.NewCounterVec(
prometheus.CounterOpts{
......@@ -24,6 +26,8 @@ var imageCounter = promauto.NewCounterVec(
},
[]string{"result"},
)
var imageCounterSuccess = imageCounter.WithLabelValues("success")
var imageCounterFailure = imageCounter.WithLabelValues("failure")
var imageProcessDuration = promauto.NewCounter(prometheus.CounterOpts{
Name: "imghost_process_duration",
......@@ -47,7 +51,7 @@ func main() {
})
go serveQueue(client, config.ImageQueue, func(value string) {
queueGauge.WithLabelValues("queued").Dec()
queueGaugeQueued.Dec()
ProcessImage(&config, client, value)
})
if err := http.ListenAndServe(":2112", nil); err != nil {
......
......@@ -14,8 +14,8 @@ func trackTime(start time.Time, function func(time.Duration)) {
}
func ProcessImage(config *Config, client *redis.Client, value string) {
queueGauge.WithLabelValues("in_progress").Inc()
defer queueGauge.WithLabelValues("in_progress").Dec()
queueGaugeInProgress.Inc()
defer queueGaugeInProgress.Dec()
defer trackTime(time.Now(), func(duration time.Duration) {
imageProcessDuration.Add(float64(duration.Milliseconds()))
})
......@@ -35,14 +35,14 @@ func ProcessImage(config *Config, client *redis.Client, value string) {
}
if len(errors) != 0 {
imageCounter.WithLabelValues("error").Inc()
imageCounterFailure.Inc()
returnResult(config, client, Result{
Id: image.Id,
Success: false,
Errors: errorMessages,
})
} else {
imageCounter.WithLabelValues("success").Inc()
imageCounterSuccess.Inc()
returnResult(config, client, Result{
Id: image.Id,
Success: true,
......
......@@ -11,7 +11,7 @@ func serveQueue(client *redis.Client, queue string, function func(value string))
element := client.BLPop(0, fmt.Sprintf("queue:%s", queue))
if len(element.Val()) == 2 {
value := element.Val()[1]
queueGauge.Inc()
queueGaugeQueued.Inc()
go function(value)
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment