mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-22 09:51:01 +00:00
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:
parent
2171212c5a
commit
9288670c61
4 changed files with 25 additions and 0 deletions
|
@ -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",
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue