|
| 1 | +This documentation is intended to guide you how to enable custom monitoring on operator installed Kafka cluster |
| 2 | + |
| 3 | +#### Using Helm for Prometheus: |
| 4 | + |
| 5 | +By default operator installs Kafka Pods with the following annotations, also it opens port 9020 in all brokers to enable scraping. |
| 6 | + |
| 7 | +``` |
| 8 | + "prometheus.io/scrape": "true" |
| 9 | + "prometheus.io/port": "9020" |
| 10 | +``` |
| 11 | + |
| 12 | +Prometheus must be configured to recognize these annotations. The following example contains the required config. |
| 13 | + |
| 14 | +``` |
| 15 | +# Example scrape config for pods |
| 16 | +# |
| 17 | +# The relabeling allows the actual pod scrape endpoint to be configured via the |
| 18 | +# following annotations: |
| 19 | +# |
| 20 | +# * `prometheus.io/scrape`: Only scrape pods that have a value of `true` |
| 21 | +# * `prometheus.io/path`: If the metrics path is not `/metrics` override this. |
| 22 | +# * `prometheus.io/port`: Scrape the pod on the indicated port instead of the default of `9102`. |
| 23 | +- job_name: 'kubernetes-pods' |
| 24 | +
|
| 25 | + kubernetes_sd_configs: |
| 26 | + - role: pod |
| 27 | +
|
| 28 | + relabel_configs: |
| 29 | + - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape] |
| 30 | + action: keep |
| 31 | + regex: true |
| 32 | + - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path] |
| 33 | + action: replace |
| 34 | + target_label: __metrics_path__ |
| 35 | + regex: (.+) |
| 36 | + - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port] |
| 37 | + action: replace |
| 38 | + regex: ([^:]+)(?::\d+)?;(\d+) |
| 39 | + replacement: $1:$2 |
| 40 | + target_label: __address__ |
| 41 | +``` |
| 42 | + |
| 43 | +Using the provided [CR](https://github.com/banzaicloud/kafka-operator/blob/master/config/samples/banzaicloud_v1alpha1_kafkacluster.yaml), the operator installs the official [jmx exporter](https://github.com/prometheus/jmx_exporter) for Prometheus. |
| 44 | + |
| 45 | +To change this behavior please modify the following lines in the end of the CR. |
| 46 | + |
| 47 | +``` |
| 48 | +monitoringConfig: |
| 49 | + jmxImage describes the used prometheus jmx exporter agent container |
| 50 | + jmxImage: "banzaicloud/jmx-javaagent:0.12.0" |
| 51 | + pathToJar describes the path to the jar file in the given image |
| 52 | + pathToJar: "/opt/jmx_exporter/jmx_prometheus_javaagent-0.12.0.jar" |
| 53 | + kafkaJMXExporterConfig describes jmx exporter config for Kafka |
| 54 | + kafkaJMXExporterConfig: | |
| 55 | + lowercaseOutputName: true |
| 56 | +``` |
| 57 | + |
| 58 | +#### Using the ServiceMonitors: |
| 59 | + |
| 60 | +To use ServiceMonitors, we recommend to use kafka with unique service/broker instead of headless service. |
| 61 | + |
| 62 | +Configure the CR in a following way: |
| 63 | + |
| 64 | +``` |
| 65 | + # Specify if the cluster should use headlessService for Kafka or individual services |
| 66 | + # using service/broker may come in handy in case of service mesh |
| 67 | + headlessServiceEnabled: false |
| 68 | +``` |
| 69 | + |
| 70 | +Disabling Headless service means the operator will set up Kafka with unique services per broker. |
| 71 | + |
| 72 | +Once you have a cluster up and running create as many ServiceMonitors as brokers. |
| 73 | + |
| 74 | +``` |
| 75 | +apiVersion: monitoring.coreos.com/v1 |
| 76 | +kind: ServiceMonitor |
| 77 | +metadata: |
| 78 | + name: kafka-0 |
| 79 | +spec: |
| 80 | + selector: |
| 81 | + matchLabels: |
| 82 | + app: kafka |
| 83 | + brokerId: "0" |
| 84 | + kafka_cr: kafka |
| 85 | + endpoints: |
| 86 | + - port: metrics |
| 87 | + interval: 10s |
| 88 | +``` |
0 commit comments