Monitor MySQL

From the Introduction section, you know it is not feasible to instrument MySQL with Prometheus metrics directly. To expose MySQL metrics in Prometheus format, you need to deploy MySQL exporter instead.

This tutorial walks you through an example of how to monitor MySQL metrics and visualize them.

Prerequisites

  • Please make sure you enable the OpenPitrix system. MySQL and MySQL exporter will be deployed from the App Store.
  • You need to create a workspace, a project, and a user account for this tutorial. For more information, see Create Workspace, Project, Account and Role. The account needs to be a platform regular user and to be invited as the project operator with the operator role. In this tutorial, you log in as project-operator and work in the project demo in the workspace demo-workspace.

Hands-on Lab

Step 1: Deploy MySQL

To begin with, you deploy MySQL from the App Store and set the root password to testing. Please make sure you are landing on the Overview page of the project demo.

  1. Go to App Store.

go-to-app-store

  1. Find MySQL and click Deploy.

find-mysql

click-deploy

  1. Make sure MySQL is deployed in demo and click Next.

click-next

  1. Uncomment the mysqlRootPassword field and click Deploy.

uncomment-mysqlRootPassword

  1. Wait until MySQL is up and running.

check-if-mysql-is-running

Step 2: Deploy MySQL exporter

You need to deploy MySQL exporter in demo on the same cluster. MySQL exporter is responsible for querying MySQL status and reports the data in Prometheus format.

  1. Go to App Store and find MySQL exporter.

find-mysql-exporter

exporter-click-deploy

  1. Deploy MySQL exporter in demo again.

exporter-click-next

  1. Make sure serviceMonitor.enabled is set to true. The built-in MySQL exporter sets it to true by default, so you don’t have to manually modify serviceMonitor.enabled.

set-servicemonitor-to-true

Warning

Don’t forget to enable the SericeMonitor CRD if you are using external exporter helm charts. Those charts usually disable ServiceMonitor by default and require manual modification.

  1. Modify MySQL connection parameters. MySQL exporter needs to connect to the target MySQL. In this tutorial, MySQL is installed with the service name mysql-a8xgvx. Set mysql.host to mysql-a8xgvx, mysql.pass to testing, and user to root as below. Note that your MySQL service may be created with a different name.

mysql-conn-params

  1. Click Deploy and wait until MySQL exporter is up and running.

exporter-click-deploy-2

exporter-is-running

Step 3: Create Dashboard

After about two minutes, you can create a monitoring dashboard for MySQL and visualize metrics in real time.

  1. Navigate to Custom Monitoring under Monitoring & Alerting and click Create.

navigate-to-custom-monitoring

  1. In the dialogue that appears, name the dashboard as mysql-overview and choose MySQL template. Click Create to continue.

create-mysql-dashboard

  1. Save the template by clicking Save Template in the top right corner. A newly-created dashboard displays in the dashboard list as below.

save-mysql-template

monitor-mysql-done

Tip

For more information about dashboard strings, see Visualization.