Skip to content

Prometheus metrics

[!NOTE]
This documentation applies to mariadb-operator version >= v0.0.24

mariadb-operator is able to provision MariaDB instances and automatically configure Prometheus to scrape their metrics so they can be used later on to build Grafana dashboards or trigger Alertmanager alerts.

Table of contents

Operator metrics

In order to expose the operator internal metrics, please refer to the recommended installation flavour.

Exporter

The operator configures a prometheus/mysqld-exporter exporter to query MariaDB and export the metrics in Prometheus format via an http endpoint.

It is important to note that, we run this exporter as an standalone Deployment and not as a sidecar alongside every MariaDB replica. This implies that the MariaDB lifecycle is not coupled to the exporter one, so we can upgrade them independently without affecting the availability of the other.

For being able to do this, we rely on the multi-target feature introduced in the v0.15.0 of prometheus/mysqld-exporter, so make sure to specify at least v0.15.0 in the exporter image.

ServiceMonitor

Once the exporter Deployment is ready, mariadb-operator creates a ServiceMonitor object that will be eventually reconciled by the Prometheus operator , resulting in the Prometheus instance being configured to scrape the exporter endpoint.

As you scale your MariaDB with more or less replicas, mariadb-operator will reconcile the ServiceMonitor to add/remove targets related to the MariaDB instances.

Configuration

The easiest way to setup metrics in your MariaDB instance is just by setting spec.metrics.enabled = true, like in this example:

apiVersion: k8s.mariadb.com/v1alpha1
kind: MariaDB
metadata:
  name: mariadb
spec:
...
  metrics:
    enabled: true

The rest of the fields are defaulted by the operator. If you need a more fine grained configuration, refer to the API reference and take a look at this example:

apiVersion: k8s.mariadb.com/v1alpha1
kind: MariaDB
metadata:
  name: mariadb
spec:
...
  metrics:
    enabled: true
    exporter:
      image: prom/mysqld-exporter:v0.15.1
      resources:
        requests:
          cpu: 50m
          memory: 64Mi
        limits:
          cpu: 300m
          memory: 512Mi
      port: 9104
    serviceMonitor:
      prometheusRelease: kube-prometheus-stack
      jobLabel: mariadb-monitoring
      interval: 10s
      scrapeTimeout: 10s
    username: monitoring
    passwordSecretKeyRef:
      name: mariadb
      key: password

Prometheus reference installation

The easiest way to spin up a Prometheus observability stack in Kubernetes is by installing the kube-prometheus-stack helm chart.

We leverage this chart in our local development environment and we have configured it to ensure quality interactions between mariadb-operator and Prometheus. Feel free to install it by running:

make cluster
make install-prometheus

Grafana dashboards

To visualize MariaDB metrics, our Prometheus reference installation has some interesting Grafana dashboards configured that make use of the metrics configured by mariadb-operator. They are all available on grafana.com:

MySQL Overview

MySQL Exporter Quickstart and Dashboard

MySQL Replication

Galera/MariaDB - Overview

Reference