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

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

= Custom resource monitoring

[role="_abstract"]
Use kube-state-metrics to provide custom resource monitoring.
link:https://github.com/kubernetes/kube-state-metrics/[Kube-state-metrics^](KSM) is a scalable Kubernetes native service which listens to the Kubernetes API server and generates metrics about the state of the objects.
Strimzi supports monitoring through KSM for the following custom resources: `KafkaUser` and `KafkaTopic`.

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` resources:
+
* `examples/metrics/kube-state-metrics/prometheus-rules.yaml`
