Grafana dashboard: Usage insights

Grafana Usage insights overview for use with the Loki datasource

Works in conjunction with the datasource details dashboard: 

https://grafana.com/grafana/dashboards/13786

{
  "__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": ""
    },
    {
      "type": "datasource",
      "id": "testdata",
      "name": "TestData DB",
      "version": "1.0.0"
    }
  ],
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": "-- Grafana --",
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "type": "dashboard"
      }
    ]
  },
  "editable": true,
  "gnetId": 13785,
  "graphTooltip": 0,
  "id": null,
  "links": [
    {
      "icon": "dashboard",
      "tags": [],
      "title": "Usage insights per datasource",
      "tooltip": "",
      "type": "link",
      "url": "/d/AEbrOO2Mz/usage-insights-for-datasource"
    }
  ],
  "panels": [
    {
      "collapsed": false,
      "datasource": null,
      "gridPos": {
        "h": 1,
        "w": 24,
        "x": 0,
        "y": 0
      },
      "id": 31,
      "panels": [],
      "title": "Usage Insight KPI",
      "type": "row"
    },
    {
      "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": 4,
        "w": 6,
        "x": 0,
        "y": 1
      },
      "id": 25,
      "interval": "23.9h",
      "options": {
        "colorMode": "background",
        "graphMode": "area",
        "justifyMode": "center",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "last"
          ],
          "fields": "",
          "values": false
        },
        "text": {},
        "textMode": "value"
      },
      "pluginVersion": "9.0.0-pre",
      "targets": [
        {
          "expr": "sum(count_over_time({kind=\"usage_insights\"}[$__interval])) ",
          "legendFormat": "",
          "refId": "A"
        }
      ],
      "timeFrom": "24h",
      "title": "Total usage insights events  ",
      "transformations": [
        {
          "id": "reduce",
          "options": {
            "reducers": [
              "sum"
            ]
          }
        }
      ],
      "type": "stat"
    },
    {
      "datasource": "${DS_LOKI}",
      "description": "",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "purple",
                "value": null
              }
            ]
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "Requests"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 100
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 4,
        "w": 6,
        "x": 6,
        "y": 1
      },
      "id": 27,
      "interval": "4.9m",
      "options": {
        "colorMode": "background",
        "graphMode": "none",
        "justifyMode": "auto",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "sum"
          ],
          "fields": "",
          "values": false
        },
        "text": {},
        "textMode": "value"
      },
      "pluginVersion": "9.0.0-pre",
      "targets": [
        {
          "expr": "count(sum by (datasourceId) (count_over_time({kind=\"usage_insights\"} | json |  error=\"\" [5m])))  ",
          "legendFormat": "",
          "refId": "A"
        }
      ],
      "timeFrom": "5m",
      "title": "Datasources in use right now",
      "transformations": [],
      "type": "stat"
    },
    {
      "datasource": "${DS_LOKI}",
      "description": "",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "purple",
                "value": null
              }
            ]
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "Requests"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 100
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 4,
        "w": 6,
        "x": 12,
        "y": 1
      },
      "id": 28,
      "interval": "4.9m",
      "options": {
        "colorMode": "background",
        "graphMode": "none",
        "justifyMode": "auto",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "max"
          ],
          "fields": "",
          "values": false
        },
        "text": {},
        "textMode": "value"
      },
      "pluginVersion": "9.0.0-pre",
      "targets": [
        {
          "expr": "count(sum by (dashboardId) (count_over_time({kind=\"usage_insights\"} | json |  error=\"\" [5m])))",
          "legendFormat": "",
          "refId": "A"
        }
      ],
      "timeFrom": "5m",
      "title": "Dashboards in use right now",
      "transformations": [],
      "type": "stat"
    },
    {
      "datasource": "${DS_LOKI}",
      "description": "",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": null
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "purple",
                "value": null
              }
            ]
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "Requests"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 100
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 4,
        "w": 6,
        "x": 18,
        "y": 1
      },
      "id": 29,
      "interval": "4.9m",
      "options": {
        "colorMode": "background",
        "graphMode": "none",
        "justifyMode": "auto",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "max"
          ],
          "fields": "",
          "values": false
        },
        "text": {},
        "textMode": "value"
      },
      "pluginVersion": "9.0.0-pre",
      "targets": [
        {
          "expr": "count(sum by (userId) (count_over_time({kind=\"usage_insights\"} | json |  error=\"\" [5m])))",
          "legendFormat": "",
          "refId": "A"
        }
      ],
      "timeFrom": "5m",
      "title": "Users right now",
      "transformations": [],
      "type": "stat"
    },
    {
      "collapsed": false,
      "datasource": "",
      "gridPos": {
        "h": 1,
        "w": 24,
        "x": 0,
        "y": 5
      },
      "id": 16,
      "panels": [],
      "title": "Usage Insight Details",
      "type": "row"
    },
    {
      "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}",
      "fieldConfig": {
        "defaults": {
          "unit": "short"
        },
        "overrides": []
      },
      "fill": 1,
      "fillGradient": 0,
      "gridPos": {
        "h": 8,
        "w": 24,
        "x": 0,
        "y": 6
      },
      "hiddenSeries": false,
      "id": 10,
      "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": "PDDA8E780A17E7EF1"
          },
          "expr": "sum by(host) (count_over_time({kind=\"usage_insights\"} | json | eventName=\"data-request\" | error = \"\" [$__interval]))",
          "legendFormat": "Data Requests from {{host}}",
          "refId": "A"
        },
        {
          "datasource": {
            "type": "loki",
            "uid": "PDDA8E780A17E7EF1"
          },
          "expr": "sum by(host) (count_over_time({kind=\"usage_insights\"} | json | eventName=\"data-request\" | error != \"\" [$__interval]))",
          "legendFormat": "Data Requests errors from {{host}}",
          "refId": "B"
        },
        {
          "datasource": {
            "type": "loki",
            "uid": "PDDA8E780A17E7EF1"
          },
          "expr": "sum by(host) (count_over_time({kind=\"usage_insights\"} | json | eventName=\"dashboard-view\" [$__interval]))",
          "legendFormat": "Dashboard views from  {{host}}",
          "refId": "C"
        },
        {
          "datasource": {
            "type": "loki",
            "uid": "PDDA8E780A17E7EF1"
          },
          "expr": "sum by (eventName)  (\n  sum_over_time(\n    {kind=\"usage_insights\"} \n    | json \n    | eventName = \"data-request\" \n    | cachedQueries > 0\n    | unwrap cachedQueries [$__interval]\n  )\n)",
          "hide": false,
          "legendFormat": "Cached Queries",
          "refId": "D"
        },
        {
          "datasource": {
            "type": "loki",
            "uid": "PDDA8E780A17E7EF1"
          },
          "expr": "sum by (eventName) (\n  sum_over_time(\n    {kind=\"usage_insights\"} \n    | json \n    | eventName = \"data-request\" \n    | totalQueries > 0\n    | unwrap totalQueries [$__interval]\n  )\n)",
          "hide": false,
          "legendFormat": "Total Queries",
          "refId": "E"
        }
      ],
      "thresholds": [],
      "timeRegions": [],
      "title": "Usage insights events",
      "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}",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": "auto",
            "displayMode": "auto",
            "filterable": false,
            "inspect": false
          },
          "links": [],
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "Views"
            },
            "properties": [
              {
                "id": "custom.displayMode",
                "value": "gradient-gauge"
              },
              {
                "id": "color",
                "value": {
                  "mode": "continuous-BlPu"
                }
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 7,
        "w": 9,
        "x": 0,
        "y": 14
      },
      "id": 18,
      "interval": "",
      "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 (dashboardId,dashboardName,folderName) (count_over_time({kind=\"usage_insights\"} | json | eventName=\"data-request\" [$__interval])))",
          "legendFormat": "{{dashboardName}} - {{folderName}}",
          "refId": "A"
        }
      ],
      "timeFrom": "24h",
      "title": "Top 10 dashboards",
      "transformations": [
        {
          "id": "reduce",
          "options": {
            "includeTimeField": false,
            "mode": "seriesToRows",
            "reducers": [
              "sum"
            ]
          }
        },
        {
          "id": "organize",
          "options": {
            "excludeByName": {},
            "indexByName": {},
            "renameByName": {
              "Field": "Dashboard - Folder",
              "Total": "Views"
            }
          }
        }
      ],
      "type": "table"
    },
    {
      "datasource": "${DS_LOKI}",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": "auto",
            "displayMode": "auto",
            "filterable": false,
            "inspect": false
          },
          "links": [
            {
              "title": "Go to datasource usage insights",
              "url": "/d/AEbrOO2Mz/usage-insights-for-datasource?var-Datasource=${__value.text:percentencode}"
            }
          ],
          "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": 7,
        "w": 9,
        "x": 9,
        "y": 14
      },
      "id": 20,
      "interval": "",
      "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 (datasourceName) (count_over_time({kind=\"usage_insights\"} | json | eventName=\"data-request\" [$__interval])))",
          "legendFormat": "{{datasourceName}}",
          "refId": "A"
        }
      ],
      "timeFrom": "24h",
      "title": "Top 10 data sources",
      "transformations": [
        {
          "id": "reduce",
          "options": {
            "reducers": [
              "sum"
            ]
          }
        },
        {
          "id": "organize",
          "options": {
            "excludeByName": {},
            "indexByName": {},
            "renameByName": {
              "Field": "Datasource",
              "Total": "Query Count"
            }
          }
        }
      ],
      "type": "table"
    },
    {
      "datasource": "${DS_LOKI}",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": "auto",
            "displayMode": "auto",
            "filterable": false,
            "inspect": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "Views"
            },
            "properties": [
              {
                "id": "custom.displayMode",
                "value": "gradient-gauge"
              },
              {
                "id": "color",
                "value": {
                  "mode": "continuous-BlPu"
                }
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 7,
        "w": 6,
        "x": 18,
        "y": 14
      },
      "id": 22,
      "interval": "",
      "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\"} | json | eventName=\"data-request\" [$__interval])))",
          "legendFormat": "{{username}}",
          "refId": "A"
        }
      ],
      "timeFrom": "24h",
      "title": "Top 10 users",
      "transformations": [
        {
          "id": "reduce",
          "options": {
            "reducers": [
              "sum"
            ]
          }
        },
        {
          "id": "organize",
          "options": {
            "excludeByName": {},
            "indexByName": {},
            "renameByName": {
              "Field": "Username",
              "Total": "Views"
            }
          }
        }
      ],
      "type": "table"
    },
    {
      "datasource": "${DS_LOKI}",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": "auto",
            "displayMode": "auto",
            "filterable": false,
            "inspect": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              }
            ]
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "Error Count"
            },
            "properties": [
              {
                "id": "custom.displayMode",
                "value": "gradient-gauge"
              },
              {
                "id": "color",
                "value": {
                  "mode": "continuous-YlRd"
                }
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 7,
        "w": 9,
        "x": 0,
        "y": 21
      },
      "id": 19,
      "interval": "",
      "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 (dashboardId,dashboardName,folderName) (count_over_time({kind=\"usage_insights\"} | json | eventName=\"data-request\" | error!=\"\" [$__interval])))",
          "legendFormat": "{{dashboardName}} - {{folderName}}",
          "refId": "A"
        }
      ],
      "timeFrom": "24h",
      "title": "Top 10 dashboards with errors",
      "transformations": [
        {
          "id": "reduce",
          "options": {
            "reducers": [
              "sum"
            ]
          }
        },
        {
          "id": "organize",
          "options": {
            "excludeByName": {},
            "indexByName": {},
            "renameByName": {
              "Field": "Dashboard - Folder",
              "Total": "Error Count"
            }
          }
        }
      ],
      "type": "table"
    },
    {
      "datasource": "${DS_LOKI}",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": "auto",
            "displayMode": "auto",
            "filterable": false,
            "inspect": false
          },
          "links": [
            {
              "title": "Go to datasource insights",
              "url": "/d/AEbrOO2Mz/usage-insights-for-datasource?var-Datasource=${__value.text:percentencode}"
            }
          ],
          "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": 7,
        "w": 9,
        "x": 9,
        "y": 21
      },
      "id": 21,
      "interval": "",
      "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 (datasourceName) (count_over_time({kind=\"usage_insights\"} | json | eventName=\"data-request\" | error!=\"\" [$__interval])))",
          "legendFormat": "{{datasourceName}}",
          "refId": "A"
        }
      ],
      "timeFrom": "24h",
      "title": "Top 10 data sources with errors",
      "transformations": [
        {
          "id": "reduce",
          "options": {
            "reducers": [
              "sum"
            ]
          }
        },
        {
          "id": "organize",
          "options": {
            "excludeByName": {},
            "indexByName": {},
            "renameByName": {
              "Field": "Datasource",
              "Total": "Error Count"
            }
          }
        }
      ],
      "type": "table"
    },
    {
      "datasource": "${DS_LOKI}",
      "description": "",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": "auto",
            "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": 7,
        "w": 6,
        "x": 18,
        "y": 21
      },
      "id": 23,
      "interval": "",
      "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\"} | json | eventName=\"data-request\" | error!=\"\" [$__interval])))",
          "legendFormat": "{{username}}",
          "refId": "A"
        }
      ],
      "timeFrom": "24h",
      "title": "Top 10 users seeing errors",
      "transformations": [
        {
          "id": "reduce",
          "options": {
            "reducers": [
              "sum"
            ]
          }
        },
        {
          "id": "organize",
          "options": {
            "excludeByName": {},
            "indexByName": {},
            "renameByName": {
              "Field": "Username",
              "Total": "Error count"
            }
          }
        }
      ],
      "type": "table"
    }
  ],
  "refresh": "",
  "schemaVersion": 36,
  "style": "dark",
  "tags": [],
  "templating": {
    "list": []
  },
  "time": {
    "from": "now-15m",
    "to": "now"
  },
  "timepicker": {},
  "timezone": "",
  "title": "Usage insights",
  "uid": "XU8HAD5Gk",
  "version": 12,
  "weekStart": ""
}