{"id":1697,"date":"2024-03-05T14:32:40","date_gmt":"2024-03-05T06:32:40","guid":{"rendered":"https:\/\/www.strongd.net\/?p=1697"},"modified":"2024-03-05T14:32:40","modified_gmt":"2024-03-05T06:32:40","slug":"collect-and-visualize-mysql-server-logs-with-the-updated-mysql-integration-for-grafana-cloud","status":"publish","type":"post","link":"https:\/\/www.strongd.net\/?p=1697","title":{"rendered":"Collect and visualize MySQL server logs with the updated MySQL integration for Grafana Cloud"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full\" src=\"https:\/\/grafana.com\/static\/assets\/meta\/mysql-integration-grafana-cloud-dashboard-screenshot.png?w=1504\" width=\"1504\" height=\"763\" \/><\/p>\n<p>Today, we are excited to announce that the\u00a0<a href=\"https:\/\/grafana.com\/solutions\/mysql\/monitor\/?pg=blog&amp;plcmt=body-txt\">MySQL integration<\/a>\u00a0has received an important update, which includes a new pre-built MySQL logs dashboard and the Grafana Agent configuration to view and collect MySQL server logs.<\/p>\n<p>The integration is already available in\u00a0<a href=\"https:\/\/grafana.com\/products\/cloud\/?pg=blog&amp;plcmt=body-txt\">Grafana Cloud<\/a>, our platform that brings together all your metrics, logs, and traces with Grafana for full-stack observability.<\/p>\n<h2 id=\"why-you-need-logs\">Why you need logs<\/h2>\n<p>Of all the\u00a0<a href=\"https:\/\/grafana.com\/blog\/2019\/10\/21\/whats-next-for-observability\/?pg=blog&amp;plcmt=body-txt\">three pillars<\/a>\u00a0of observability,\u00a0<a href=\"https:\/\/grafana.com\/docs\/grafana-cloud\/fundamentals\/intro-to-metrics-and-visualizations\/?pg=blog&amp;plcmt=body-txt\">metrics<\/a>\u00a0are the most widely used: They are easier to gather and store than\u00a0<a href=\"https:\/\/grafana.com\/docs\/grafana-cloud\/logs\/?pg=blog&amp;plcmt=body-txt\">logs<\/a>\u00a0or\u00a0<a href=\"https:\/\/grafana.com\/docs\/grafana-cloud\/traces\/?pg=blog&amp;plcmt=body-txt\">traces<\/a>. They are great for detecting problems and understanding system performance at a glance. Still, metrics are often not enough to understand what caused an issue.<\/p>\n<p>On the other hand, logs can tell you many more details about the root cause, once you narrow down the time and location of the problem using metrics.<\/p>\n<h2 id=\"getting-started-with-the-mysql-integration\">Getting started with the MySQL integration<\/h2>\n<p><a href=\"https:\/\/grafana.com\/docs\/grafana-cloud\/agent\/?pg=blog&amp;plcmt=body-txt\">Grafana Agent<\/a>\u00a0is the universal collector and is all you need to send different telemetry data to the Grafana Cloud stack, including metrics, logs, and traces.<\/p>\n<p>If you already use the embedded Agent integration to collect Prometheus metrics, your Agent configuration could look like this:<\/p>\n<div class=\"code-snippet\">\n<div class=\"lang-toolbar\"><span class=\"lang-toolbar__item\">yaml<\/span><span class=\"code-clipboard\"><button aria-expanded=\"false\"><img loading=\"lazy\" decoding=\"async\" class=\"code-clipboard__icon\" src=\"https:\/\/grafana.com\/media\/images\/icons\/icon-copy-small-2.svg\" alt=\"Copy code to clipboard\" width=\"14\" height=\"13\" \/>Copy<\/button><\/span><\/p>\n<div class=\"lang-toolbar__border\"><\/div>\n<\/div>\n<div class=\"code-snippet\">\n<pre class=\"language-yaml\" tabindex=\"0\" data-expanded=\"false\"><code class=\"language-yaml\"><span class=\"token key atrule\">integrations<\/span><span class=\"token punctuation\">:<\/span>\r\n  <span class=\"token key atrule\">prometheus_remote_write<\/span><span class=\"token punctuation\">:<\/span>\r\n    <span class=\"token punctuation\">-<\/span> <span class=\"token key atrule\">url<\/span><span class=\"token punctuation\">:<\/span> https<span class=\"token punctuation\">:<\/span>\/\/&lt;cloud<span class=\"token punctuation\">-<\/span>endpoint<span class=\"token punctuation\">&gt;<\/span>\/api\/prom\/push\r\n  <span class=\"token key atrule\">mysqld_exporter<\/span><span class=\"token punctuation\">:<\/span>\r\n    <span class=\"token key atrule\">enabled<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token boolean important\">true<\/span>\r\n    <span class=\"token key atrule\">instance<\/span><span class=\"token punctuation\">:<\/span> mysql<span class=\"token punctuation\">-<\/span><span class=\"token number\">01<\/span>\r\n    <span class=\"token key atrule\">data_source_name<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">\"root:put-password-here@(localhost:3306)\/\"<\/span><\/code><\/pre>\n<\/div>\n<\/div>\n<p>Adding MySQL logs is just adding some extra lines of Grafana Agent config.yml:<\/p>\n<div class=\"code-snippet\">\n<div class=\"lang-toolbar\"><span class=\"lang-toolbar__item\">yaml<\/span><span class=\"code-clipboard\"><button aria-expanded=\"false\"><img loading=\"lazy\" decoding=\"async\" class=\"code-clipboard__icon\" src=\"https:\/\/grafana.com\/media\/images\/icons\/icon-copy-small-2.svg\" alt=\"Copy code to clipboard\" width=\"14\" height=\"13\" \/>Copy<\/button><\/span><\/p>\n<div class=\"lang-toolbar__border\"><\/div>\n<\/div>\n<div class=\"code-snippet\">\n<section class=\"expand-code-wrapper\">\n<div class=\"button-div\"><button class=\"expand-code-btn\">Expand code<\/button><\/div>\n<pre class=\"language-yaml\" tabindex=\"0\" data-expanded=\"false\"><code class=\"language-yaml\"><span class=\"token key atrule\">metrics<\/span><span class=\"token punctuation\">:<\/span>\r\n  <span class=\"token key atrule\">wal_directory<\/span><span class=\"token punctuation\">:<\/span> \/tmp\/wal\r\n<span class=\"token key atrule\">logs<\/span><span class=\"token punctuation\">:<\/span>\r\n  <span class=\"token key atrule\">configs<\/span><span class=\"token punctuation\">:<\/span>\r\n  <span class=\"token punctuation\">-<\/span> <span class=\"token key atrule\">name<\/span><span class=\"token punctuation\">:<\/span> agent\r\n    <span class=\"token key atrule\">clients<\/span><span class=\"token punctuation\">:<\/span>\r\n    <span class=\"token punctuation\">-<\/span> <span class=\"token key atrule\">url<\/span><span class=\"token punctuation\">:<\/span> https<span class=\"token punctuation\">:<\/span>\/\/&lt;cloud<span class=\"token punctuation\">-<\/span>logs<span class=\"token punctuation\">-<\/span>endpoint<span class=\"token punctuation\">&gt;<\/span>\/loki\/api\/v1\/push\r\n    <span class=\"token key atrule\">positions<\/span><span class=\"token punctuation\">:<\/span>\r\n      <span class=\"token key atrule\">filename<\/span><span class=\"token punctuation\">:<\/span> \/tmp\/positions.yaml\r\n    <span class=\"token key atrule\">target_config<\/span><span class=\"token punctuation\">:<\/span>\r\n      <span class=\"token key atrule\">sync_period<\/span><span class=\"token punctuation\">:<\/span> 10s\r\n    <span class=\"token key atrule\">scrape_configs<\/span><span class=\"token punctuation\">:<\/span>\r\n    <span class=\"token punctuation\">-<\/span> <span class=\"token key atrule\">job_name<\/span><span class=\"token punctuation\">:<\/span> integrations\/mysql \r\n      <span class=\"token key atrule\">static_configs<\/span><span class=\"token punctuation\">:<\/span>\r\n        <span class=\"token punctuation\">-<\/span> <span class=\"token key atrule\">labels<\/span><span class=\"token punctuation\">:<\/span>\r\n            <span class=\"token key atrule\">instance<\/span><span class=\"token punctuation\">:<\/span> mysql<span class=\"token punctuation\">-<\/span><span class=\"token number\">01<\/span>\r\n            <span class=\"token key atrule\">job<\/span><span class=\"token punctuation\">:<\/span> integrations\/mysql\r\n            <span class=\"token key atrule\">__path__<\/span><span class=\"token punctuation\">:<\/span> \/var\/log\/mysql\/<span class=\"token important\">*.log<\/span>\r\n      <span class=\"token key atrule\">pipeline_stages<\/span><span class=\"token punctuation\">:<\/span>\r\n        <span class=\"token punctuation\">-<\/span> <span class=\"token key atrule\">regex<\/span><span class=\"token punctuation\">:<\/span>\r\n            <span class=\"token key atrule\">expression<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">'(?P&lt;timestamp&gt;.+) (?P&lt;thread&gt;[\\d]+) \\[(?P&lt;label&gt;.+?)\\]( \\[(?P&lt;err_code&gt;.+?)\\] \\[(?P&lt;subsystem&gt;.+?)\\])? (?P&lt;msg&gt;.+)'<\/span>\r\n        <span class=\"token punctuation\">-<\/span> <span class=\"token key atrule\">labels<\/span><span class=\"token punctuation\">:<\/span>\r\n            <span class=\"token key atrule\">label<\/span><span class=\"token punctuation\">:<\/span>\r\n            <span class=\"token key atrule\">err_code<\/span><span class=\"token punctuation\">:<\/span>\r\n            <span class=\"token key atrule\">subsystem<\/span><span class=\"token punctuation\">:<\/span>\r\n        <span class=\"token punctuation\">-<\/span> <span class=\"token key atrule\">drop<\/span><span class=\"token punctuation\">:<\/span>\r\n            <span class=\"token key atrule\">expression<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">\"^ *$\"<\/span>\r\n            <span class=\"token key atrule\">drop_counter_reason<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">\"drop empty lines\"<\/span>\r\n\r\n<span class=\"token key atrule\">integrations<\/span><span class=\"token punctuation\">:<\/span>\r\n  <span class=\"token key atrule\">prometheus_remote_write<\/span><span class=\"token punctuation\">:<\/span>\r\n    <span class=\"token punctuation\">-<\/span> <span class=\"token key atrule\">url<\/span><span class=\"token punctuation\">:<\/span> https<span class=\"token punctuation\">:<\/span>\/\/&lt;cloud<span class=\"token punctuation\">-<\/span>endpoint<span class=\"token punctuation\">&gt;<\/span>\/api\/prom\/push\r\n  <span class=\"token key atrule\">mysqld_exporter<\/span><span class=\"token punctuation\">:<\/span>\r\n    <span class=\"token key atrule\">enabled<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token boolean important\">true<\/span>\r\n    <span class=\"token key atrule\">instance<\/span><span class=\"token punctuation\">:<\/span> mysql<span class=\"token punctuation\">-<\/span><span class=\"token number\">01<\/span>\r\n    <span class=\"token key atrule\">data_source_name<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">\"root:put-password-here@(localhost:3306)\/\"<\/span>\r\n    <span class=\"token key atrule\">relabel_configs<\/span><span class=\"token punctuation\">:<\/span>\r\n      <span class=\"token punctuation\">-<\/span> <span class=\"token key atrule\">source_labels<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token punctuation\">[<\/span>__address__<span class=\"token punctuation\">]<\/span>\r\n        <span class=\"token key atrule\">target_label<\/span><span class=\"token punctuation\">:<\/span> job\r\n        <span class=\"token key atrule\">replacement<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">'integrations\/mysql'<\/span><\/code><\/pre>\n<\/section>\n<\/div>\n<\/div>\n<p>The additional configuration above locates and parses MySQL server logs by using an embedded\u00a0<a href=\"https:\/\/grafana.com\/docs\/agent\/latest\/configuration\/logs-config\/?pg=blog&amp;plcmt=body-txt\">Promtail<\/a>\u00a0Agent.<\/p>\n<p>The most crucial configuration part is to make sure that the labels\u00a0<code>job<\/code>\u00a0and\u00a0<code>instance<\/code>\u00a0match each other for logs and metrics. This ensures that we can quickly dive from graphs to corresponding logs for more details on what actually happened.<\/p>\n<p>You can find more information on configuring the MySQL integration in our\u00a0<a href=\"https:\/\/grafana.com\/docs\/grafana-cloud\/integrations\/integrations\/integration-mysql\/?pg=blog&amp;plcmt=body-txt\">MySQL integration documentation<\/a>.<\/p>\n<p>To learn more and get a better understanding of how to correlate metrics, logs, and traces in\u00a0<a href=\"https:\/\/grafana.com\/oss\/?pg=blog&amp;plcmt=body-txt\">Grafana<\/a>, I also recommend checking out the detailed talk by Andrej Ocenas on\u00a0<a href=\"https:\/\/grafana.com\/blog\/2020\/03\/31\/how-to-successfully-correlate-metrics-logs-and-traces-in-grafana\/?pg=blog&amp;plcmt=body-txt\">how to successfully correlate metrics, logs, and traces in Grafana<\/a>.<\/p>\n<h2 id=\"start-monitoring-with-the-mysql-logs-dashboard\">Start monitoring with the MySQL logs dashboard<\/h2>\n<figure class=\"figure-wrapper figure-wrapper__lightbox w-100p\"><a class=\"lightbox-link captioned\" href=\"https:\/\/grafana.com\/static\/assets\/img\/blog\/mysql-integration-grafana-cloud-logs-dashboard.png\"><img decoding=\"async\" class=\"mb-0 lazyloaded\" title=\"New logs dashboard in the My SQL integration for Grafana Cloud\" src=\"https:\/\/grafana.com\/static\/assets\/img\/blog\/mysql-integration-grafana-cloud-logs-dashboard.png\" alt=\"New logs dashboard in the My SQL integration for Grafana Cloud\" data-src=\"\/static\/assets\/img\/blog\/mysql-integration-grafana-cloud-logs-dashboard.png\" \/><\/a><figcaption class=\"w-100p caption mb-1 text-gray-13\">New logs dashboard in the My SQL integration for Grafana Cloud<\/figcaption><\/figure>\n<p>Along with coming packaged with pre-built dashboards as well as metrics and alerts, the MySQL integration for Grafana Cloud now bundles a new MySQL logs dashboard that can be quickly accessed from the MySQL overview dashboard when you need a deeper understanding of what\u2019s going on with your MySQL server:<\/p>\n<div style=\"box-sizing: border-box; color: #393946; font-family: inter, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;\">\n<figure class=\"p-0 m-0\">\n<div class=\"my-1\"><iframe title=\"vimeo video\" src=\"https:\/\/player.vimeo.com\/video\/712187194?transparent=0\" allowfullscreen=\"allowfullscreen\" data-mce-fragment=\"1\"><\/iframe><\/div>\n<\/figure>\n<\/div>\n<p>The important thing to note is that if you jump from one dashboard to another, the context of the MySQL instance and time interval will remain the same.<\/p>\n<h2 id=\"try-out-the-mysql-integration\">Try out the MySQL integration<\/h2>\n<p>The enhanced MySQL integration with log capabilities is available now for Grafana Cloud users. If you\u2019re not already using\u00a0<a href=\"https:\/\/grafana.com\/products\/cloud\/?pg=blog&amp;plcmt=body-txt\">Grafana Cloud<\/a>, we have a generous free forever tier and plans for every use case.\u00a0<a href=\"https:\/\/grafana.com\/auth\/sign-up\/create-user?pg=blog&amp;plcmt=body-txt\">Sign up for free now<\/a>!<\/p>\n<p>It\u2019s the easiest way to get started observing metrics, logs, traces, and dashboards.<\/p>\n<p>For more information on monitoring and alerting on Grafana Cloud and MySQL, check out our\u00a0<a href=\"https:\/\/grafana.com\/docs\/grafana-cloud\/reference\/integrations\/integration-mysql\/\">MySQL integration documentation,<\/a>\u00a0<a href=\"https:\/\/grafana.com\/solutions\/mysql\/monitor\/\">\u00a0the MySQL solutions page,<\/a>\u00a0or join the #integrations channel in the\u00a0<a href=\"https:\/\/grafana.slack.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Grafana Labs Community Slack<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today, we are excited to announce that the\u00a0MySQL integration\u00a0has received an important update, which includes a new pre-built MySQL logs dashboard and the Grafana Agent configuration to view and collect MySQL server logs. The integration is already available in\u00a0Grafana Cloud, our platform that brings together all your metrics, logs, and traces with Grafana for full-stack &hellip; <a href=\"https:\/\/www.strongd.net\/?p=1697\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Collect and visualize MySQL server logs with the updated MySQL integration for Grafana Cloud<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"gallery","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-1697","post","type-post","status-publish","format-gallery","hentry","category-20","post_format-post-format-gallery"],"_links":{"self":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/1697","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1697"}],"version-history":[{"count":1,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/1697\/revisions"}],"predecessor-version":[{"id":1698,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/1697\/revisions\/1698"}],"wp:attachment":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1697"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1697"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1697"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}