feat: expose unprotected metrics endpoint (#1614)

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: Anbraten <anton@ju60.de>
This commit is contained in:
Alexander Matyushentsev 2023-03-12 00:41:10 -08:00 committed by GitHub
parent 2171212c5a
commit 9288670c61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 0 deletions

View file

@ -77,6 +77,12 @@ var flags = []cli.Flag{
Usage: "grpc address",
Value: ":9000",
},
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_METRICS_SERVER_ADDR"},
Name: "metrics-server-addr",
Usage: "metrics server address",
Value: "",
},
&cli.StringSliceFlag{
EnvVars: []string{"WOODPECKER_ADMIN"},
Name: "admin",

View file

@ -27,6 +27,7 @@ import (
"github.com/caddyserver/certmagic"
"github.com/gin-gonic/gin"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
@ -258,6 +259,14 @@ func run(c *cli.Context) error {
})
}
if metricsServerAddr := c.String("metrics-server-addr"); metricsServerAddr != "" {
g.Go(func() error {
metricsRouter := gin.New()
metricsRouter.GET("/metrics", gin.WrapH(promhttp.Handler()))
return http.ListenAndServe(metricsServerAddr, metricsRouter)
})
}
log.Info().Msgf("Starting Woodpecker server with version '%s'", version.String())
return g.Wait()

View file

@ -160,6 +160,12 @@ Automatically generates an SSL certificate using Let's Encrypt, and configures t
Configures the gRPC listener port.
### `WOODPECKER_METRICS_SERVER_ADDR`
> Default: empty
Configures an unprotected metrics endpoint. An empty value disables the metrics endpoint completely.
Example: `:9001`
### `WOODPECKER_ADMIN`
> Default: empty

View file

@ -30,6 +30,10 @@ scrape_configs:
- targets: ['woodpecker.domain.com']
```
## Unauthenticated Access
Alternatively, the unprotected `/metrics` endpoint might be exposed on the internal port. (Port is configurable via the `WOODPECKER_METRICS_SERVER_ADDR` environment variable, e.g. `:9001`.)
## Metric Reference
List of Prometheus metrics specific to Woodpecker: