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 {
2828 WakeOnLanDevices []WakeOnLanDevice `json:"wake_on_lan_devices"`
2929 EdidString string `json:"hdmi_edid_string"`
3030 ActiveExtension string `json:"active_extension"`
31+ MetricsEnabled bool `json:"enable_metrics"`
3132 DisplayMaxBrightness int `json:"display_max_brightness"`
3233 DisplayDimAfterSec int `json:"display_dim_after_sec"`
3334 DisplayOffAfterSec int `json:"display_off_after_sec"`
Original file line number Diff line number Diff line change @@ -3,8 +3,10 @@ package kvm
33import (
44 "net/http"
55
6+ "github.com/gin-gonic/gin"
67 "github.com/prometheus/client_golang/prometheus"
78 versioncollector "github.com/prometheus/client_golang/prometheus/collectors/version"
9+ "github.com/prometheus/client_golang/prometheus/promhttp"
810 "github.com/prometheus/common/version"
911)
1012
@@ -14,4 +16,17 @@ func initPrometheus() {
1416 // A Prometheus metrics endpoint.
1517 version .Version = builtAppVersion
1618 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+ }
1732}
Original file line number Diff line number Diff line change @@ -12,7 +12,6 @@ import (
1212
1313 "github.com/gin-gonic/gin"
1414 "github.com/google/uuid"
15- "github.com/prometheus/client_golang/prometheus/promhttp"
1615 "golang.org/x/crypto/bcrypt"
1716)
1817
@@ -87,7 +86,7 @@ func setupRouter() *gin.Engine {
8786 r .POST ("/device/setup" , handleSetup )
8887
8988 // A Prometheus metrics endpoint.
90- r .GET ("/metrics" , gin .WrapH (promhttp . Handler () ))
89+ r .GET ("/metrics" , prometheusCheckAuthMiddleware (), gin .WrapH (promHandler ))
9190
9291 // Protected routes (allows both password and noPassword modes)
9392 protected := r .Group ("/" )
You can’t perform that action at this time.
0 commit comments