77 "sync"
88
99 "github.com/jetkvm/kvm/internal/usbgadget"
10+ "github.com/prometheus/client_golang/prometheus"
11+ "github.com/prometheus/client_golang/prometheus/promauto"
1012)
1113
1214type WakeOnLanDevice struct {
@@ -127,6 +129,21 @@ var (
127129 configLock = & sync.Mutex {}
128130)
129131
132+ var (
133+ configSuccess = promauto .NewGauge (
134+ prometheus.GaugeOpts {
135+ Name : "jetkvm_config_last_reload_successful" ,
136+ Help : "The last configuration load succeeded" ,
137+ },
138+ )
139+ configSuccessTime = promauto .NewGauge (
140+ prometheus.GaugeOpts {
141+ Name : "jetkvm_config_last_reload_success_timestamp_seconds" ,
142+ Help : "Timestamp of last successful config load" ,
143+ },
144+ )
145+ )
146+
130147func LoadConfig () {
131148 configLock .Lock ()
132149 defer configLock .Unlock ()
@@ -142,6 +159,8 @@ func LoadConfig() {
142159 file , err := os .Open (configPath )
143160 if err != nil {
144161 logger .Debug ().Msg ("default config file doesn't exist, using default" )
162+ configSuccess .Set (1.0 )
163+ configSuccessTime .SetToCurrentTime ()
145164 return
146165 }
147166 defer file .Close ()
@@ -150,6 +169,7 @@ func LoadConfig() {
150169 loadedConfig := * defaultConfig
151170 if err := json .NewDecoder (file ).Decode (& loadedConfig ); err != nil {
152171 logger .Warn ().Err (err ).Msg ("config file JSON parsing failed" )
172+ configSuccess .Set (0.0 )
153173 return
154174 }
155175
@@ -162,6 +182,8 @@ func LoadConfig() {
162182 loadedConfig .UsbDevices = defaultConfig .UsbDevices
163183 }
164184
185+ configSuccess .Set (1.0 )
186+ configSuccessTime .SetToCurrentTime ()
165187 config = & loadedConfig
166188}
167189
0 commit comments