:_mod-docs-content-type: REFERENCE

// Module included in the following assemblies:
//
// assembly-deploying.adoc

[id='ref-metrics-options-{context}']
= Enabling a metrics provider

[role="_abstract"]
Configure the console deployment to enable a metrics provider. 
You can set up configuration to use one of the following sources to scrape metrics from Kafka clusters using Prometheus:

OpenShift's built-in user workload monitoring::
Use OpenShift's workload monitoring, incorporating the Prometheus operator, to monitor console services and workloads without the need for an additional monitoring solution.
A standalone Prometheus instance::
Provide the details and credentials to connect with your own Prometheus instance.
An embedded Prometheus instance (default):: 
Deploy a private Prometheus instance for use only by the console instance. 
The instance is configured to retrieve metrics from all Strimzi managed Kafka instances in the same Kubernetes cluster. 
Using embedded metrics is intended for development and evaluation only, not production.

Example configuration for OpenShift monitoring and a standalone Prometheus instance is provided in the following files: 

* `examples/console/console-openshift-metrics.yaml`
* `examples/console/console-standalone-prometheus.yaml`

You can define Prometheus sources globally as part of the console configuration using `metricsSources` properties:

`metricsSources`:: Declares one or more metrics providers that the console can use to collect metrics.
`type`:: Specifies the type of metrics source. Valid options:
  - `openshift-monitoring`
  - `standalone` (external Prometheus)
  - `embedded` (console-managed Prometheus)
`url`:: For `standalone` sources, specifies the base URL of the Prometheus instance.
`authentication`:: (For `standalone` and `openshift-monitoring` only) Configures access to the metrics provider using `basic`, `bearer` token, or `oidc` authentication.
`trustStore`:: (Optional, for `standalone` only) Specifies a truststore for verifying TLS certificates when connecting to the metrics provider. 
Supported formats: `JKS`, `PEM`, `PKCS12`. 
Content may be provided using a `ConfigMap` or a `Secret`.

Assign the metrics source to a Kafka cluster using the `kafkaClusters.metricsSource` property.
The value of `metricsSource` is the `name` of the entry in the `metricsSources` array.

The configuration for `openshift-monitoring` and `embedded` requires no further configuration besides the `type`. 

.Example metrics configuration for Openshift monitoring
[source,yaml]
----
apiVersion: console.streamshub.github.com/v1alpha1
kind: Console
metadata:
  name: my-console
spec:
  hostname: my-console.<cluster_domain>
  # ...
  metricsSources:
    - name: my-ocp-prometheus
      type: openshift-monitoring
  kafkaClusters:
    - name: console-kafka
      namespace: kafka
      listener: secure  
      metricsSource: my-ocp-prometheus                  
      credentials:
        kafkaUser:
          name: console-kafka-user1
  # ...        
----

.Example metrics configuration for standalone Prometheus monitoring
[source,yaml]
----
apiVersion: console.streamshub.github.com/v1alpha1
kind: Console
metadata:
  name: my-console
spec:
  hostname: my-console.<cluster_domain>
  # ...
  metricsSources:
    - name: my-custom-prometheus
      type: standalone
      url: <prometheus_instance_address>
      authentication:
        basic:
          username: my-user
          password: my-password
      trustStore:
        type: JKS
        content:
          valueFrom:
            configMapKeyRef:
              name: my-prometheus-configmap
              key: ca.jks
        password:
          value: truststore-password
  kafkaClusters:
    - name: console-kafka
      namespace: kafka
      listener: secure
      metricsSource: my-ocp-prometheus
      credentials:
        kafkaUser:
          name: console-kafka-user1
  # ...
----

* `metricsSources.name` defines a unique name for the metrics source.
* `metricsSources.type` specifies the type of metrics source. Use `standalone` for an external Prometheus instance.
* `metricsSources.url` specifies the URL of the standalone Prometheus instance used for metrics collection.
* `metricsSources.authentication` defines the authentication configuration used to access the Prometheus instance.
** `basic` specifies basic authentication and requires a `username` and `password`.
** `bearer` specifies bearer token authentication and requires a `token`.
** `oidc` specifies OpenID Connect authentication. For details, see xref:ref-authentication-options-{context}[Using an OIDC provider to secure access to Kafka clusters].
* `metricsSources.trustStore` optionally defines a truststore used to validate the metrics provider TLS certificate. Supported formats include `JKS`, `PEM`, and `PKCS12`. Truststore content can be provided by using either a ConfigMap or a Secret.
* `metricsSources.trustStore.password` optionally specifies the truststore password. The password can be provided as a plaintext value or via a Secret. Plaintext values are not recommended for production environments.
* `kafkaClusters.metricsSource` associates the Kafka cluster with the configured metrics source.
