aboutsummaryrefslogtreecommitdiff
path: root/internal/app/metrics.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/app/metrics.go')
-rw-r--r--internal/app/metrics.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/internal/app/metrics.go b/internal/app/metrics.go
new file mode 100644
index 00000000..80ff32f6
--- /dev/null
+++ b/internal/app/metrics.go
@@ -0,0 +1,29 @@
+// Copyright 2020 The Gogs Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package app
+
+import (
+ "net/http"
+
+ "gopkg.in/macaron.v1"
+
+ "gogs.io/gogs/internal/conf"
+ "gogs.io/gogs/internal/context"
+)
+
+func MetricsFilter() macaron.Handler {
+ return func(c *context.Context) {
+ if !conf.Prometheus.Enabled {
+ c.Status(http.StatusNotFound)
+ return
+ }
+
+ if !conf.Prometheus.EnableBasicAuth {
+ return
+ }
+
+ c.RequireBasicAuth(conf.Prometheus.BasicAuthUsername, conf.Prometheus.BasicAuthPassword)
+ }
+}