Skip to content

Commit a651f36

Browse files
authored
Merge pull request #137 from Keyruu/main
feat: add is_suspended to host info metric
2 parents 92c3ede + a88044a commit a651f36

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

internal/manager/manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func (m *Manager) Run(ctx context.Context) {
224224
if lastDpl != nil {
225225
m.needToReboot = m.executor.NeedToReboot(lastDpl.Generation.OutPath, lastDpl.Operation)
226226
}
227-
m.prometheus.SetHostInfo(m.needToReboot)
227+
m.prometheus.SetHostInfo(m.needToReboot, m.isSuspended)
228228

229229
m.FetchAndBuild(ctx)
230230
m.deployer.Run(ctx)
@@ -256,7 +256,7 @@ func (m *Manager) Run(ctx context.Context) {
256256
e := &protobuf.Event_RebootRequired{Deployment: dpl}
257257
m.broker.Publish(&protobuf.Event{Type: &protobuf.Event_RebootRequired_{RebootRequired: e}})
258258
}
259-
m.prometheus.SetHostInfo(m.needToReboot)
259+
m.prometheus.SetHostInfo(m.needToReboot, m.isSuspended)
260260
if dpl.RestartComin.GetValue() {
261261
// TODO: stop contexts
262262
logrus.Infof("manager: comin needs to be restarted")

internal/prometheus/prometheus.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func New() Prometheus {
3232
hostInfo := prometheus.NewGaugeVec(prometheus.GaugeOpts{
3333
Name: "comin_host_info",
3434
Help: "Info of the host.",
35-
}, []string{"need_to_reboot"})
35+
}, []string{"is_suspended", "need_to_reboot"})
3636
promReg.MustRegister(buildInfo)
3737
promReg.MustRegister(deploymentInfo)
3838
promReg.MustRegister(fetchCounter)
@@ -68,13 +68,17 @@ func (m Prometheus) SetDeploymentInfo(commitId, status string) {
6868
m.deploymentInfo.With(prometheus.Labels{"commit_id": commitId, "status": status}).Set(1)
6969
}
7070

71-
func (m Prometheus) SetHostInfo(needToReboot bool) {
72-
m.hostInfo.Reset()
73-
var value string
74-
if needToReboot {
75-
value = "1"
76-
} else {
77-
value = "0"
71+
func boolToString(b bool) string {
72+
if b {
73+
return "1"
7874
}
79-
m.hostInfo.With(prometheus.Labels{"need_to_reboot": value}).Set(1)
75+
return "0"
76+
}
77+
78+
func (m Prometheus) SetHostInfo(needToReboot bool, isSuspended bool) {
79+
m.hostInfo.Reset()
80+
m.hostInfo.With(prometheus.Labels{
81+
"need_to_reboot": boolToString(needToReboot),
82+
"is_suspended": boolToString(isSuspended),
83+
}).Set(1)
8084
}

0 commit comments

Comments
 (0)