Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app.go
diff options
context:
space:
mode:
authorZ.J. van de Weg <git@zjvandeweg.nl>2017-02-03 00:08:19 +0300
committerZ.J. van de Weg <git@zjvandeweg.nl>2017-02-07 21:38:47 +0300
commitddff37bc7cecf2f73a7bb82d60391505ad96a426 (patch)
tree88bdfc87ba74866da6224ddea200062fee31e5aa /app.go
parent1e31fac9d8a60efb3b2b536a46e059f286ab62c0 (diff)
Improve complexity metrics
Also fixed the dependencies, moved metrics to its own package and updated the tests
Diffstat (limited to 'app.go')
-rw-r--r--app.go24
1 files changed, 16 insertions, 8 deletions
diff --git a/app.go b/app.go
index ffe7bc24..4ef5e730 100644
--- a/app.go
+++ b/app.go
@@ -9,7 +9,9 @@ import (
"sync"
"time"
+ "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
+ "gitlab.com/gitlab-org/gitlab-pages/metrics"
)
const xForwardedProto = "X-Forwarded-Proto"
@@ -46,8 +48,8 @@ func (a *theApp) serveContent(ww http.ResponseWriter, r *http.Request, https boo
w := newLoggingResponseWriter(ww)
defer w.Log(r)
- sessionsActive.Inc()
- defer sessionsActive.Dec()
+ metrics.SessionsActive.Inc()
+ defer metrics.SessionsActive.Dec()
// Add auto redirect
if https && !a.RedirectHTTP {
@@ -68,7 +70,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()
+ metrics.ProcessedRequests.WithLabelValues(strconv.Itoa(w.status), r.Method).Inc()
}
func (a *theApp) ServeHTTP(ww http.ResponseWriter, r *http.Request) {
@@ -129,11 +131,17 @@ func (a *theApp) Run() {
}
// Serve metrics for Prometheus
- if a.MetricsAddress != "" {
- go func() {
- http.Handle("/metrics", promhttp.Handler())
- log.Fatal(http.ListenAndServe(a.MetricsAddress, nil))
- }()
+ if a.ListenMetrics != 0 {
+ wg.Add(1)
+ go func(fd uintptr) {
+ defer wg.Done()
+
+ handler := promhttp.HandlerFor(prometheus.DefaultGatherer, promhttp.HandlerOpts{}).ServeHTTP
+ err := listenAndServe(fd, handler, false, nil)
+ if err != nil {
+ log.Fatal(err)
+ }
+ }(a.ListenMetrics)
}
go watchDomains(a.Domain, a.UpdateDomains, time.Second)