Skip to content

Commit

Permalink
Added LISTEN_ADDRESS as env to set metrics endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
itisallgood committed Sep 20, 2024
1 parent df01a9d commit 505dc15
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,12 @@ helm install kubewatch robusta/kubewatch --set='rbac.create=true,slack.channel=#
```

#### Metrics
`kubewatch` runs a Prometheus metrics endpoint at `/metrics` on port `2112` that can be used to monitor health and the performance of `kubewatch`.
`kubewatch` runs a Prometheus metrics endpoint at `/metrics` on port `2112` by default. This endpoint can be used to monitor health and the performance of `kubewatch`.

The `kubewatch_events_total` metric can help track the total number of Kubernetes events, categorized by resource type (e.g., `Pods`, `Deployments`) and event type (e.g., `Create`, `Delete`).

You can change the default port (`2112`) on which the metrics server listens by setting the `LISTEN_ADDRESS` environment variable.

### Local Installation
#### Using go package installer:

Expand Down
13 changes: 8 additions & 5 deletions pkg/client/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package client

import (
"net/http"

"os"
"github.com/prometheus/client_golang/prometheus/promhttp"

"github.com/bitnami-labs/kubewatch/config"
Expand All @@ -39,13 +39,16 @@ import (

// Run runs the event loop processing with given handler
func Run(conf *config.Config) {
metricsPort := ":2112"
listenAddress := os.Getenv("LISTEN_ADDRESS")
if listenAddress == "" {
listenAddress = ":2112"
}

go func() {
http.Handle("/metrics", promhttp.Handler())
logrus.Infof("Starting metrics server on port %s", metricsPort)
if err := http.ListenAndServe(metricsPort, nil); err != nil {
logrus.Errorf("Error starting metrics server on port %s: %v", metricsPort, err)
logrus.Infof("Starting metrics server on port %s", listenAddress)
if err := http.ListenAndServe(listenAddress, nil); err != nil {
logrus.Errorf("Error starting metrics server on port %s: %v", listenAddress, err)
}
}()

Expand Down

0 comments on commit 505dc15

Please sign in to comment.