:_mod-docs-content-type: PROCEDURE

// This assembly is included in the following assemblies:
//
// metrics/assembly_metrics-custom-resource-monitoring.adoc

[id='proc-metrics-custom-resource-monitoring-{context}']

= Monitoring custom resources with kube-state-metrics

[role="_abstract"]
Use kube-state-metrics (KSM) to monitor the state and readiness of custom resources managed by Strimzi.
link:https://github.com/kubernetes/kube-state-metrics/[KSM^] is a scalable Kubernetes native service that listens to the Kubernetes API server and exports metrics about the state of the objects.
Monitoring through KSM allows you to track the health of Strimzi components, identify resources that are not ready, and configure alerts for warning conditions.

You can use your own KSM deployment or deploy KSM using the xref:assembly-metrics-config-files-{context}[example metrics configuration files] provided by Strimzi.
The example files include a configuration file for a KSM deployment:

* `examples/metrics/kube-state-metrics/ksm.yaml`

If you are using the example deployment file, you can update the namespace by replacing the example `myproject` with your own:

On Linux, use:

[source,shell,subs="+quotes,attributes+"]
sed -E -i '/[[:space:]]\*namespace: [a-zA-Z0-9-]*$/s/namespace:[[:space:]]\*[a-zA-Z0-9-]*$/namespace: _myproject_/' examples/metrics/kube-state-metrics/ksm.yaml

On MacOS, use:

[source,shell,subs="+quotes,attributes+"]
sed -i '' -e '/[[:space:]]\*namespace: [a-zA-Z0-9-]*$/s/namespace:[[:space:]]\*[a-zA-Z0-9-]*$/namespace: _myproject_/' examples/metrics/kube-state-metrics/ksm.yaml

Strimzi also provides an xref:assembly-metrics-config-files-{context}[example configuration `ConfigMap` for KSM]:

* `examples/metrics/kube-state-metrics/configmap.yaml`

This procedure uses the example KSM deployment and configuration file.

.Prerequisites
* xref:assembly-metrics-prometheus-{context}[Prometheus and Prometheus Alertmanager are deployed]

.Procedure

. Deploy KSM:
+
[source,shell,subs="+quotes,attributes"]
kubectl apply -f configmap.yaml
kubectl apply -f ksm.yaml

. Verify that Prometheus is scraping KSM metrics.
+
Metrics are scraped from the `strimzi-kube-state-metrics` service using the `ServiceMonitor` configured for the KSM deployment.
+
For alerting on these metrics, check the provided `PrometheusRule` resource:
+
* `examples/metrics/kube-state-metrics/prometheus-rules.yaml`
