Add new HTTPServer to serve /metrics on port 8082

This commit runs a new HTTPServer on port 8082 in a goroutine to serve
/metrics endpoint on a different port.

This also update the configurations and compose files.

Fixes: #1081

Signed-off-by: Vivek Singh <vivekkmr45@yahoo.in>
This commit is contained in:
Vivek Singh 2019-02-13 16:06:27 +05:30 committed by Alex Ellis
parent aeb4eb9993
commit 90ddd56985
9 changed files with 24 additions and 3 deletions

View File

@ -3,6 +3,7 @@ services:
gateway: gateway:
ports: ports:
- 8080:8080 - 8080:8080
- 8082:8082
image: openfaas/gateway:0.11.0-arm64 image: openfaas/gateway:0.11.0-arm64
networks: networks:
- functions - functions

View File

@ -3,6 +3,7 @@ services:
gateway: gateway:
ports: ports:
- 8080:8080 - 8080:8080
- 8082:8082
image: openfaas/gateway:0.11.0-armhf image: openfaas/gateway:0.11.0-armhf
networks: networks:
- functions - functions

View File

@ -3,6 +3,7 @@ services:
gateway: gateway:
ports: ports:
- 8080:8080 - 8080:8080
- 8082:8082
image: openfaas/gateway:0.11.1 image: openfaas/gateway:0.11.1
networks: networks:
- functions - functions

View File

@ -48,6 +48,7 @@ RUN addgroup -S app \
WORKDIR /home/app WORKDIR /home/app
EXPOSE 8080 EXPOSE 8080
EXPOSE 8082
ENV http_proxy "" ENV http_proxy ""
ENV https_proxy "" ENV https_proxy ""

View File

@ -29,6 +29,7 @@ RUN addgroup -S app \
WORKDIR /home/app WORKDIR /home/app
EXPOSE 8080 EXPOSE 8080
EXPOSE 8082
ENV http_proxy "" ENV http_proxy ""
ENV https_proxy "" ENV https_proxy ""

View File

@ -48,6 +48,7 @@ RUN addgroup -S app \
WORKDIR /home/app WORKDIR /home/app
EXPOSE 8080 EXPOSE 8080
EXPOSE 8082
ENV http_proxy "" ENV http_proxy ""
ENV https_proxy "" ENV https_proxy ""

View File

@ -207,7 +207,22 @@ func main() {
} }
metricsHandler := metrics.PrometheusHandler() metricsHandler := metrics.PrometheusHandler()
r.Handle("/metrics", metricsHandler)
//Create a new server to serve /metrics endpoint
go func() {
routes := mux.NewRouter()
routes.Handle("/metrics", metricsHandler)
port := 8082
s := &http.Server{
Addr: fmt.Sprintf(":%d", port),
ReadTimeout: config.ReadTimeout,
WriteTimeout: config.WriteTimeout,
MaxHeaderBytes: http.DefaultMaxHeaderBytes,
Handler: routes,
}
log.Fatal(s.ListenAndServe())
}()
r.HandleFunc("/healthz", handlers.MakeForwardingProxyHandler(reverseProxy, forwardingNotifiers, urlResolver, nilURLTransformer)).Methods(http.MethodGet) r.HandleFunc("/healthz", handlers.MakeForwardingProxyHandler(reverseProxy, forwardingNotifiers, urlResolver, nilURLTransformer)).Methods(http.MethodGet)
r.Handle("/", http.RedirectHandler("/ui/", http.StatusMovedPermanently)).Methods(http.MethodGet) r.Handle("/", http.RedirectHandler("/ui/", http.StatusMovedPermanently)).Methods(http.MethodGet)

View File

@ -32,6 +32,6 @@ scrape_configs:
scrape_interval: 5s scrape_interval: 5s
dns_sd_configs: dns_sd_configs:
- names: ['gateway.default.svc.cluster.local'] - names: ['gateway.default.svc.cluster.local']
port: 8080 port: 8082
type: A type: A
refresh_interval: 5s refresh_interval: 5s

View File

@ -32,7 +32,7 @@ scrape_configs:
scrape_interval: 5s scrape_interval: 5s
dns_sd_configs: dns_sd_configs:
- names: ['tasks.gateway'] - names: ['tasks.gateway']
port: 8080 port: 8082
type: A type: A
refresh_interval: 5s refresh_interval: 5s