New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need for SetListenAddress in prometheus. #31
Comments
I am looking for a way to hide the metrics-endpoint from the public as well, because the contain quite sensistive information!
I saw, that the methods |
no idea but you do not need them. Handler uses prometheus global objects and necessary handler can be created and served from/by ordinary http.Server This is how handler is created for Echo echo-contrib/prometheus/prometheus.go Lines 418 to 424 in 4d116ee
This should be enough for you to serve prom form custom server. metricsServer := http.Server{
Addr: "localhost:8080",
Handler: promhttp.Handler(),
}
if err := metricsServer.ListenAndServe(); err != http.ErrServerClosed {
// log.fatal
} |
closing, new middleware was added with #94 Newer middleware allows user to separate handler function which can be served from different http server. extremely simplistic example: import (
"errors"
"github.com/labstack/echo-contrib/echoprometheus"
"github.com/labstack/echo/v4"
"log"
"net/http"
)
func main() {
e := echo.New()
e.Use(echoprometheus.NewMiddleware("myapp")) // Add metrics middleware
go func() {
private := echo.New()
private.GET("/metrics", echoprometheus.NewHandler()) // Add handler for metrics scrapers
if err := private.Start("localhost:8081"); err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Fatal(err)
}
}()
if err := e.Start("0.0.0.0:8080"); err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Fatal(err)
}
} |
Need the SetListenAddress in prometheus to include the middleware in my project where the go project is being used as an API gateway and if the default address is set to give the metrics it will make the metrics open for the public to hit.
The text was updated successfully, but these errors were encountered: