Grafana dashboard: Grafana Usage insights datasource details
Description: Grafana Usage insights datasource details for use with the Loki datasource

Grafana Usage insights detail view per data source, for use with the Loki datasource

Works in conjunction with the usage insights overview dashboard: 

https://grafana.com/grafana/dashboards/13785

{
  "__inputs": [
    {
      "name": "DS_LOKI",
      "label": "loki-datasource",
      "description": "",
      "type": "datasource",
      "pluginId": "loki",
      "pluginName": "Loki"
    }
  ],
  "__requires": [
    {
      "type": "grafana",
      "id": "grafana",
      "name": "Grafana",
      "version": "7.3.6"
    },
    {
      "type": "panel",
      "id": "graph",
      "name": "Graph",
      "version": ""
    },
    {
      "type": "datasource",
      "id": "loki",
      "name": "Loki",
      "version": "1.0.0"
    },
    {
      "type": "panel",
      "id": "stat",
      "name": "Stat",
      "version": ""
    },
    {
      "type": "panel",
      "id": "table",
      "name": "Table",
      "version": ""
    }
  ],
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": "-- Grafana --",
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "target": {
          "limit": 100,
          "matchAny": false,
          "tags": [],
          "type": "dashboard"
        },
        "type": "dashboard"
      }
    ]
  },
  "description": "Grafana Usage insights datasource details for use with the Loki datasource",
  "editable": true,
  "fiscalYearStartMonth": 0,
  "gnetId": 13786,
  "graphTooltip": 0,
  "id": 95,
  "iteration": 1650655079520,
  "links": [
    {
      "icon": "dashboard",
      "tags": [],
      "title": "Usage Insights Overview",
      "type": "link",
      "url": "/d/XU8HAD5Gk/usage-insights"
    }
  ],
  "liveNow": false,
  "panels": [
    {
      "cacheTimeout": null,
      "datasource": "${DS_LOKI}",
      "description": "",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [],
          "max": 100,
          "min": 0,
          "noValue": "No errors",
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "purple",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          },
          "unit": "percent"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 7,
        "w": 4,
        "x": 0,
        "y": 0
      },
      "id": 11,
      "links": [],
      "maxDataPoints": 1,
      "options": {
        "colorMode": "background",
        "graphMode": "area",
        "justifyMode": "center",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "max"
          ],
          "fields": "",
          "values": false
        },
        "text": {},
        "textMode": "value"
      },
      "pluginVersion": "9.0.0-pre",
      "targets": [
        {
          "expr": "sum(rate({kind=\"usage_insights\"} | json | datasourceName=\"${Datasource}\" | eventName=\"data-request\" | error!=\"\" [$__interval])) / (sum(rate({kind=\"usage_insights\"} | json | datasourceName=\"${Datasource}\" | eventName=\"data-request\" [$__interval])) / 100) ",
          "legendFormat": "",
          "refId": "A"
        }
      ],
      "title": "% of error requests ",
      "type": "stat"
    },
    {
      "cacheTimeout": null,
      "datasource": "${DS_LOKI}",
      "description": "",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": null
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "purple",
                "value": null
              }
            ]
          },
          "unit": "short"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 7,
        "w": 4,
        "x": 4,
        "y": 0
      },
      "id": 15,
      "links": [],
      "maxDataPoints": 1,
      "options": {
        "colorMode": "background",
        "graphMode": "area",
        "justifyMode": "center",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "sum"
          ],
          "fields": "",
          "values": false
        },
        "text": {},
        "textMode": "value"
      },
      "pluginVersion": "9.0.0-pre",
      "targets": [
        {
          "expr": "sum(count_over_time({kind=\"usage_insights\"} | json | datasourceName=\"${Datasource}\" | eventName=\"data-request\" [$__interval]))",
          "legendFormat": "",
          "refId": "A"
        }
      ],
      "title": "Total requests ",
      "type": "stat"
    },
    {
      "aliasColors": {
        "Dashboard views from  Jons-MBP": "light-yellow",
        "Dashboard views from  iMac-Pro-Ward.local": "blue",
        "Errors for Jons-MBP": "red",
        "Request errors from Jons-MBP": "red",
        "Request errors from iMac-Pro-Ward.local": "dark-red",
        "Requests from Jons-MBP": "green",
        "Requests from iMac-Pro-Ward.local": "dark-green",
        "Success for Jons-MBP": "green"
      },
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "datasource": "${DS_LOKI}",
      "description": "",
      "fieldConfig": {
        "defaults": {
          "unit": "short"
        },
        "overrides": []
      },
      "fill": 1,
      "fillGradient": 0,
      "gridPos": {
        "h": 7,
        "w": 16,
        "x": 8,
        "y": 0
      },
      "hiddenSeries": false,
      "id": 17,
      "interval": "5m",
      "legend": {
        "alignAsTable": true,
        "avg": false,
        "current": false,
        "max": false,
        "min": false,
        "rightSide": true,
        "show": true,
        "total": false,
        "values": false
      },
      "lines": true,
      "linewidth": 1,
      "nullPointMode": "null as zero",
      "options": {
        "alertThreshold": true
      },
      "percentage": false,
      "pluginVersion": "9.0.0-pre",
      "pointradius": 2,
      "points": true,
      "renderer": "flot",
      "seriesOverrides": [
        {
          "$$hashKey": "object:220",
          "alias": "/errors/",
          "color": "#E02F44"
        },
        {
          "$$hashKey": "object:221",
          "alias": "/Requests from/",
          "color": "#3274D9"
        },
        {
          "$$hashKey": "object:736",
          "alias": "/Dashboard views from/",
          "color": "#56A64B"
        }
      ],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "datasource": {
            "type": "loki",
            "uid": "nKl5Cesnz"
          },
          "expr": "sum by(host) (count_over_time({kind=\"usage_insights\", datasource=\"${Datasource}\"} | json | eventName=\"data-request\" | error = \"\" [$__interval]))",
          "legendFormat": "Data Requests from {{host}}",
          "refId": "A"
        },
        {
          "datasource": {
            "type": "loki",
            "uid": "nKl5Cesnz"
          },
          "expr": "sum by(host) (count_over_time({kind=\"usage_insights\", datasource=\"${Datasource}\"} | json | eventName=\"data-request\" | error != \"\" [$__interval]))",
          "legendFormat": "Data Requests errors from {{host}}",
          "refId": "B"
        },
        {
          "datasource": {
            "type": "loki",
            "uid": "nKl5Cesnz"
          },
          "expr": "sum by (eventName) (\n  sum_over_time(\n    {kind=\"usage_insights\", datasource=\"${Datasource}\"} \n    | json \n    | eventName = \"data-request\" \n    | cachedQueries > 0\n    | unwrap cachedQueries [$__interval]\n  )\n)\n",
          "hide": false,
          "legendFormat": "Cached Queries",
          "refId": "C"
        },
        {
          "datasource": {
            "type": "loki",
            "uid": "nKl5Cesnz"
          },
          "expr": "sum by (eventName) (\n  sum_over_time(\n    {kind=\"usage_insights\", datasource=\"${Datasource}\"} \n    | json \n    | eventName = \"data-request\"\n    | totalQueries > 0\n    | unwrap totalQueries [$__interval]\n  )\n)",
          "hide": false,
          "legendFormat": "Total Queries",
          "refId": "D"
        }
      ],
      "thresholds": [],
      "timeRegions": [],
      "title": "Datasource requests over time",
      "tooltip": {
        "shared": true,
        "sort": 0,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "mode": "time",
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "$$hashKey": "object:234",
          "decimals": 0,
          "format": "short",
          "logBase": 1,
          "show": true
        },
        {
          "$$hashKey": "object:235",
          "format": "short",
          "logBase": 1,
          "show": false
        }
      ],
      "yaxis": {
        "align": false
      }
    },
    {
      "datasource": "${DS_LOKI}",
      "description": "",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "displayMode": "auto",
            "filterable": false,
            "inspect": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "Count"
            },
            "properties": [
              {
                "id": "custom.displayMode",
                "value": "gradient-gauge"
              },
              {
                "id": "color",
                "value": {
                  "mode": "continuous-YlRd"
                }
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 8,
        "w": 8,
        "x": 0,
        "y": 7
      },
      "id": 13,
      "interval": "30ms",
      "options": {
        "footer": {
          "fields": "",
          "reducer": [
            "sum"
          ],
          "show": false
        },
        "showHeader": true,
        "sortBy": [
          {
            "desc": true,
            "displayName": "Total"
          }
        ]
      },
      "pluginVersion": "9.0.0-pre",
      "targets": [
        {
          "expr": "topk(10, sum by (error) (count_over_time({kind=\"usage_insights\", datasource=\"${Datasource}\"} | json | error != \"\" [$__interval])))",
          "legendFormat": "{{error}}",
          "refId": "A"
        }
      ],
      "title": "Top 10 error types",
      "transformations": [
        {
          "id": "reduce",
          "options": {
            "includeTimeField": false,
            "mode": "seriesToRows",
            "reducers": [
              "sum"
            ]
          }
        },
        {
          "id": "organize",
          "options": {
            "excludeByName": {},
            "indexByName": {},
            "renameByName": {
              "Field": "Error Type",
              "Total": "Count"
            }
          }
        }
      ],
      "type": "table"
    },
    {
      "aliasColors": {
        "95th percentile": "blue",
        "max latency": "super-light-blue"
      },
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "datasource": "${DS_LOKI}",
      "description": "",
      "fieldConfig": {
        "defaults": {
          "unit": "ms"
        },
        "overrides": []
      },
      "fill": 5,
      "fillGradient": 9,
      "gridPos": {
        "h": 8,
        "w": 16,
        "x": 8,
        "y": 7
      },
      "hiddenSeries": false,
      "id": 9,
      "interval": "30",
      "legend": {
        "avg": false,
        "current": false,
        "max": false,
        "min": false,
        "show": true,
        "total": false,
        "values": false
      },
      "lines": true,
      "linewidth": 1,
      "nullPointMode": "null",
      "options": {
        "alertThreshold": true
      },
      "percentage": false,
      "pluginVersion": "9.0.0-pre",
      "pointradius": 2,
      "points": false,
      "renderer": "flot",
      "seriesOverrides": [
        {
          "$$hashKey": "object:232",
          "alias": "max latency",
          "dashes": true,
          "fillGradient": 3
        }
      ],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "targets": [
        {
          "expr": "quantile_over_time(0.95,{kind=\"usage_insights\", datasource=\"${Datasource}\"} | json | eventName=\"data-request\" | error=\"\" | unwrap duration [$__interval]) by (host)",
          "legendFormat": "95th percentile",
          "refId": "C"
        },
        {
          "expr": "max(max_over_time({kind=\"usage_insights\", datasource=\"${Datasource}\"} | json | eventName=\"data-request\" | error=\"\" | unwrap duration [$__interval])) by (host)",
          "legendFormat": "max latency",
          "refId": "D"
        }
      ],
      "thresholds": [],
      "timeRegions": [],
      "title": "95th percentile of Request Time",
      "tooltip": {
        "shared": false,
        "sort": 0,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "mode": "time",
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "$$hashKey": "object:178",
          "format": "ms",
          "logBase": 1,
          "min": "0",
          "show": true
        },
        {
          "$$hashKey": "object:179",
          "format": "short",
          "logBase": 1,
          "show": false
        }
      ],
      "yaxis": {
        "align": false
      }
    },
    {
      "datasource": "${DS_LOKI}",
      "description": "",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "displayMode": "auto",
            "filterable": false,
            "inspect": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "Error Count"
            },
            "properties": [
              {
                "id": "custom.displayMode",
                "value": "gradient-gauge"
              },
              {
                "id": "color",
                "value": {
                  "mode": "continuous-YlRd"
                }
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 8,
        "w": 8,
        "x": 0,
        "y": 15
      },
      "id": 14,
      "options": {
        "footer": {
          "fields": "",
          "reducer": [
            "sum"
          ],
          "show": false
        },
        "showHeader": true
      },
      "pluginVersion": "9.0.0-pre",
      "targets": [
        {
          "expr": "topk(10, sum by (username) (count_over_time({kind=\"usage_insights\", datasource=\"${Datasource}\"} | json | eventName=\"data-request\" | error!=\"\" [$__interval])))",
          "legendFormat": "{{username}}",
          "refId": "A"
        }
      ],
      "title": "Top 10 users with errors",
      "transformations": [
        {
          "id": "reduce",
          "options": {
            "reducers": [
              "sum"
            ]
          }
        },
        {
          "id": "organize",
          "options": {
            "excludeByName": {},
            "indexByName": {},
            "renameByName": {
              "Field": "Username",
              "Total": "Error Count"
            }
          }
        }
      ],
      "type": "table"
    },
    {
      "datasource": "${DS_LOKI}",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "displayMode": "auto",
            "filterable": false,
            "inspect": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "Query count"
            },
            "properties": [
              {
                "id": "custom.displayMode",
                "value": "gradient-gauge"
              },
              {
                "id": "color",
                "value": {
                  "mode": "continuous-BlPu"
                }
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 8,
        "w": 16,
        "x": 8,
        "y": 15
      },
      "id": 6,
      "options": {
        "footer": {
          "fields": "",
          "reducer": [
            "sum"
          ],
          "show": false
        },
        "showHeader": true
      },
      "pluginVersion": "9.0.0-pre",
      "targets": [
        {
          "expr": "topk(10, sum by (username) (count_over_time({kind=\"usage_insights\", datasource=\"${Datasource}\"} | json | eventName=\"data-request\" [$__interval])))",
          "legendFormat": "{{username}}",
          "refId": "A"
        }
      ],
      "title": "Top 10 users ",
      "transformations": [
        {
          "id": "reduce",
          "options": {
            "reducers": [
              "sum"
            ]
          }
        },
        {
          "id": "organize",
          "options": {
            "excludeByName": {},
            "indexByName": {},
            "renameByName": {
              "Field": "Username",
              "Total": "Query count"
            }
          }
        }
      ],
      "type": "table"
    }
  ],
  "refresh": "",
  "schemaVersion": 36,
  "style": "dark",
  "tags": [],
  "templating": {
    "list": [
      {
        "current": {
          "selected": true,
          "text": "-- Grafana --",
          "value": "-- Grafana --"
        },
        "datasource": {
          "type": "loki",
          "uid": "nKl5Cesnz"
        },
        "definition": "label_values({datasource=~\".+\"}, datasource)",
        "hide": 0,
        "includeAll": false,
        "label": "Datasource",
        "multi": false,
        "name": "Datasource",
        "options": [],
        "query": "label_values({datasource=~\".+\"}, datasource)",
        "refresh": 2,
        "regex": "",
        "skipUrlSync": false,
        "sort": 1,
        "tagValuesQuery": "",
        "tagsQuery": "",
        "type": "query",
        "useTags": false
      }
    ]
  },
  "time": {
    "from": "now-15m",
    "to": "now"
  },
  "timepicker": {},
  "timezone": "",
  "title": "Grafana Usage insights datasource details",
  "uid": "AEbrOO2Mz",
  "version": 4,
  "weekStart": ""
}