9
9
"github.com/jetkvm/kvm/internal/logging"
10
10
"github.com/jetkvm/kvm/internal/network"
11
11
"github.com/jetkvm/kvm/internal/usbgadget"
12
+ "github.com/prometheus/client_golang/prometheus"
13
+ "github.com/prometheus/client_golang/prometheus/promauto"
12
14
)
13
15
14
16
type WakeOnLanDevice struct {
@@ -138,6 +140,21 @@ var (
138
140
configLock = & sync.Mutex {}
139
141
)
140
142
143
+ var (
144
+ configSuccess = promauto .NewGauge (
145
+ prometheus.GaugeOpts {
146
+ Name : "jetkvm_config_last_reload_successful" ,
147
+ Help : "The last configuration load succeeded" ,
148
+ },
149
+ )
150
+ configSuccessTime = promauto .NewGauge (
151
+ prometheus.GaugeOpts {
152
+ Name : "jetkvm_config_last_reload_success_timestamp_seconds" ,
153
+ Help : "Timestamp of last successful config load" ,
154
+ },
155
+ )
156
+ )
157
+
141
158
func LoadConfig () {
142
159
configLock .Lock ()
143
160
defer configLock .Unlock ()
@@ -153,6 +170,8 @@ func LoadConfig() {
153
170
file , err := os .Open (configPath )
154
171
if err != nil {
155
172
logger .Debug ().Msg ("default config file doesn't exist, using default" )
173
+ configSuccess .Set (1.0 )
174
+ configSuccessTime .SetToCurrentTime ()
156
175
return
157
176
}
158
177
defer file .Close ()
@@ -161,6 +180,7 @@ func LoadConfig() {
161
180
loadedConfig := * defaultConfig
162
181
if err := json .NewDecoder (file ).Decode (& loadedConfig ); err != nil {
163
182
logger .Warn ().Err (err ).Msg ("config file JSON parsing failed" )
183
+ configSuccess .Set (0.0 )
164
184
return
165
185
}
166
186
@@ -181,6 +201,9 @@ func LoadConfig() {
181
201
182
202
logging .GetRootLogger ().UpdateLogLevel (config .DefaultLogLevel )
183
203
204
+ configSuccess .Set (1.0 )
205
+ configSuccessTime .SetToCurrentTime ()
206
+
184
207
logger .Info ().Str ("path" , configPath ).Msg ("config loaded" )
185
208
}
186
209
0 commit comments