<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>MySQL Server Exporter on Grafana Labs</title><link>https://grafana.com/oss/prometheus/exporters/mysql-exporter/</link><description>Recent content in MySQL Server Exporter on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/oss/prometheus/exporters/mysql-exporter/index.xml" rel="self" type="application/rss+xml"/><item><title>Alerting rules</title><link>https://grafana.com</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://grafana.com</guid><description>&lt;p>This quickstart includes the following alerting rules:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;code>MySQLDown&lt;/code>&lt;/p>
&lt;p>MySQL [job] on [instance] is not up.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;code>MySQLGaleraNotReady&lt;/code>&lt;/p>
&lt;p>[job] on [instance] is not ready.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;code>MySQLGaleraOutOfSync&lt;/code>&lt;/p>
&lt;p>[job] on [instance] is not in sync.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;code>MySQLGaleraDonorFallingBehind&lt;/code>&lt;/p>
&lt;p>[job] on [instance] is a donor (hotbackup) and is falling behind (queue size [value]).&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;code>MySQLReplicationNotRunning&lt;/code>&lt;/p>
&lt;p>Slave replication (IO or SQL) has been down for more than 2 minutes.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;code>MySQLReplicationLag&lt;/code>&lt;/p>
&lt;p>The mysql slave replication has fallen behind and is not recovering.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;code>MySQLInnoDBLogWaits&lt;/code>&lt;/p>
&lt;p>The innodb logs are waiting for disk at a rate of [value] / second.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;a class="btn btn--primary br-5 mb-1" href="assets/alerting_rules.yaml" rel="noopener noreferrer">Download the following alerting rules YAML file&lt;/a>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">###
# Sample prometheus rules/alerts for mysqld.
#
# NOTE: Please review these carefully as thresholds and behavior may not meet
# your SLOs or labels.
#
###
groups:
- name: MySQLdAlerts
rules:
- alert: MySQLDown
annotations:
description: MySQL {{$labels.job}} on {{$labels.instance}} is not up.
summary: MySQL not up
expr: mysql_up != 1
for: 5m
labels:
severity: critical
- name: GaleraAlerts
rules:
- alert: MySQLGaleraNotReady
annotations:
description: &amp;#39;{{$labels.job}} on {{$labels.instance}} is not ready.&amp;#39;
summary: Galera cluster node not ready
expr: mysql_global_status_wsrep_ready != 1
for: 5m
labels:
severity: warning
- alert: MySQLGaleraOutOfSync
annotations:
description: &amp;#39;{{$labels.job}} on {{$labels.instance}} is not in sync ({{$value}} != 4).&amp;#39;
summary: Galera cluster node out of sync
expr: (mysql_global_status_wsrep_local_state != 4 and mysql_global_variables_wsrep_desync == 0)
for: 5m
labels:
severity: warning
- alert: MySQLGaleraDonorFallingBehind
annotations:
description: &amp;#39;{{$labels.job}} on {{$labels.instance}} is a donor (hotbackup) and is falling behind (queue size {{$value}}).&amp;#39;
summary: xtradb cluster donor node falling behind
expr: (mysql_global_status_wsrep_local_state == 2 and mysql_global_status_wsrep_local_recv_queue &amp;gt; 100)
for: 5m
labels:
severity: warning
- alert: MySQLReplicationNotRunning
annotations:
description: Slave replication (IO or SQL) has been down for more than 2 minutes.
summary: Slave replication is not running
expr: mysql_slave_status_slave_io_running == 0 or mysql_slave_status_slave_sql_running == 0
for: 2m
labels:
severity: critical
- alert: MySQLReplicationLag
annotations:
description: The mysql slave replication has fallen behind and is not recovering
summary: MySQL slave replication is lagging
expr: (instance:mysql_slave_lag_seconds &amp;gt; 30) and on(instance) (predict_linear(instance:mysql_slave_lag_seconds[5m], 60 * 2) &amp;gt; 0)
for: 1m
labels:
severity: critical
- alert: MySQLReplicationLag
annotations:
description: The mysql slave replication has fallen behind and is not recovering
summary: MySQL slave replication is lagging
expr: (instance:mysql_heartbeat_lag_seconds &amp;gt; 30) and on(instance) (predict_linear(instance:mysql_heartbeat_lag_seconds[5m], 60 * 2) &amp;gt; 0)
for: 1m
labels:
severity: critical
- alert: MySQLInnoDBLogWaits
annotations:
description: The innodb logs are waiting for disk at a rate of {{$value}} / second
summary: MySQL innodb log writes stalling
expr: rate(mysql_global_status_innodb_log_waits[15m]) &amp;gt; 10
labels:
severity: warning&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>This alerting rule YAML file was generated using the MySQL Exporter &lt;a href="https://github.com/prometheus/mysqld_exporter/tree/master/mysqld-mixin" target="_blank" rel="noopener noreferrer">mixin&lt;/a>.&lt;/p></description></item><item><title>Cloud integration</title><link>https://grafana.com</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://grafana.com</guid><description>
&lt;div class="bg-solitude p-1 mb-1" style="">
&lt;p>Grafana Cloud comes with an ever-expanding set of integrations to quickly get an observability stack up and running in minutes. The MySQL Integration, built-in to the Grafana Cloud Agent, exposes and scrapes essential MySQL metrics and pushes them to Grafana Cloud. The agent will scrape metrics using an embedded MySQL Exporter, and Grafana Cloud will automatically provision tailored Grafana dashboards and alerts for visualizing and acting on this data.&lt;/p>
&lt;div>
&lt;a class="btn btn--primary br-5 " href="/auth/sign-up/create-user?pg=oss-prom-mysql-exporter&amp;amp;plcmt=body-txt-overview" rel="noopener noreferrer">Sign up for a free account to get started&lt;/a>
&lt;/div>
&lt;/div>
&lt;p>To learn more, check out the &lt;a href="/docs/grafana-cloud/integrations/">Grafana Cloud docs&lt;/a>.&lt;/p>
&lt;h3 id="how-it-works">How it works&lt;/h3>
&lt;p>Configuring, installing, connecting, and maintaining Prometheus monitoring components typically involves significant domain knowledge. It can take quite a while to go from setup to dashboard and alerts. As the creators of Grafana - and core contributors to Prometheus and Cortex - we build simple integrations to abstract some of this work away in order to quickly get started. How it works:&lt;/p>
&lt;ol>
&lt;li>Sign up (or log in) for a &lt;a href="/auth/sign-up/create-user?pg=oss-prom-mysql-exporter&amp;amp;plcmt=body-txt-integration">free Grafana Cloud account&lt;/a>.&lt;/li>
&lt;li>Select the target you’d like to observe (an ever-expanding catalogue).&lt;/li>
&lt;li>Run a one-line command to install the Grafana Cloud Agent. The agent embeds and preconfigures Exporters to expose default metrics, and pushes them to the Grafana Cloud metrics backend.&lt;/li>
&lt;li>Voila! You’ll see tailored Grafana dashboards and will benefit from sane alerting defaults.&lt;/li>
&lt;/ol>
&lt;p>Looking for a different Exporter or integration? Check out our &lt;a href="/docs/grafana-cloud/integrations/">growing library of integrations for popular components&lt;/a> like MySQL, Postgres, Redis, Memcached and more.&lt;/p></description></item><item><title>Dashboards</title><link>https://grafana.com</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://grafana.com</guid><description>&lt;p>&lt;strong>Note: These dashboards may depend on the recording rules in the previous tab. Be sure to import these before importing the dashboards.&lt;/strong>&lt;/p>
&lt;h3 id="mysql-overview-dashboard">MySQL Overview Dashboard&lt;/h3>
&lt;p>&lt;img
class="lazyload d-inline-block"
src="/api/dashboards/14057/images/10051/image"
alt="MySQL Overview Dashboard"/>&lt;/p>
&lt;p>This dashboard includes panels for the following metrics:&lt;/p>
&lt;ul>
&lt;li>Uptime&lt;/li>
&lt;li>Current QPS&lt;/li>
&lt;li>InnoDB Buffer Pool&lt;/li>
&lt;li>MySQL Connections&lt;/li>
&lt;li>MySQL Client Thread Activity&lt;/li>
&lt;li>MySQL Questions&lt;/li>
&lt;li>MySQL Thread Cache&lt;/li>
&lt;li>MySQL Temporary Objects&lt;/li>
&lt;li>MySQL Select Types&lt;/li>
&lt;li>MySQL Sorts&lt;/li>
&lt;li>MySQL Slow Queries&lt;/li>
&lt;li>MySQL Aborted Connections&lt;/li>
&lt;li>MySQL Table Locks&lt;/li>
&lt;li>MySQL Network Traffic&lt;/li>
&lt;li>MySQL Internal Memory Overview&lt;/li>
&lt;li>Top Command Counters&lt;/li>
&lt;li>MySQL Handlers&lt;/li>
&lt;li>MySQL Transaction Handlers&lt;/li>
&lt;li>Process States&lt;/li>
&lt;li>Top Process States Hourly&lt;/li>
&lt;li>MySQL Query Cache Memory&lt;/li>
&lt;li>MySQL Query Cache Activity&lt;/li>
&lt;li>MySQL File Openings&lt;/li>
&lt;li>MySQL Open Files&lt;/li>
&lt;li>MySQL Table Open Cache Status&lt;/li>
&lt;li>MySQL Open Tables&lt;/li>
&lt;li>MySQL Table Definition Cache&lt;/li>
&lt;/ul>
&lt;p>You can import the dashboard directly using the following dashboard ID: &lt;strong>&lt;code>14057&lt;/code>&lt;/strong>.&lt;/p>
&lt;p>You can fetch the dashboard JSON &lt;a href="/api/dashboards/14057/revisions/1/download">&lt;strong>here&lt;/strong>&lt;/a>.&lt;/p>
&lt;p>This dashboard was generated using the MySQL exporter &lt;a href="https://github.com/prometheus/mysqld_exporter/tree/master/mysqld-mixin" target="_blank" rel="noopener noreferrer">mixin&lt;/a>.&lt;/p></description></item><item><title>Install</title><link>https://grafana.com</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://grafana.com</guid><description>&lt;h2 id="mysql-exporter-quickstart">MySQL Exporter Quickstart&lt;/h2>
&lt;p>In this guide you&amp;rsquo;ll learn how to set up and configure the MySQL Server Exporter to collect MySQL metrics like queries per second (QPS) and InnoDB buffer pool size, and expose them as Prometheus-style metrics. You&amp;rsquo;ll then configure &lt;a href="https://prometheus.io/" target="_blank" rel="noopener noreferrer">Prometheus&lt;/a> to scrape MySQL metrics and optionally ship them to Grafana Cloud. Finally, you&amp;rsquo;ll set up a preconfigured and curated set of &lt;a href="https://prometheus.io/docs/prometheus/latest/configuration/recording_rules/" target="_blank" rel="noopener noreferrer">recording rules&lt;/a>, Grafana &lt;a href="/grafana/dashboards">dashboards&lt;/a>, and &lt;a href="https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/" target="_blank" rel="noopener noreferrer">alerting rules&lt;/a>. At the end of this guide you&amp;rsquo;ll have dashboards that you can use to visualize your MySQL Server metrics, and set of preconfigured alerts.&lt;/p>
&lt;p>If you&amp;rsquo;re using &lt;a href="/products/cloud/">Grafana Cloud&lt;/a>, the &lt;a href="/docs/grafana-cloud/integrations/integration-mysql/">MySQL&lt;/a> Integration can help you get up and running quickly. The MySQL Integration embeds the MySQL exporter into the &lt;a href="https://github.com/grafana/agent" target="_blank" rel="noopener noreferrer">Grafana Cloud Agent&lt;/a> and automatically provisions alerting rules and dashboards, so you don&amp;rsquo;t have to run through the steps in this guide. To learn how to set up Node Exporter using the MySQL Integration, please see &lt;a href="/docs/grafana-cloud/integrations/integration-mysql/">MySQL Integration&lt;/a> from the Grafana Cloud docs.&lt;/p>
&lt;h2 id="prerequisites">Prerequisites&lt;/h2>
&lt;p>Before you get started, you should have the following available to you:&lt;/p>
&lt;ul>
&lt;li>A machine compatible with a MySQL Server Exporter release. To see a list of available releases, please see &lt;a href="https://github.com/prometheus/mysqld_exporter/releases/" target="_blank" rel="noopener noreferrer">Releases&lt;/a>.&lt;/li>
&lt;li>MySQL running on your machine. To learn more about installing and running MySQL, please see the &lt;a href="https://dev.mysql.com/doc/mysql-installation-excerpt/8.0/en/" target="_blank" rel="noopener noreferrer">MySQL Installation Guide&lt;/a>.&lt;/li>
&lt;li>Prometheus running in your environment or directly on the machine. To learn how to install Prometheus, please see &lt;a href="https://prometheus.io/docs/prometheus/latest/installation/" target="_blank" rel="noopener noreferrer">Installation&lt;/a> from the Prometheus docs.&lt;/li>
&lt;li>Grafana running in your environment or directly on the machine. To learn how to install Grafana, please see &lt;a href="/docs/grafana/latest/installation/">Install Grafana&lt;/a> from the Grafana docs.&lt;/li>
&lt;li>(Optional) A Grafana Cloud account. Grafana Cloud hosts Grafana and a &lt;a href="/oss/mimir/">Mimir&lt;/a>-based Prometheus metrics endpoint. You will still need to scrape metrics, using either Prometheus installed in your environment, or the &lt;a href="https://github.com/grafana/agent" target="_blank" rel="noopener noreferrer">Grafana Cloud Agent&lt;/a>. To learn more about Grafana Cloud, please see &lt;a href="/products/cloud/">Grafana Cloud&lt;/a>.&lt;/li>
&lt;/ul>
&lt;h2 id="step-1-setting-up-the-mysql-server-exporter">Step 1: Setting up the MySQL Server Exporter&lt;/h2>
&lt;p>In this step you&amp;rsquo;ll set up the MySQL Server exporter on your machine to collect and expose MySQL metrics in Prometheus format. This guide uses an Ubuntu 20.04 system with MySQL 8.0.23. Steps may vary slightly depending on your operating system and MySQL version.&lt;/p>
&lt;p>To begin, log in to your machine and download the relevant MySQL Exporter binary. This guide uses the &lt;code>linux-amd64&lt;/code> binary but you should choose the one corresponding to your system&amp;rsquo;s OS and architecture:&lt;/p>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>Replace &lt;code>v0.12.1.linux-amd64&lt;/code> with the version you&amp;rsquo;d like to install. This guide may become stale so it&amp;rsquo;s best to check the MySQL Exporter &lt;a href="https://github.com/prometheus/mysqld_exporter/releases/" target="_blank" rel="noopener noreferrer">Releases&lt;/a> page for the latest stable version.&lt;/p>
&lt;p>Unzip the tarball and &lt;code>cd &lt;/code> into the directory:&lt;/p>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">tar xvfz mysqld_exporter-*.*-amd64.tar.gz
cd mysqld_exporter-*.*-amd64&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>Before you run the MySQL exporter, you first need to create the MySQL user that it&amp;rsquo;ll use to fetch database metrics. Log in to your MySQL database and run the following command as a user with administrative privileges:&lt;/p>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">CREATE USER &amp;#39;exporter&amp;#39;@&amp;#39;localhost&amp;#39; IDENTIFIED BY &amp;#39;enter_password_here&amp;#39; WITH MAX_USER_CONNECTIONS 3;&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">Query OK, 0 rows affected (0.03 sec)&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;blockquote>
&lt;p>&lt;strong>Note:&lt;/strong> It&amp;rsquo;s recommended to set a maximum connection limit for the exporter user to avoid overloading the server with monitoring scrapes under heavy load. This is not supported on all MySQL/MariaDB versions; for example, MariaDB 10.1 (provided with Ubuntu 18.04) &lt;a href="https://mariadb.com/kb/en/library/create-user/#resource-limit-options" target="_blank" rel="noopener noreferrer">does &lt;em>not&lt;/em> support this feature&lt;/a>.&lt;/p>&lt;/blockquote>
&lt;p>Next, grant this new user the appropriate permissions to fetch database metrics:&lt;/p>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO &amp;#39;exporter&amp;#39;@&amp;#39;localhost&amp;#39;;&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">Query OK, 0 rows affected (0.02 sec)&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>Now that you&amp;rsquo;ve created the exporter MySQL user, you&amp;rsquo;re ready to test the exporter.&lt;/p>
&lt;p>Set the following environment variable:&lt;/p>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">export DATA_SOURCE_NAME=&amp;#39;exporter:enter_password_here@(mysql_hostname:3306)/&amp;#39;&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>Be sure to replace &lt;code>exporter&lt;/code> with the user you created above, &lt;code>enter_password_here&lt;/code> with the password you defined, and &lt;code>mysql_hostname&lt;/code> with the hostname of the MySQL instance (&lt;code>localhost&lt;/code> if you&amp;rsquo;re on the same machine).&lt;/p>
&lt;p>Finally, run the exporter:&lt;/p>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">./mysqld_exporter&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">INFO[0000] Starting mysqld_exporter (version=0.12.1, branch=HEAD, revision=48667bf7c3b438b5e93b259f3d17b70a7c9aff96) source=&amp;#34;mysqld_exporter.go:257&amp;#34;
INFO[0000] Build context (go=go1.12.7, user=root@0b3e56a7bc0a, date=20190729-12:35:58) source=&amp;#34;mysqld_exporter.go:258&amp;#34;
INFO[0000] Enabled scrapers: source=&amp;#34;mysqld_exporter.go:269&amp;#34;
INFO[0000] --collect.slave_status source=&amp;#34;mysqld_exporter.go:273&amp;#34;
INFO[0000] --collect.global_status source=&amp;#34;mysqld_exporter.go:273&amp;#34;
INFO[0000] --collect.global_variables source=&amp;#34;mysqld_exporter.go:273&amp;#34;
INFO[0000] --collect.info_schema.query_response_time source=&amp;#34;mysqld_exporter.go:273&amp;#34;
INFO[0000] --collect.info_schema.innodb_cmp source=&amp;#34;mysqld_exporter.go:273&amp;#34;
INFO[0000] --collect.info_schema.innodb_cmpmem source=&amp;#34;mysqld_exporter.go:273&amp;#34;
INFO[0000] Listening on :9104 source=&amp;#34;mysqld_exporter.go:283&amp;#34;&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>If you see the above output, you successfully ran the MySQL Server exporter.&lt;/p>
&lt;p>MySQL Exporter publishes MySQL metrics in Prometheus format on port &lt;code>9104&lt;/code>. You can test this using &lt;code>curl&lt;/code>. You will need to open a new SSH session or background the MySQL Exporter process to use &lt;code>curl&lt;/code>.&lt;/p>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">curl http://localhost:9104/metrics&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">. . .
process_resident_memory_bytes 1.2079104e&amp;#43;07
# HELP process_start_time_seconds Start time of the process since unix epoch in seconds.
# TYPE process_start_time_seconds gauge
process_start_time_seconds 1.61377616023e&amp;#43;09
# HELP process_virtual_memory_bytes Virtual memory size in bytes.
# TYPE process_virtual_memory_bytes gauge
process_virtual_memory_bytes 1.16355072e&amp;#43;08
# HELP process_virtual_memory_max_bytes Maximum amount of virtual memory available in bytes.
# TYPE process_virtual_memory_max_bytes gauge
process_virtual_memory_max_bytes -1
# HELP promhttp_metric_handler_requests_in_flight Current number of scrapes being served.
# TYPE promhttp_metric_handler_requests_in_flight gauge
promhttp_metric_handler_requests_in_flight 1
# HELP promhttp_metric_handler_requests_total Total number of scrapes by HTTP status code.
# TYPE promhttp_metric_handler_requests_total counter
promhttp_metric_handler_requests_total{code=&amp;#34;200&amp;#34;} 1
promhttp_metric_handler_requests_total{code=&amp;#34;500&amp;#34;} 0
promhttp_metric_handler_requests_total{code=&amp;#34;503&amp;#34;} 0&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>If you see the above output, you&amp;rsquo;re ready to begin scraping MySQL metrics using Prometheus.&lt;/p>
&lt;p>To avoid running and managing MySQL Exporter from the command line, you can create a &lt;code>systemd&lt;/code> service. To learn how to do this, please see &lt;a href="/docs/grafana-cloud/agent/agent_as_service/">Creating a systemd service to manage the agent&lt;/a>. Replace the path to the agent binary with the path to MySQL Exporter.&lt;/p>
&lt;p>You can use a &lt;code>my.cnf&lt;/code> file to set the username and password the MySQL Exporter will use. In addition, the exporter provides many flags to configure which metrics to scrape and where to publish them. To learn more about these features, please see the &lt;a href="https://github.com/prometheus/mysqld_exporter" target="_blank" rel="noopener noreferrer">MySQL Exporter GitHub repository&lt;/a>.&lt;/p>
&lt;h2 id="step-2-scraping-mysql-exporter-using-prometheus">Step 2: Scraping MySQL Exporter using Prometheus&lt;/h2>
&lt;p>Now that the MySQL Exporter is up and running on your machine, you can configure a Prometheus scrape job to collect and store MySQL Exporter metrics.&lt;/p>
&lt;p>Add the following scrape job config to the &lt;code>scrape_configs&lt;/code> section of your &lt;code>prometheus.yml&lt;/code> configuration file:&lt;/p>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">- job_name: mysql
static_configs:
- targets: [&amp;#39;mysql_exporter_machine_IP_address:9104&amp;#39;]&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>Replace &lt;code>mysql_exporter_machine_IP_address&lt;/code> with the IP address of the machine running MySQL Exporter. If you&amp;rsquo;re running Prometheus on the same machine, this will be &lt;code>localhost&lt;/code>. To learn more about configuring Prometheus, please see &lt;a href="https://prometheus.io/docs/prometheus/latest/configuration/configuration/" target="_blank" rel="noopener noreferrer">Configuration&lt;/a> from the Prometheus docs.&lt;/p>
&lt;p>If you don&amp;rsquo;t have a &lt;code>prometheus.yml&lt;/code> configuration file, create a simple one using your favorite text editor. Open your preferred text editor and paste in the following Prometheus configuration:&lt;/p>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">global:
scrape_interval: 15s
scrape_configs:
- job_name: mysql
static_configs:
- targets: [&amp;#39;mysql_exporter_machine_IP_address:9104&amp;#39;]&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>This configuration tells Prometheus to scrape all jobs every 15 seconds. The only configured scrape job is called &lt;code>mysql&lt;/code> and defines a &lt;code>mysql_exporter_machine_IP_address:9104&lt;/code> target. By default, Prometheus will scrape the &lt;code>/metrics&lt;/code> endpoint using HTTP.&lt;/p>
&lt;p>Save and close the file. You can then run Prometheus with the file using the following command:&lt;/p>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">./prometheus --config.file=./prometheus.yml&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;h3 id="shipping-metrics-to-grafana-cloud">Shipping metrics to Grafana Cloud&lt;/h3>
&lt;p>To ship MySQL Exporter metrics to Grafana Cloud from Prometheus, configure the &lt;code>remote_write&lt;/code> parameter in your &lt;code>prometheus.yml&lt;/code> configuration file. To learn more, please see &lt;a href="/docs/grafana-cloud/metrics/prometheus/">Metrics — Prometheus&lt;/a> from the Grafana Cloud docs. To learn more about the &lt;code>remote_write&lt;/code> parameter, please see &lt;a href="https://prometheus.io/docs/prometheus/latest/configuration/configuration/#remote_write" target="_blank" rel="noopener noreferrer">&lt;code>remote_write&lt;/code>&lt;/a> from the Prometheus docs.&lt;/p>
&lt;h2 id="step-3-configure-recording-rules">Step 3: Configure recording rules&lt;/h2>
&lt;p>Using recording rules, you can precompute and cache frequently queried metrics. For example, if a dashboard panel uses a computationally intensive query like a &lt;code>rate()&lt;/code>, you can create a recording rule that runs at a regular reduced interval and saves the result of the intensive query in a new time series. This avoids fetching and computing data every time the dashboard gets refreshed. To learn more about Prometheus recording rules, please see &lt;a href="https://prometheus.io/docs/prometheus/latest/configuration/recording_rules/" target="_blank" rel="noopener noreferrer">Recording Rules&lt;/a> from the Prometheus docs.&lt;/p>
&lt;p>&lt;strong>You should load the following recording rules before loading the dashboards in this guide.&lt;/strong> The dashboard queries and alerting rules use recording rules to reduce load on the Prometheus or Grafana Cloud Metrics servers, depending on where you&amp;rsquo;re evaluating the rules.&lt;/p>
&lt;p>You can fetch the recording rule YAML file &lt;a href="?tab=recording-rules">here&lt;/a>.&lt;/p>
&lt;p>This recording rule YAML file was generated using the MySQL Exporter &lt;a href="https://github.com/prometheus/mysqld_exporter/tree/master/mysqld-mixin" target="_blank" rel="noopener noreferrer">mixin&lt;/a>.&lt;/p>
&lt;h3 id="load-recording-rules-into-prometheus">Load recording rules into Prometheus&lt;/h3>
&lt;p>To load recording rules into Prometheus, add the following to your &lt;code>prometheus.yml&lt;/code> configuration file:&lt;/p>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">rule_files:
- &amp;#34;mysql_exporter_recording_rules.yml&amp;#34;&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>Be sure to replace &lt;code>mysql_exporter_recording_rules.yml&lt;/code> with the path to your MySQL Exporter recording rules YAML file.&lt;/p>
&lt;h3 id="load-recording-rules-into-grafana-cloud">Load recording rules into Grafana Cloud&lt;/h3>
&lt;p>To learn how to load recording rules into Grafana Cloud, please see &lt;a href="/docs/grafana-cloud/alerts/alerts-rules/#prometheus-and-loki-rules-with-cortextool">Prometheus and Loki rules with cortextool&lt;/a>.&lt;/p>
&lt;h2 id="step-4-configuring-dashboards">Step 4: Configuring dashboards&lt;/h2>
&lt;p>This quickstart includes one dashboard: MySQL Overview.&lt;/p>
&lt;p>To learn how to import this dashboard into Grafana, please see &lt;a href="/docs/grafana/latest/dashboards/export-import/#importing-a-dashboard">Importing a dashboard&lt;/a> from the Grafana docs.&lt;/p>
&lt;p>&lt;strong>The dashboard queries depend on the recording rules defined in the previous step. Be sure to import these before importing the dashboards.&lt;/strong>&lt;/p>
&lt;p>You can fetch the dashboard &lt;a href="?tab=dashboards">here&lt;/a>.&lt;/p>
&lt;h2 id="step-5-configuring-alerts">Step 5: Configuring alerts&lt;/h2>
&lt;p>With Prometheus alerting rules, you can define alerts that fire when PromQL expressions breach some threshold or satisfy specified conditions over a period of time. For example, you can define a &lt;code>HighRequestLatency&lt;/code> alert that fires when a request latency metric is greater than some threshold over a period of time. As soon as the alerting condition is triggered, the alert moves into &lt;code>Pending&lt;/code> state. After satisfying the condition for the period of time defined by the &lt;code>for&lt;/code> parameter, the alert moves into &lt;code>Firing&lt;/code> state. You can configure routing and notifications for firing alerts using a tool like &lt;a href="https://prometheus.io/docs/alerting/latest/alertmanager/" target="_blank" rel="noopener noreferrer">Alertmanager&lt;/a>. Alertmanager is also built-in to Grafana Cloud.&lt;/p>
&lt;p>You can fetch the alerting rule YAML file &lt;a href="?tab=alerting-rules">here&lt;/a>.&lt;/p>
&lt;h3 id="load-alerting-rules-into-prometheus">Load alerting rules into Prometheus&lt;/h3>
&lt;p>To load alerting rules into Prometheus, add the following to your &lt;code>prometheus.yml&lt;/code> configuration file:&lt;/p>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">rule_files:
- &amp;#34;mysql_exporter_alerting_rules.yml&amp;#34;&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>Be sure to replace &lt;code>mysql_exporter_alerting_rules.yml&lt;/code> with the path to your MySQL alerting rules YAML file.&lt;/p>
&lt;h3 id="load-alerting-rules-into-grafana-cloud">Load alerting rules into Grafana Cloud&lt;/h3>
&lt;p>To learn how to load alerting rules into Grafana Cloud, please see &lt;a href="/docs/grafana-cloud/alerts/alerts-rules/#prometheus-and-loki-rules-with-cortextool">Prometheus and Loki rules with cortextool&lt;/a>.&lt;/p>
&lt;h2 id="conclusion">Conclusion&lt;/h2>
&lt;p>In this quickstart you installed and ran MySQL Exporter on your Linux machine. You then configured Prometheus to scrape the database and MySQL cluster metrics exposed by MySQL Exporter. You loaded recording rules and alerting rules into Prometheus, and finally imported Grafana dashboards to visualize your MySQL metrics.&lt;/p>
&lt;p>If you&amp;rsquo;re using Grafana Cloud, you can skip all of the steps in this guide by installing the MySQL integration with the Grafana Cloud Agent. This integration embeds a preconfigured MySQL Exporter into the agent and automatically provisions Grafana dashboards and Prometheus alerting and recording rules, so you don&amp;rsquo;t have to import them manually. To learn how to set up the MySQL integration, please see &lt;a href="/docs/grafana-cloud/integrations/">Grafana Cloud Integrations&lt;/a>.&lt;/p>
&lt;p>The dashboards, recording rules, and alerting rules were generated using the MySQL Exporter Mixin. Mixins are reusable templates for dasboards, recording rules, and alerts curated and designed by subject matter experts. To learn more, please see the &lt;a href="https://github.com/prometheus/mysqld_exporter/tree/master/mysqld-mixin" target="_blank" rel="noopener noreferrer">MySQL Mixin&lt;/a> repository.&lt;/p></description></item><item><title>Recording rules</title><link>https://grafana.com</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://grafana.com</guid><description>&lt;p>&lt;strong>You should load the following recording rules before loading the dashboards in this guide.&lt;/strong> The dashboard queries use recording rules to reduce load on the Prometheus or Grafana Cloud Metrics servers, depending on where you&amp;rsquo;re evaluating the rules.&lt;/p>
&lt;p>This quickstart includes the following recording rules:&lt;/p>
&lt;ul>
&lt;li>&lt;code>record: instance:mysql_slave_lag_seconds&lt;/code>
&lt;ul>
&lt;li>PromQL: &lt;code>mysql_slave_status_seconds_behind_master - mysql_slave_status_sql_delay&lt;/code>&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>&lt;code>instance:mysql_heartbeat_lag_seconds&lt;/code>
&lt;ul>
&lt;li>PromQL: &lt;code>mysql_heartbeat_now_timestamp_seconds - mysql_heartbeat_stored_timestamp_seconds&lt;/code>&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>&lt;code>job:mysql_transactions:rate5m&lt;/code>
&lt;ul>
&lt;li>PromQL: &lt;code>sum without (command) (rate(mysql_global_status_commands_total{command=~&amp;quot;(commit|rollback)&amp;quot;}[5m]))&lt;/code>&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;a class="btn btn--primary br-5 mb-1" href="assets/recording_rules.yaml" rel="noopener noreferrer">Download the following recording rules YAML file&lt;/a>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">groups:
- name: mysqld_rules
rules:
- expr: mysql_slave_status_seconds_behind_master - mysql_slave_status_sql_delay
record: instance:mysql_slave_lag_seconds
- expr: mysql_heartbeat_now_timestamp_seconds - mysql_heartbeat_stored_timestamp_seconds
record: instance:mysql_heartbeat_lag_seconds
- expr: sum without (command) (rate(mysql_global_status_commands_total{command=~&amp;#34;(commit|rollback)&amp;#34;}[5m]))
record: job:mysql_transactions:rate5m&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>This recording rule YAML file was generated using the MySQL Exporter &lt;a href="https://github.com/prometheus/mysqld_exporter/tree/master/mysqld-mixin" target="_blank" rel="noopener noreferrer">mixin&lt;/a>.&lt;/p></description></item></channel></rss>