# HG changeset patch # User Alexander Trost <galexrt@googlemail.com> # Date 1499013487 -7200 # Sun Jul 02 18:38:07 2017 +0200 # Node ID 7cc5e3185411ed88fc39edaaff967d93dde0cf76 # Parent a6aca39a67941825529b7ecacb61ad6a52614dbe Added prometheus metrics support diff --git a/main.go b/main.go --- a/main.go +++ b/main.go @@ -1,18 +1,22 @@ package main import ( + "flag" "net/http" "os" "time" log "github.com/Sirupsen/logrus" "github.com/gorilla/handlers" + "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/common/version" ) var ready = false +var addr = flag.String("listen-address", ":8080", "The address to listen on for HTTP requests.") func main() { + flag.Parse() log.Info("Starting presentation-gitlab-k8s application..") http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { hostname, _ := os.Hostname() @@ -30,11 +34,12 @@ w.Write([]byte("500")) } }) + http.Handle("/metrics", promhttp.Handler()) go func() { <-time.After(5 * time.Second) ready = true log.Info("Application is ready!") }() - log.Info("Listen on :8000") - log.Fatal(http.ListenAndServe(":8000", handlers.LoggingHandler(os.Stdout, http.DefaultServeMux))) + log.Info("Listen on " + *addr) + log.Fatal(http.ListenAndServe(*addr, handlers.LoggingHandler(os.Stdout, http.DefaultServeMux))) } diff --git a/service.yaml b/service.yaml --- a/service.yaml +++ b/service.yaml @@ -6,7 +6,8 @@ spec: type: ClusterIP ports: - - port: 8000 + - name: http-metrics + port: 8000 protocol: TCP selector: app: __CI_ENVIRONMENT_SLUG__