Setup basic prom metrics endpoint (#624)
* Setup basic prom metrics endpoint * Use default prom handler to expose go runtime metrics
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
||||
"github.com/sosedoff/pgweb/pkg/client"
|
||||
"github.com/sosedoff/pgweb/pkg/command"
|
||||
"github.com/sosedoff/pgweb/pkg/connection"
|
||||
"github.com/sosedoff/pgweb/pkg/metrics"
|
||||
"github.com/sosedoff/pgweb/pkg/util"
|
||||
)
|
||||
|
||||
@@ -199,9 +200,12 @@ func startServer() {
|
||||
|
||||
api.SetLogger(logger)
|
||||
api.SetupRoutes(router)
|
||||
api.SetupMetrics(router)
|
||||
|
||||
fmt.Println("Starting server...")
|
||||
go func() {
|
||||
metrics.SetHealty(true)
|
||||
|
||||
err := router.Run(fmt.Sprintf("%v:%v", options.HTTPHost, options.HTTPPort))
|
||||
if err != nil {
|
||||
fmt.Println("Cant start server:", err)
|
||||
@@ -213,6 +217,18 @@ func startServer() {
|
||||
}()
|
||||
}
|
||||
|
||||
func startMetricsServer() {
|
||||
serverAddr := fmt.Sprintf("%v:%v", command.Opts.HTTPHost, command.Opts.HTTPPort)
|
||||
if options.MetricsAddr == serverAddr {
|
||||
return
|
||||
}
|
||||
|
||||
err := metrics.StartServer(logger, options.MetricsPath, options.MetricsAddr)
|
||||
if err != nil {
|
||||
logger.WithError(err).Fatal("unable to start prometheus metrics server")
|
||||
}
|
||||
}
|
||||
|
||||
func handleSignals() {
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||
@@ -265,6 +281,10 @@ func Run() {
|
||||
}
|
||||
}
|
||||
|
||||
if options.MetricsEnabled && options.MetricsAddr != "" {
|
||||
go startMetricsServer()
|
||||
}
|
||||
|
||||
startServer()
|
||||
openPage()
|
||||
handleSignals()
|
||||
|
||||
Reference in New Issue
Block a user