File tree Expand file tree Collapse file tree 3 files changed +17
-2
lines changed Expand file tree Collapse file tree 3 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ type Config struct {
28
28
WakeOnLanDevices []WakeOnLanDevice `json:"wake_on_lan_devices"`
29
29
EdidString string `json:"hdmi_edid_string"`
30
30
ActiveExtension string `json:"active_extension"`
31
+ MetricsEnabled bool `json:"enable_metrics"`
31
32
DisplayMaxBrightness int `json:"display_max_brightness"`
32
33
DisplayDimAfterSec int `json:"display_dim_after_sec"`
33
34
DisplayOffAfterSec int `json:"display_off_after_sec"`
Original file line number Diff line number Diff line change @@ -3,8 +3,10 @@ package kvm
3
3
import (
4
4
"net/http"
5
5
6
+ "github.com/gin-gonic/gin"
6
7
"github.com/prometheus/client_golang/prometheus"
7
8
versioncollector "github.com/prometheus/client_golang/prometheus/collectors/version"
9
+ "github.com/prometheus/client_golang/prometheus/promhttp"
8
10
"github.com/prometheus/common/version"
9
11
)
10
12
@@ -14,4 +16,17 @@ func initPrometheus() {
14
16
// A Prometheus metrics endpoint.
15
17
version .Version = builtAppVersion
16
18
prometheus .MustRegister (versioncollector .NewCollector ("jetkvm" ))
19
+
20
+ promHandler = promhttp .Handler ()
21
+ }
22
+
23
+ func prometheusCheckAuthMiddleware () gin.HandlerFunc {
24
+ return func (c * gin.Context ) {
25
+ if ! config .MetricsEnabled {
26
+ c .JSON (http .StatusNotFound , gin.H {"error" : "Metrics endpoint is disabled" })
27
+ return
28
+ }
29
+
30
+ c .Next ()
31
+ }
17
32
}
Original file line number Diff line number Diff line change @@ -12,7 +12,6 @@ import (
12
12
13
13
"github.com/gin-gonic/gin"
14
14
"github.com/google/uuid"
15
- "github.com/prometheus/client_golang/prometheus/promhttp"
16
15
"golang.org/x/crypto/bcrypt"
17
16
)
18
17
@@ -87,7 +86,7 @@ func setupRouter() *gin.Engine {
87
86
r .POST ("/device/setup" , handleSetup )
88
87
89
88
// A Prometheus metrics endpoint.
90
- r .GET ("/metrics" , gin .WrapH (promhttp . Handler () ))
89
+ r .GET ("/metrics" , prometheusCheckAuthMiddleware (), gin .WrapH (promHandler ))
91
90
92
91
// Protected routes (allows both password and noPassword modes)
93
92
protected := r .Group ("/" )
You can’t perform that action at this time.
0 commit comments