Add metrics endpoint support to server
We add two flags --enable-metrics and --metrics-port to enable metrics endpoint and allow specifying the port which defaults to 9090. Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
parent
0e1452a4ec
commit
43bc359fc0
1 changed files with 26 additions and 0 deletions
|
@ -285,6 +285,15 @@ func main() {
|
|||
Value: 6060,
|
||||
Usage: "port for the pprof profiler",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "enable-metrics",
|
||||
Usage: "enable metrics endpoint for the servier on localhost:9090",
|
||||
},
|
||||
cli.IntFlag{
|
||||
Name: "metrics-port",
|
||||
Value: 9090,
|
||||
Usage: "port for the metrics endpoint",
|
||||
},
|
||||
}
|
||||
|
||||
sort.Sort(cli.FlagsByName(app.Flags))
|
||||
|
@ -374,6 +383,23 @@ func main() {
|
|||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
if c.GlobalBool("enable-metrics") {
|
||||
metricsPort := c.GlobalInt("metrics-port")
|
||||
me, err := service.CreateMetricsEndpoint()
|
||||
if err != nil {
|
||||
logrus.Fatalf("Failed to create metrics endpoint: %v", err)
|
||||
}
|
||||
l, err := net.Listen("tcp", fmt.Sprintf(":%v", metricsPort))
|
||||
if err != nil {
|
||||
logrus.Fatalf("Failed to create listener for metrics: %v", err)
|
||||
}
|
||||
go func() {
|
||||
if err := http.Serve(l, me); err != nil {
|
||||
logrus.Fatalf("Failed to serve metrics endpoint: %v", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
graceful := false
|
||||
catchShutdown(s, service, &graceful)
|
||||
runtime.RegisterRuntimeServiceServer(s, service)
|
||||
|
|
Loading…
Reference in a new issue