diff options
author | Z.J. van de Weg <git@zjvandeweg.nl> | 2017-01-26 00:11:28 +0300 |
---|---|---|
committer | Z.J. van de Weg <git@zjvandeweg.nl> | 2017-02-02 23:52:30 +0300 |
commit | 1e31fac9d8a60efb3b2b536a46e059f286ab62c0 (patch) | |
tree | 3d751e07782a5e9489a46d6f4c6a96ea34cb08e6 /app.go | |
parent | bc4aa822bff4ec2a3a3fdb1daa915782331ad08a (diff) |
Prometheus monitoring for GitLab Pages
This starts of the prometheus monitoring for GitLab Pages, and
resolves gitlab-org/gitlab-pages#42
Point to check:
- Are the metric names good, keeping Prometheus' conventions in mind?
- Golang, general style etc
- Shouldn't I do some voodoo magic to import this in the library?
Diffstat (limited to 'app.go')
-rw-r--r-- | app.go | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -4,9 +4,12 @@ import ( "crypto/tls" "log" "net/http" + "strconv" "strings" "sync" "time" + + "github.com/prometheus/client_golang/prometheus/promhttp" ) const xForwardedProto = "X-Forwarded-Proto" @@ -43,6 +46,9 @@ func (a *theApp) serveContent(ww http.ResponseWriter, r *http.Request, https boo w := newLoggingResponseWriter(ww) defer w.Log(r) + sessionsActive.Inc() + defer sessionsActive.Dec() + // Add auto redirect if https && !a.RedirectHTTP { u := *r.URL @@ -62,6 +68,7 @@ func (a *theApp) serveContent(ww http.ResponseWriter, r *http.Request, https boo // Serve static file domain.ServeHTTP(&w, r) + processedRequests.WithLabelValues(strconv.Itoa(w.status), r.Method).Inc() } func (a *theApp) ServeHTTP(ww http.ResponseWriter, r *http.Request) { @@ -121,6 +128,14 @@ func (a *theApp) Run() { }(fd) } + // Serve metrics for Prometheus + if a.MetricsAddress != "" { + go func() { + http.Handle("/metrics", promhttp.Handler()) + log.Fatal(http.ListenAndServe(a.MetricsAddress, nil)) + }() + } + go watchDomains(a.Domain, a.UpdateDomains, time.Second) wg.Wait() |