1
0
mirror of https://github.com/rancher/norman.git synced 2025-07-04 02:56:42 +00:00
norman/metrics/generic_controller.go
Yuki Nishiwaki 90a67b5678 Add Generic Controller Related Metrics
To enhance operatability for the service using norman framework,
It's better to expose internal state as detail as possible.
This is the just starting point but at least which handler is executed
often and which handler with which key's execution is often failed
metrics is very useful to spot the place operator have to dig in when
something happened.
So this commit added 2 metrics.
1: handler execution total count
2: handler execution failure total count
2018-10-05 14:36:58 +09:00

59 lines
1.3 KiB
Go

package metrics
import (
"os"
"github.com/prometheus/client_golang/prometheus"
)
const MetricsGenericControllerEnv = "NORMAN_GENERIC_CONTROLLER_METRICS"
var (
genericControllerMetrics = false
TotalHandlerExecution = prometheus.NewCounterVec(
prometheus.CounterOpts{
Subsystem: "norman_generic_controller",
Name: "total_handler_execution",
Help: "Total Count of executing handler",
},
[]string{"name", "handlerName"},
)
TotalHandlerFailure = prometheus.NewCounterVec(
prometheus.CounterOpts{
Subsystem: "norman_generic_controller",
Name: "total_handler_failure",
Help: "Total Count of handler failure",
},
[]string{"name", "handlerName", "key"},
)
)
func init() {
if os.Getenv(MetricsGenericControllerEnv) == "true" {
genericControllerMetrics = true
}
}
func IncTotalHandlerExecution(controllerName, handlerName string) {
if genericControllerMetrics {
TotalHandlerExecution.With(
prometheus.Labels{
"name": controllerName,
"handlerName": handlerName},
).Inc()
}
}
func IncTotalHandlerFailure(controllerName, handlerName, key string) {
if genericControllerMetrics {
TotalHandlerFailure.With(
prometheus.Labels{
"name": controllerName,
"handlerName": handlerName,
"key": key,
},
).Inc()
}
}