Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add mapi_machinehealthcheck_remediation_success_total metric #754

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions docs/dev/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,21 @@ When using MachineHealthChecks, metrics are available from the `machine-api-cont
default metrics port(`8083`) for the `machine-healthcheck-controller` container.

The `mapi_machinehealthcheck_nodes_covered` metric describes the number of Nodes that are currently
being monitored by `machine-healthcheck-controller`. The `name` label in this metric refers to the
name of the MachineHealthCheck that is being reported. The `namespace` label refers to the owning
namespace of the MachineHealthCheck.
being monitored by `machine-healthcheck-controller`.

The `mapi_machinehealthcheck_remediation_success_total` metric gives a total count of the successful
remediation performed by a MachineHealthCheck.

The `name` label in these metric refers to the name of the MachineHealthCheck that is being reported.
The `namespace` label refers to the owning namespace of the MachineHealthCheck.

**Sample metrics**
```
# HELP mapi_machinehealthcheck_nodes_covered Number of nodes covered by MachineHealthChecks
# TYPE mapi_machinehealthcheck_nodes_covered gauge
mapi_machinehealthcheck_nodes_covered{name="machine-api-termination-handler",namespace="openshift-machine-api"} 0
mapi_machinehealthcheck_nodes_covered{name="mhc-1",namespace="openshift-machine-api"} 1
# HELP mapi_machinehealthcheck_remediation_success_total Number of successful remediations performed by MachineHealthChecks
# TYPE mapi_machinehealthcheck_remediation_success_total counter
mapi_machinehealthcheck_remediation_success_total{name="mhc-1",namespace="openshift-machine-api"} 1
```
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ func (t *target) remediate(r *ReconcileMachineHealthCheck) error {
"Machine %v has been remediated by requesting to delete Machine object",
t.string(),
)
metrics.ObserveMachineHealthCheckRemediationSuccess(t.MHC.Name, t.MHC.Namespace)

return nil
}

Expand Down
20 changes: 19 additions & 1 deletion pkg/metrics/machinehealthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,21 @@ var (
Help: "Number of nodes covered by MachineHealthChecks",
}, []string{"name", "namespace"},
)

// MachineHealthCheckRemediationSuccessTotal is a Prometheus metric, which reports the number of successful remediations by MachineHealthChecks
MachineHealthCheckRemediationSuccessTotal = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "mapi_machinehealthcheck_remediation_success_total",
Help: "Number of successful remediations performed by MachineHealthChecks",
}, []string{"name", "namespace"},
)
)

func InitializeMachineHealthCheckMetrics() {
metrics.Registry.MustRegister(MachineHealthCheckNodesCovered)
metrics.Registry.MustRegister(
MachineHealthCheckNodesCovered,
MachineHealthCheckRemediationSuccessTotal,
)
}

func DeleteMachineHealthCheckNodesCovered(name string, namespace string) {
Expand All @@ -51,3 +62,10 @@ func ObserveMachineHealthCheckNodesCovered(name string, namespace string, count
"namespace": namespace,
}).Set(float64(count))
}

func ObserveMachineHealthCheckRemediationSuccess(name string, namespace string) {
MachineHealthCheckRemediationSuccessTotal.With(prometheus.Labels{
"name": name,
"namespace": namespace,
}).Inc()
}