Grafana dashboard: Ruby on Rails Slowlog by SQL Query
Description: The sloweds queries in your Ruby on Rails application

# A Ruby on Rails Performance Dashboard

The datasource would be a [influxdb](https://www.influxdata.com/products/influxdb-overview/) database that is filled by the official [influxdb-rails](https://github.com/influxdata/influxdb-rails) reporter.

**PLEASE NOTE**: This dashboard is one of a collection of Ruby on Rails dashboards. They make the most sense united.

- [Ruby On Rails Performance Overview](https://grafana.com/dashboards/10428/)
- Performance insights into individual requests, see [Ruby On Rails Performance per Request](https://grafana.com/dashboards/10429/)
- Performance of individual actions, see [Ruby On Rails Performance per Action](https://grafana.com/grafana/dashboards/11031)
- [Ruby On Rails Health Overview](https://grafana.com/grafana/dashboards/14115)
- [Ruby on Rails ActiveJob Overview](https://grafana.com/grafana/dashboards/14116)
- [Ruby on Rails Slowlog by Request](https://grafana.com/grafana/dashboards/14118)
- [Ruby on Rails Slowlog by Action](https://grafana.com/grafana/dashboards/14117)
- [Ruby on Rails Slowlog by SQL](https://grafana.com/grafana/dashboards/14119)

{
  "__inputs": [
    {
      "name": "DS_INFLUXDB-RAILS",
      "label": "InfluxDB",
      "description": "",
      "type": "datasource",
      "pluginId": "influxdb",
      "pluginName": "InfluxDB"
    }
  ],
  "__requires": [
    {
      "type": "grafana",
      "id": "grafana",
      "name": "Grafana",
      "version": "7.1.1"
    },
    {
      "type": "datasource",
      "id": "influxdb",
      "name": "InfluxDB",
      "version": "1.0.0"
    },
    {
      "type": "panel",
      "id": "table-old",
      "name": "Table (old)",
      "version": ""
    }
  ],
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": "-- Grafana --",
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "type": "dashboard"
      }
    ]
  },
  "description": "The sloweds queries in your Ruby on Rails application",
  "editable": true,
  "gnetId": 14119,
  "graphTooltip": 0,
  "id": null,
  "links": [
    {
      "$$hashKey": "object:40",
      "icon": "external link",
      "tags": [
        "influxdb-rails"
      ],
      "type": "dashboards"
    }
  ],
  "panels": [
    {
      "columns": [],
      "datasource": "${DS_INFLUXDB-RAILS}",
      "description": "Data for the selected range by database query.\n\n- Count: Number of occurrences\n- Mean: Average time spent\n- Median: Median time spent\n- Maximum: Slowest occurrence\n\n[Average vs. Median?](https://www.differencebetween.com/difference-between-mean-and-median/)",
      "fieldConfig": {
        "defaults": {
          "custom": {}
        },
        "overrides": []
      },
      "fontSize": "100%",
      "gridPos": {
        "h": 23,
        "w": 24,
        "x": 0,
        "y": 0
      },
      "id": 2,
      "links": [],
      "pageSize": null,
      "scroll": true,
      "showHeader": true,
      "sort": {
        "col": 6,
        "desc": true
      },
      "styles": [
        {
          "alias": "Time",
          "align": "auto",
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "pattern": "Time",
          "type": "hidden"
        },
        {
          "alias": "Count",
          "align": "auto",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": null,
          "mappingType": 1,
          "pattern": "count",
          "thresholds": [],
          "type": "number",
          "unit": "short"
        },
        {
          "alias": "Mean",
          "align": "auto",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "mean",
          "thresholds": [],
          "type": "number",
          "unit": "ms"
        },
        {
          "alias": "Median",
          "align": "auto",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "median",
          "thresholds": [],
          "type": "number",
          "unit": "ms"
        },
        {
          "alias": "Controller Action",
          "align": "auto",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "link": true,
          "linkTargetBlank": true,
          "linkTooltip": "View data per this Controller Action",
          "linkUrl": "/d/influxdb-rails-action/ruby-on-rails-performance-per-action?var-Action=${__cell}&from=$__from&to=$__to",
          "mappingType": 1,
          "pattern": "location",
          "thresholds": [],
          "type": "string",
          "unit": "short"
        },
        {
          "alias": "Name of the operation",
          "align": "auto",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "name",
          "thresholds": [],
          "type": "string",
          "unit": "short",
          "valueMaps": [
            {
              "text": "Raw",
              "value": ""
            }
          ]
        },
        {
          "alias": "Maximum",
          "align": "auto",
          "colorMode": "value",
          "colors": [
            "rgba(50, 172, 45, 0.97)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(245, 54, 54, 0.9)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "max",
          "thresholds": [
            "3000",
            "5000"
          ],
          "type": "number",
          "unit": "ms"
        }
      ],
      "targets": [
        {
          "groupBy": [
            {
              "params": [
                "name"
              ],
              "type": "tag"
            },
            {
              "params": [
                "location"
              ],
              "type": "tag"
            }
          ],
          "measurement": "rails",
          "orderByTime": "ASC",
          "policy": "default",
          "refId": "A",
          "resultFormat": "table",
          "select": [
            [
              {
                "params": [
                  "value"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "count"
              }
            ],
            [
              {
                "params": [
                  "value"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ],
            [
              {
                "params": [
                  "value"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "median"
              }
            ],
            [
              {
                "params": [
                  "value"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "max"
              }
            ]
          ],
          "tags": [
            {
              "key": "hook",
              "operator": "=",
              "value": "sql"
            }
          ]
        }
      ],
      "title": "Slowest Database Query",
      "transform": "table",
      "type": "table-old"
    }
  ],
  "schemaVersion": 26,
  "style": "dark",
  "tags": [
    "Performance",
    "Ruby on Rails",
    "influxdb-rails"
  ],
  "templating": {
    "list": []
  },
  "time": {
    "from": "now-1h",
    "to": "now"
  },
  "timepicker": {
    "hidden": false,
    "refresh_intervals": [
      "10s",
      "30s",
      "1m",
      "5m",
      "15m",
      "30m",
      "1h",
      "2h",
      "1d"
    ]
  },
  "timezone": "",
  "title": "Ruby on Rails Slowlog by SQL Query",
  "uid": "influxdb-rails-slowlog-sql",
  "version": 14
}