Grafana dashboard: Grafana active users

This dashboard is based on Grafana audit logging data hosted in Loki. It shows the number of active users in Grafana by the user's licensed role (Viewer or Editor/Admin).

This dashboard only applies to Grafana Enterprise, and it relies on [audit logs exported to Loki](https://grafana.com/docs/grafana/latest/enterprise/auditing/).

Important: this dashboard does not account for users that have been deleted from Grafana, which might lead to some discrepancies between this information and the information on the Licensing page in Grafana. In those cases, the Licensing page is correct.

See more information on licensing in the [Grafana docs](https://grafana.com/docs/grafana/latest/enterprise/license/license-restrictions/).

{
  "__inputs": [
    {
      "name": "DS_LOKI",
      "label": "Loki",
      "description": "",
      "type": "datasource",
      "pluginId": "loki",
      "pluginName": "Loki"
    }
  ],
  "__requires": [
    {
      "type": "grafana",
      "id": "grafana",
      "name": "Grafana",
      "version": "7.5.0-beta2"
    },
    {
      "type": "panel",
      "id": "graph",
      "name": "Graph",
      "version": ""
    },
    {
      "type": "panel",
      "id": "logs",
      "name": "Logs",
      "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": "panel",
      "id": "text",
      "name": "Text",
      "version": ""
    }
  ],
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": "-- Grafana --",
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "type": "dashboard"
      }
    ]
  },
  "editable": true,
  "gnetId": 14490,
  "graphTooltip": 0,
  "id": null,
  "links": [],
  "panels": [
    {
      "collapsed": true,
      "datasource": "${DS_LOKI}",
      "gridPos": {
        "h": 1,
        "w": 24,
        "x": 0,
        "y": 0
      },
      "id": 11,
      "panels": [
        {
          "datasource": "${DS_LOKI}",
          "fieldConfig": {
            "defaults": {},
            "overrides": []
          },
          "gridPos": {
            "h": 4,
            "w": 24,
            "x": 0,
            "y": 1
          },
          "id": 9,
          "options": {
            "content": "This dashboard shows the number of active users in Grafana, based on Grafana's audit logs. \n\nThis dashboard only applies to Grafana Enterprise, and it relies on [audit logs exported to Loki](https://grafana.com/docs/grafana/latest/enterprise/auditing/).\n\nImportant note: this dashboard does not account for users that have been deleted from Grafana, which might lead to differences between this information and the information on the Licensing page in Grafana. In those cases, the Licensing page is correct.\n\nFor information on active users and licensed roles, see [Grafana's docs](https://grafana.com/docs/grafana/latest/enterprise/license/license-restrictions/).",
            "mode": "markdown"
          },
          "pluginVersion": "7.5.0-beta2",
          "timeFrom": null,
          "timeShift": null,
          "type": "text"
        }
      ],
      "title": "About this dashboard",
      "type": "row"
    },
    {
      "collapsed": false,
      "datasource": "${DS_LOKI}",
      "gridPos": {
        "h": 1,
        "w": 24,
        "x": 0,
        "y": 1
      },
      "id": 13,
      "panels": [],
      "title": "Data",
      "type": "row"
    },
    {
      "datasource": "${DS_LOKI}",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "light-blue",
                "value": null
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 6,
        "x": 0,
        "y": 2
      },
      "id": 6,
      "options": {
        "colorMode": "value",
        "graphMode": "area",
        "justifyMode": "auto",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "text": {},
        "textMode": "auto"
      },
      "pluginVersion": "7.5.0-beta2",
      "targets": [
        {
          "expr": "count(sum(count_over_time({kind=\"auditing\"} | json | action=\"billing-information\" additionalData_billing_role=\"server_admin\" [30d])) by (user_username))",
          "hide": false,
          "legendFormat": "server admins",
          "refId": "Server Admins"
        },
        {
          "expr": "count(sum(count_over_time({kind=\"auditing\"} | json | action=\"billing-information\" additionalData_billing_role=\"admin\" [30d])) by (user_username))",
          "hide": false,
          "legendFormat": "org admins",
          "refId": "Org Admins"
        },
        {
          "expr": "count(sum(count_over_time({kind=\"auditing\"} | json | action=\"billing-information\" additionalData_billing_role=\"editor\" [30d])) by (user_username))",
          "hide": false,
          "legendFormat": "editors",
          "refId": "Editors"
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "Current active editor/admins",
      "transformations": [
        {
          "id": "calculateField",
          "options": {
            "alias": "Editor/Admins",
            "mode": "reduceRow",
            "reduce": {
              "include": [
                "org admins",
                "server admins",
                "editors"
              ],
              "reducer": "sum"
            },
            "replaceFields": true
          }
        }
      ],
      "transparent": true,
      "type": "stat"
    },
    {
      "datasource": "${DS_LOKI}",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "light-green",
                "value": null
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 6,
        "x": 6,
        "y": 2
      },
      "id": 7,
      "options": {
        "colorMode": "value",
        "graphMode": "area",
        "justifyMode": "auto",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "text": {},
        "textMode": "auto"
      },
      "pluginVersion": "7.5.0-beta2",
      "targets": [
        {
          "expr": "count(sum(count_over_time({kind=\"auditing\"} | json | action=\"billing-information\" additionalData_billing_role=\"viewer\" [30d])) by (user_username))",
          "hide": false,
          "instant": false,
          "legendFormat": "viewers",
          "range": true,
          "refId": "Viewers"
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "Current active viewers",
      "transformations": [],
      "transparent": true,
      "type": "stat"
    },
    {
      "datasource": "${DS_LOKI}",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": null,
            "filterable": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 28,
        "w": 11,
        "x": 12,
        "y": 2
      },
      "id": 3,
      "maxDataPoints": null,
      "options": {
        "frameIndex": 2,
        "showHeader": true,
        "sortBy": []
      },
      "pluginVersion": "7.5.0-beta2",
      "targets": [
        {
          "expr": "sum by (user_username, additionalData_billing_role) (\n  count_over_time (\n    {kind=\"auditing\"} | json | action=\"billing-information\" \n    [30d]\n  )\n)",
          "instant": true,
          "range": false,
          "refId": "A"
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "Current active users",
      "transformations": [
        {
          "id": "organize",
          "options": {
            "excludeByName": {
              "Time": true
            },
            "indexByName": {},
            "renameByName": {
              "Value #A": "Logins, past 30 days",
              "additionalData_billing_role": "Licensed role",
              "user_username": "Username"
            }
          }
        }
      ],
      "type": "table"
    },
    {
      "aliasColors": {
        "editor/admins": "light-blue",
        "viewers": "light-green"
      },
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "datasource": "${DS_LOKI}",
      "fieldConfig": {
        "defaults": {
          "unit": "short"
        },
        "overrides": []
      },
      "fill": 7,
      "fillGradient": 0,
      "gridPos": {
        "h": 9,
        "w": 12,
        "x": 0,
        "y": 10
      },
      "hiddenSeries": false,
      "id": 2,
      "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": "7.5.0-beta2",
      "pointradius": 2,
      "points": false,
      "renderer": "flot",
      "seriesOverrides": [],
      "spaceLength": 10,
      "stack": true,
      "steppedLine": false,
      "targets": [
        {
          "expr": "count(sum(count_over_time({kind=\"auditing\"} | json | action=\"billing-information\" additionalData_billing_role=\"viewer\" [30d])) by (user_username))",
          "hide": false,
          "instant": false,
          "legendFormat": "viewers",
          "range": true,
          "refId": "Viewers"
        },
        {
          "expr": "count(sum(count_over_time({kind=\"auditing\"} | json | action=\"billing-information\" additionalData_billing_role=\"server_admin\" [30d])) by (user_username))",
          "hide": false,
          "legendFormat": "grafana admins",
          "refId": "Server Admins"
        },
        {
          "expr": "count(sum(count_over_time({kind=\"auditing\"} | json | action=\"billing-information\" additionalData_billing_role=\"admin\" [30d])) by (user_username))",
          "hide": false,
          "legendFormat": "org admins",
          "refId": "Org Admins"
        },
        {
          "expr": "count(sum(count_over_time({kind=\"auditing\"} | json | action=\"billing-information\" additionalData_billing_role=\"editor\" [30d])) by (user_username))",
          "hide": false,
          "legendFormat": "editors",
          "refId": "Editors"
        }
      ],
      "thresholds": [],
      "timeFrom": null,
      "timeRegions": [],
      "timeShift": null,
      "title": "Active users over time, by licensed role",
      "tooltip": {
        "shared": true,
        "sort": 0,
        "value_type": "individual"
      },
      "transformations": [
        {
          "id": "calculateField",
          "options": {
            "alias": "editor/admins",
            "binary": {
              "left": "editors",
              "operator": "+",
              "reducer": "sum",
              "right": "grafana admins"
            },
            "mode": "reduceRow",
            "reduce": {
              "include": [
                "grafana admins",
                "org admins",
                "editors"
              ],
              "reducer": "sum"
            },
            "replaceFields": false
          }
        },
        {
          "id": "organize",
          "options": {
            "excludeByName": {
              "editors": true,
              "grafana admins": true,
              "org admins": true
            },
            "indexByName": {},
            "renameByName": {}
          }
        }
      ],
      "type": "graph",
      "xaxis": {
        "buckets": null,
        "mode": "time",
        "name": null,
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "$$hashKey": "object:101",
          "format": "short",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": "0",
          "show": true
        },
        {
          "$$hashKey": "object:102",
          "format": "short",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        }
      ],
      "yaxis": {
        "align": false,
        "alignLevel": null
      }
    },
    {
      "datasource": "${DS_LOKI}",
      "description": "Logs that update the active status and licensed role of a user.",
      "fieldConfig": {
        "defaults": {},
        "overrides": []
      },
      "gridPos": {
        "h": 11,
        "w": 12,
        "x": 0,
        "y": 19
      },
      "id": 5,
      "options": {
        "dedupStrategy": "none",
        "showLabels": false,
        "showTime": false,
        "sortOrder": "Descending",
        "wrapLogMessage": false
      },
      "pluginVersion": "7.5.0-beta2",
      "targets": [
        {
          "expr": "{kind=\"auditing\"} | json | action=\"billing-information\"",
          "hide": false,
          "refId": "A"
        }
      ],
      "title": "Active user status logs",
      "type": "logs"
    }
  ],
  "schemaVersion": 27,
  "style": "dark",
  "tags": [],
  "templating": {
    "list": []
  },
  "time": {
    "from": "now-6h",
    "to": "now"
  },
  "timepicker": {},
  "timezone": "",
  "title": "Grafana active users",
  "uid": "active-users",
  "version": 14
}