Skip to content

Commit

Permalink
add build_info metric for KSM
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Ye <yb532204897@gmail.com>
  • Loading branch information
yeya24 committed Dec 18, 2020
1 parent a832eeb commit 0e319bd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ http_request_duration_seconds_sum{handler="metrics",method="get"} 0.021113919999
http_request_duration_seconds_count{handler="metrics",method="get"} 30
```

kube-state-metrics exposes the build info metric:
```
kube_state_metrics_build_info{goversion="go1.14.7",revision="a832eebc",version="v2.0.0-beta"} 1
```


### Scaling kube-state-metrics

#### Resource recommendation
Expand Down
17 changes: 17 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"net/http"
"net/http/pprof"
"os"
"runtime"
"strconv"
"time"

Expand Down Expand Up @@ -80,6 +81,7 @@ func main() {
storeBuilder := store.NewBuilder()

ksmMetricsRegistry := prometheus.NewRegistry()
registerBuildInfo(ksmMetricsRegistry)
durationVec := promauto.With(ksmMetricsRegistry).NewHistogramVec(
prometheus.HistogramOpts{
Name: "http_request_duration_seconds",
Expand Down Expand Up @@ -295,3 +297,18 @@ func buildMetricsServer(m *metricshandler.MetricsHandler, durationObserver prome
})
return mux
}

func registerBuildInfo(r prometheus.Registerer) {
v := version.GetVersion()
promauto.With(r).NewGaugeFunc(prometheus.GaugeOpts{
Name: "kube_state_metrics_build_info",
Help: "A metric with a constant '1' value labeled by version, revision, and " +
"goversion from which kube-state-metrics was built.",
ConstLabels: prometheus.Labels{
"version": v.Release,
"revision": v.GitCommit,
"goversion": runtime.Version(),
}},
func() float64 { return 1 },
)
}

0 comments on commit 0e319bd

Please sign in to comment.