Grafana dashboard: Slow Logs
Description: MySQL slow logs monitoring

Dashboard to analyze MySQL slow logs from many servers and many databases
As a data source uses an index of Elasticsearch
Data collected with fluentd https://www.fluentd.org/datasources/mysqlslowquerylog

{
  "__inputs": [
    {
      "name": "DS_ELASTICSEARCH_SLOWLOGS",
      "label": "Elasticsearch SlowLogs",
      "description": "",
      "type": "datasource",
      "pluginId": "elasticsearch",
      "pluginName": "Elasticsearch"
    }
  ],
  "__requires": [
    {
      "type": "panel",
      "id": "bargauge",
      "name": "Bar gauge",
      "version": ""
    },
    {
      "type": "datasource",
      "id": "elasticsearch",
      "name": "Elasticsearch",
      "version": "1.0.0"
    },
    {
      "type": "grafana",
      "id": "grafana",
      "name": "Grafana",
      "version": "8.0.3"
    },
    {
      "type": "panel",
      "id": "table",
      "name": "Table",
      "version": ""
    },
    {
      "type": "panel",
      "id": "timeseries",
      "name": "Time series",
      "version": ""
    }
  ],
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": "-- Grafana --",
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "type": "dashboard"
      }
    ]
  },
  "description": "MySQL slow logs monitoring",
  "editable": true,
  "gnetId": 15766,
  "graphTooltip": 0,
  "id": null,
  "iteration": 1654013595226,
  "links": [],
  "panels": [
    {
      "datasource": "${DS_ELASTICSEARCH_SLOWLOGS}",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            "axisLabel": "",
            "axisPlacement": "auto",
            "barAlignment": 0,
            "drawStyle": "line",
            "fillOpacity": 0,
            "gradientMode": "none",
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            },
            "lineInterpolation": "linear",
            "lineWidth": 1,
            "pointSize": 5,
            "scaleDistribution": {
              "type": "linear"
            },
            "showPoints": "auto",
            "spanNulls": false,
            "stacking": {
              "group": "A",
              "mode": "none"
            },
            "thresholdsStyle": {
              "mode": "off"
            }
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 24,
        "x": 0,
        "y": 0
      },
      "id": 2,
      "options": {
        "legend": {
          "calcs": [
            "sum",
            "min",
            "max"
          ],
          "displayMode": "list",
          "placement": "bottom"
        },
        "tooltip": {
          "mode": "single"
        }
      },
      "targets": [
        {
          "alias": "",
          "bucketAggs": [
            {
              "field": "@timestamp",
              "id": "2",
              "settings": {
                "interval": "auto"
              },
              "type": "date_histogram"
            }
          ],
          "metrics": [
            {
              "id": "1",
              "type": "count"
            }
          ],
          "query": "hostname: ${hostName} AND db: ${dbName}",
          "queryType": "randomWalk",
          "refId": "A",
          "timeField": "@timestamp"
        }
      ],
      "title": "Total",
      "type": "timeseries"
    },
    {
      "datasource": "${DS_ELASTICSEARCH_SLOWLOGS}",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [],
          "thresholds": {
            "mode": "percentage",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "#EAB839",
                "value": 25
              },
              {
                "color": "red",
                "value": 50
              }
            ]
          },
          "unit": "short"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 9,
        "w": 6,
        "x": 0,
        "y": 8
      },
      "id": 8,
      "options": {
        "displayMode": "gradient",
        "orientation": "horizontal",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "/^Count$/",
          "values": true
        },
        "showUnfilled": true,
        "text": {}
      },
      "pluginVersion": "8.0.3",
      "targets": [
        {
          "alias": "",
          "bucketAggs": [
            {
              "field": "hostname.keyword",
              "id": "3",
              "settings": {
                "min_doc_count": "0",
                "order": "desc",
                "orderBy": "1",
                "size": "10"
              },
              "type": "terms"
            }
          ],
          "metrics": [
            {
              "id": "1",
              "type": "count"
            }
          ],
          "query": "",
          "queryType": "randomWalk",
          "refId": "A",
          "timeField": "@timestamp"
        }
      ],
      "title": "Top DB Hosts",
      "type": "bargauge"
    },
    {
      "datasource": "${DS_ELASTICSEARCH_SLOWLOGS}",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [],
          "thresholds": {
            "mode": "percentage",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "#EAB839",
                "value": 25
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          },
          "unit": "short"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 9,
        "w": 6,
        "x": 6,
        "y": 8
      },
      "id": 6,
      "options": {
        "displayMode": "gradient",
        "orientation": "horizontal",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "/^Count$/",
          "values": true
        },
        "showUnfilled": true,
        "text": {}
      },
      "pluginVersion": "8.0.3",
      "targets": [
        {
          "alias": "",
          "bucketAggs": [
            {
              "field": "schema.keyword",
              "id": "2",
              "settings": {
                "min_doc_count": "0",
                "order": "desc",
                "orderBy": "_count",
                "size": "10"
              },
              "type": "terms"
            }
          ],
          "metrics": [
            {
              "hide": false,
              "id": "1",
              "type": "count"
            }
          ],
          "query": "hostname: ${hostName}",
          "queryType": "randomWalk",
          "refId": "A",
          "timeField": "@timestamp"
        }
      ],
      "title": "TOP DB's",
      "type": "bargauge"
    },
    {
      "datasource": "${DS_ELASTICSEARCH_SLOWLOGS}",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [],
          "thresholds": {
            "mode": "percentage",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "#EAB839",
                "value": 25
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          },
          "unit": "short"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 9,
        "w": 12,
        "x": 12,
        "y": 8
      },
      "id": 10,
      "options": {
        "displayMode": "gradient",
        "orientation": "horizontal",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "/^Count$/",
          "values": true
        },
        "showUnfilled": true,
        "text": {}
      },
      "pluginVersion": "8.0.3",
      "targets": [
        {
          "alias": "",
          "bucketAggs": [
            {
              "field": "sql_fingerprint.keyword",
              "id": "3",
              "settings": {
                "min_doc_count": "0",
                "order": "desc",
                "orderBy": "1",
                "size": "10"
              },
              "type": "terms"
            }
          ],
          "metrics": [
            {
              "id": "1",
              "type": "count"
            }
          ],
          "query": "hostname: ${hostName} AND schema: ${dbName}",
          "queryType": "randomWalk",
          "refId": "A",
          "timeField": "@timestamp"
        }
      ],
      "title": "Top queries - Count",
      "type": "bargauge"
    },
    {
      "datasource": "${DS_ELASTICSEARCH_SLOWLOGS}",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": "auto",
            "displayMode": "auto",
            "filterable": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "time"
            },
            "properties": [
              {
                "id": "unit",
                "value": "dateTimeAsUSNoDateIfToday"
              },
              {
                "id": "custom.align",
                "value": "right"
              },
              {
                "id": "custom.width",
                "value": 150
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "filesort"
            },
            "properties": [
              {
                "id": "custom.align",
                "value": "center"
              },
              {
                "id": "mappings",
                "value": [
                  {
                    "options": {
                      "No": {
                        "color": "dark-green",
                        "index": 1
                      },
                      "Yes": {
                        "color": "dark-red",
                        "index": 0
                      }
                    },
                    "type": "value"
                  }
                ]
              },
              {
                "id": "custom.displayMode",
                "value": "color-background-solid"
              },
              {
                "id": "custom.width",
                "value": 80
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "filesort_on_disk"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 120
              },
              {
                "id": "custom.align",
                "value": "center"
              },
              {
                "id": "mappings",
                "value": [
                  {
                    "options": {
                      "No": {
                        "color": "dark-green",
                        "index": 1
                      },
                      "Yes": {
                        "color": "dark-red",
                        "index": 0
                      }
                    },
                    "type": "value"
                  }
                ]
              },
              {
                "id": "custom.displayMode",
                "value": "color-background-solid"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "full_join"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 80
              },
              {
                "id": "custom.align",
                "value": "center"
              },
              {
                "id": "mappings",
                "value": [
                  {
                    "options": {
                      "No": {
                        "color": "dark-green",
                        "index": 1
                      },
                      "Yes": {
                        "color": "dark-red",
                        "index": 0
                      }
                    },
                    "type": "value"
                  }
                ]
              },
              {
                "id": "custom.displayMode",
                "value": "color-background-solid"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "full_scan"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 80
              },
              {
                "id": "custom.align",
                "value": "center"
              },
              {
                "id": "mappings",
                "value": [
                  {
                    "options": {
                      "No": {
                        "color": "dark-green",
                        "index": 1
                      },
                      "Yes": {
                        "color": "dark-red",
                        "index": 0
                      }
                    },
                    "type": "value"
                  }
                ]
              },
              {
                "id": "custom.displayMode",
                "value": "color-background-solid"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "merge_passes"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 120
              },
              {
                "id": "custom.align",
                "value": "center"
              },
              {
                "id": "thresholds",
                "value": {
                  "mode": "absolute",
                  "steps": [
                    {
                      "color": "green",
                      "value": null
                    },
                    {
                      "color": "dark-green",
                      "value": 0
                    },
                    {
                      "color": "red",
                      "value": 1
                    }
                  ]
                }
              },
              {
                "id": "custom.displayMode",
                "value": "color-background-solid"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "priority_queue"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 120
              },
              {
                "id": "custom.align",
                "value": "center"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "qc_hit"
            },
            "properties": [
              {
                "id": "custom.align",
                "value": "center"
              },
              {
                "id": "custom.width",
                "value": 80
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "tmp_table"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 100
              },
              {
                "id": "custom.align",
                "value": "center"
              },
              {
                "id": "mappings",
                "value": [
                  {
                    "options": {
                      "No": {
                        "color": "dark-green",
                        "index": 1
                      },
                      "Yes": {
                        "color": "dark-red",
                        "index": 0
                      }
                    },
                    "type": "value"
                  }
                ]
              },
              {
                "id": "custom.displayMode",
                "value": "color-background-solid"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "tmp_table_on_disk"
            },
            "properties": [
              {
                "id": "custom.align",
                "value": "center"
              },
              {
                "id": "custom.width",
                "value": 130
              },
              {
                "id": "mappings",
                "value": [
                  {
                    "options": {
                      "No": {
                        "color": "dark-green",
                        "index": 1
                      },
                      "Yes": {
                        "color": "dark-red",
                        "index": 0
                      }
                    },
                    "type": "value"
                  }
                ]
              },
              {
                "id": "custom.displayMode",
                "value": "color-background-solid"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "lock_time"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 100
              },
              {
                "id": "custom.align",
                "value": "right"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "query_time"
            },
            "properties": [
              {
                "id": "custom.align",
                "value": "right"
              },
              {
                "id": "custom.width",
                "value": 100
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "rows_affected"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 117
              },
              {
                "id": "custom.align",
                "value": "right"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "rows_examined"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 100
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "rows_sent"
            },
            "properties": [
              {
                "id": "custom.align",
                "value": "right"
              },
              {
                "id": "custom.width",
                "value": 100
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "thread_id"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 130
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "hostname"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 130
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "db"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 130
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "tmp_disk_tables"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 120
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "tmp_table_sizes"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 130
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "tmp_tables"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 80
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "bytes_sent"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 100
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "indexed"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 80
              },
              {
                "id": "custom.align",
                "value": "center"
              },
              {
                "id": "mappings",
                "value": [
                  {
                    "options": {
                      "NaN": {
                        "color": "dark-blue",
                        "index": 3
                      }
                    },
                    "type": "value"
                  },
                  {
                    "options": {
                      "from": 0.91,
                      "result": {
                        "color": "dark-green",
                        "index": 0,
                        "text": "Yes"
                      },
                      "to": 1
                    },
                    "type": "range"
                  },
                  {
                    "options": {
                      "from": 0.5,
                      "result": {
                        "color": "dark-orange",
                        "index": 1,
                        "text": "Poor"
                      },
                      "to": 0.9
                    },
                    "type": "range"
                  },
                  {
                    "options": {
                      "from": 0,
                      "result": {
                        "color": "dark-red",
                        "index": 2,
                        "text": "No"
                      },
                      "to": 0.49
                    },
                    "type": "range"
                  }
                ]
              },
              {
                "id": "custom.displayMode",
                "value": "color-background-solid"
              },
              {
                "id": "decimals",
                "value": 2
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 27,
        "w": 24,
        "x": 0,
        "y": 17
      },
      "id": 4,
      "options": {
        "showHeader": true,
        "sortBy": []
      },
      "pluginVersion": "8.0.3",
      "targets": [
        {
          "alias": "",
          "bucketAggs": [],
          "metrics": [
            {
              "id": "1",
              "settings": {
                "limit": "500"
              },
              "type": "logs"
            }
          ],
          "query": "hostname: ${hostName} AND schema: ${dbName}",
          "queryType": "randomWalk",
          "refId": "A",
          "timeField": "@timestamp"
        }
      ],
      "title": "Slow Queries",
      "transformations": [
        {
          "id": "calculateField",
          "options": {
            "alias": "indexed",
            "binary": {
              "left": "rows_sent",
              "operator": "/",
              "reducer": "sum",
              "right": "rows_examined"
            },
            "mode": "binary",
            "reduce": {
              "include": [
                "rows_sent",
                "rows_examined"
              ],
              "reducer": "diffperc"
            },
            "replaceFields": false
          }
        },
        {
          "id": "organize",
          "options": {
            "excludeByName": {
              "@version": true,
              "_id": true,
              "_index": true,
              "_source": true,
              "_type": true,
              "db": true,
              "highlight": true,
              "host": true,
              "host_ip": true,
              "port": true,
              "schema": false,
              "sort": true,
              "tags": true,
              "user": true
            },
            "indexByName": {
              "@timestamp": 0,
              "@version": 2,
              "_id": 3,
              "_index": 4,
              "_source": 5,
              "_type": 6,
              "bytes_sent": 31,
              "db": 7,
              "filesort": 10,
              "filesort_on_disk": 11,
              "full_join": 12,
              "full_scan": 13,
              "highlight": 14,
              "host": 15,
              "host_ip": 16,
              "hostname": 1,
              "indexed": 9,
              "lock_time": 26,
              "merge_passes": 17,
              "port": 23,
              "priority_queue": 24,
              "qc_hit": 25,
              "query_time": 27,
              "rows_affected": 28,
              "rows_examined": 29,
              "rows_sent": 30,
              "schema": 8,
              "sort": 32,
              "sql_fingerprint": 33,
              "tags": 34,
              "thread_id": 35,
              "tmp_disk_tables": 20,
              "tmp_table": 18,
              "tmp_table_on_disk": 19,
              "tmp_table_sizes": 21,
              "tmp_tables": 22,
              "user": 36
            },
            "renameByName": {
              "@timestamp": "time"
            }
          }
        }
      ],
      "type": "table"
    }
  ],
  "refresh": "5s",
  "schemaVersion": 30,
  "style": "dark",
  "tags": [
    "mysql"
  ],
  "templating": {
    "list": [
      {
        "allValue": null,
        "current": {},
        "datasource": "${DS_ELASTICSEARCH_SLOWLOGS}",
        "definition": "{\"find\": \"terms\", \"field\": \"hostname.keyword\", \"size\": 1000}",
        "description": "DB server host name",
        "error": null,
        "hide": 0,
        "includeAll": true,
        "label": null,
        "multi": true,
        "name": "hostName",
        "options": [],
        "query": "{\"find\": \"terms\", \"field\": \"hostname.keyword\", \"size\": 1000}",
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 1,
        "type": "query"
      },
      {
        "allValue": null,
        "current": {},
        "datasource": "${DS_ELASTICSEARCH_SLOWLOGS}",
        "definition": "{\"find\": \"terms\", \"field\": \"schema.keyword\", \"size\": 1000, \"query\": \"$hostName\"}",
        "description": null,
        "error": null,
        "hide": 0,
        "includeAll": true,
        "label": null,
        "multi": true,
        "name": "dbName",
        "options": [],
        "query": "{\"find\": \"terms\", \"field\": \"schema.keyword\", \"size\": 1000, \"query\": \"$hostName\"}",
        "refresh": 2,
        "regex": "",
        "skipUrlSync": false,
        "sort": 1,
        "type": "query"
      },
      {
        "datasource": "Elasticsearch SlowLogs",
        "description": null,
        "error": null,
        "filters": [],
        "hide": 0,
        "label": null,
        "name": "Filters",
        "skipUrlSync": false,
        "type": "adhoc"
      }
    ]
  },
  "time": {
    "from": "now-5m",
    "to": "now-1m"
  },
  "timepicker": {
    "nowDelay": "1m"
  },
  "timezone": "",
  "title": "Slow Logs",
  "uid": "9ae49Eank",
  "version": 52
}