{
  "uid": "traffic-parrot-license-usage",
  "title": "License usage",
  "description": "Traffic Parrot licenses purchased, in use and refused, from the license server's /metrics endpoint. History starts when Prometheus first scrapes a license server started with metrics.enabled=true.",
  "tags": ["traffic-parrot"],
  "editable": true,
  "graphTooltip": 1,
  "schemaVersion": 38,
  "version": 1,
  "time": {"from": "now-7d", "to": "now"},
  "refresh": "1m",
  "timezone": "browser",
  "links": [
    {"type": "dashboards", "tags": ["traffic-parrot"], "asDropdown": false, "includeVars": false, "keepTime": true, "title": "", "icon": "external link", "targetBlank": false, "tooltip": ""}
  ],
  "templating": {
    "list": [
      {
        "type": "datasource",
        "name": "datasource",
        "label": "Data source",
        "query": "prometheus",
        "current": {},
        "options": [],
        "regex": "",
        "hide": 0,
        "refresh": 1,
        "multi": false,
        "includeAll": false
      },
      {
        "type": "query",
        "name": "job",
        "label": "License server",
        "description": "The Prometheus job that scrapes the license server.",
        "datasource": {"type": "prometheus", "uid": "${datasource}"},
        "definition": "label_values(tp_licences_purchased, job)",
        "query": "label_values(tp_licences_purchased, job)",
        "current": {},
        "options": [],
        "regex": "",
        "hide": 0,
        "refresh": 2,
        "sort": 1,
        "multi": false,
        "includeAll": false
      },
      {
        "type": "custom",
        "name": "group",
        "label": "Break down by",
        "description": "The team tag the breakdowns group by. Choose both to see each project of each team. To group by another tag, add it here and to the legends of the two grouped panels, which name project and team.",
        "query": "project,team",
        "current": {"selected": true, "text": ["project"], "value": ["project"]},
        "options": [
          {"selected": true, "text": "project", "value": "project"},
          {"selected": false, "text": "team", "value": "team"}
        ],
        "hide": 0,
        "multi": true,
        "includeAll": false
      }
    ]
  },
  "panels": [
    {
      "id": 1,
      "type": "stat",
      "title": "Licenses purchased",
      "description": "Licenses the license server's usage license allows.",
      "datasource": {"type": "prometheus", "uid": "${datasource}"},
      "gridPos": {"h": 4, "w": 5, "x": 0, "y": 0},
      "fieldConfig": {
        "defaults": {"unit": "none", "decimals": 0, "noValue": "No data from this license server"},
        "overrides": []
      },
      "options": {"reduceOptions": {"calcs": ["lastNotNull"], "fields": "", "values": false}, "colorMode": "none", "graphMode": "none", "textMode": "value", "justifyMode": "auto", "orientation": "auto"},
      "targets": [
        {"refId": "A", "datasource": {"type": "prometheus", "uid": "${datasource}"}, "expr": "max(tp_licences_purchased{job=\"$job\"})", "instant": true, "range": false, "legendFormat": "Purchased"}
      ]
    },
    {
      "id": 2,
      "type": "stat",
      "title": "In use now",
      "description": "Licenses checked out now. An instance that stopped without checking its license in is counted for up to about 7 minutes: a license times out after 5 minutes without a keep-alive, checked every minute.",
      "datasource": {"type": "prometheus", "uid": "${datasource}"},
      "gridPos": {"h": 4, "w": 5, "x": 5, "y": 0},
      "fieldConfig": {
        "defaults": {"unit": "none", "decimals": 0, "noValue": "No data from this license server"},
        "overrides": []
      },
      "options": {"reduceOptions": {"calcs": ["lastNotNull"], "fields": "", "values": false}, "colorMode": "none", "graphMode": "none", "textMode": "value", "justifyMode": "auto", "orientation": "auto"},
      "targets": [
        {"refId": "A", "datasource": {"type": "prometheus", "uid": "${datasource}"}, "expr": "sum(tp_licences_in_use{job=\"$job\"}) or (0 * max(tp_licences_purchased{job=\"$job\"}))", "instant": true, "range": false, "legendFormat": "In use"}
      ]
    },
    {
      "id": 3,
      "type": "stat",
      "title": "In use, % of purchased",
      "description": "Licenses in use now as a percentage of those purchased. It can pass 100 under a license that does not enforce its limit, where instances check out more licenses than were purchased.",
      "datasource": {"type": "prometheus", "uid": "${datasource}"},
      "gridPos": {"h": 4, "w": 5, "x": 10, "y": 0},
      "fieldConfig": {
        "defaults": {"unit": "percent", "decimals": 0, "noValue": "No data from this license server", "color": {"mode": "thresholds"}, "thresholds": {"mode": "absolute", "steps": [{"color": "green", "value": null}, {"color": "orange", "value": 80}, {"color": "red", "value": 100}]}},
        "overrides": []
      },
      "options": {"reduceOptions": {"calcs": ["lastNotNull"], "fields": "", "values": false}, "colorMode": "background", "graphMode": "none", "textMode": "value", "justifyMode": "auto", "orientation": "auto"},
      "targets": [
        {"refId": "A", "datasource": {"type": "prometheus", "uid": "${datasource}"}, "expr": "100 * (sum(tp_licences_in_use{job=\"$job\"}) or (0 * max(tp_licences_purchased{job=\"$job\"}))) / max(tp_licences_purchased{job=\"$job\"})", "instant": true, "range": false, "legendFormat": "In use, %"}
      ]
    },
    {
      "id": 4,
      "type": "stat",
      "title": "Peak in use",
      "description": "The most licenses in use at once in the dashboard's time range, sampled every minute.",
      "datasource": {"type": "prometheus", "uid": "${datasource}"},
      "gridPos": {"h": 4, "w": 5, "x": 15, "y": 0},
      "fieldConfig": {
        "defaults": {"unit": "none", "decimals": 0, "noValue": "No data from this license server"},
        "overrides": []
      },
      "options": {"reduceOptions": {"calcs": ["lastNotNull"], "fields": "", "values": false}, "colorMode": "none", "graphMode": "none", "textMode": "value", "justifyMode": "auto", "orientation": "auto"},
      "targets": [
        {"refId": "A", "datasource": {"type": "prometheus", "uid": "${datasource}"}, "expr": "max_over_time((sum(tp_licences_in_use{job=\"$job\"}) or (0 * max(tp_licences_purchased{job=\"$job\"})))[$__range:1m])", "instant": true, "range": false, "legendFormat": "Peak"}
      ]
    },
    {
      "id": 5,
      "type": "stat",
      "title": "Refused check-outs",
      "description": "Check-outs the license server refused in the dashboard's time range because no license was free. Refusals happen only under a license that enforces its limit, so under any other license this stays at 0. Not counted: a refusal by a license server that is not activated, and the first refusal of a project or team that holds no license at that moment.",
      "datasource": {"type": "prometheus", "uid": "${datasource}"},
      "gridPos": {"h": 4, "w": 4, "x": 20, "y": 0},
      "fieldConfig": {
        "defaults": {"unit": "none", "decimals": 0, "noValue": "No data from this license server"},
        "overrides": []
      },
      "options": {"reduceOptions": {"calcs": ["lastNotNull"], "fields": "", "values": false}, "colorMode": "none", "graphMode": "none", "textMode": "value", "justifyMode": "auto", "orientation": "auto"},
      "targets": [
        {"refId": "A", "datasource": {"type": "prometheus", "uid": "${datasource}"}, "expr": "round(sum(increase(tp_licence_rejections_total{job=\"$job\"}[$__range]))) or (0 * max(tp_licences_purchased{job=\"$job\"}))", "instant": true, "range": false, "legendFormat": "Refused"}
      ]
    },
    {
      "id": 6,
      "type": "timeseries",
      "title": "Licenses in use and purchased",
      "description": "An instance that stopped without checking its license in is counted for up to about 7 minutes. In use can pass purchased under a license that does not enforce its limit.",
      "datasource": {"type": "prometheus", "uid": "${datasource}"},
      "gridPos": {"h": 9, "w": 12, "x": 0, "y": 4},
      "fieldConfig": {
        "defaults": {
          "unit": "none",
          "decimals": 0,
          "min": 0,
          "color": {"mode": "palette-classic-by-name"},
          "custom": {"drawStyle": "line", "lineInterpolation": "stepAfter", "lineWidth": 2, "fillOpacity": 0, "showPoints": "never", "spanNulls": false, "stacking": {"mode": "none", "group": "A"}, "axisLabel": "Licenses"}
        },
        "overrides": [
          {"matcher": {"id": "byName", "options": "Purchased"}, "properties": [{"id": "custom.lineStyle", "value": {"fill": "dash", "dash": [10, 10]}}]}
        ]
      },
      "options": {"legend": {"displayMode": "list", "placement": "bottom", "showLegend": true}, "tooltip": {"mode": "multi", "sort": "desc"}},
      "targets": [
        {"refId": "A", "datasource": {"type": "prometheus", "uid": "${datasource}"}, "expr": "sum(tp_licences_in_use{job=\"$job\"}) or (0 * max(tp_licences_purchased{job=\"$job\"}))", "range": true, "instant": false, "legendFormat": "In use"},
        {"refId": "B", "datasource": {"type": "prometheus", "uid": "${datasource}"}, "expr": "max(tp_licences_purchased{job=\"$job\"})", "range": true, "instant": false, "legendFormat": "Purchased"}
      ]
    },
    {
      "id": 7,
      "type": "timeseries",
      "title": "Licenses in use by ${group:text}",
      "description": "Licenses in use, stacked by the tag chosen in Break down by. An instance with no project tag counts under the project it reports, or none. Once any instance sends a team tag, one without it counts under team none.",
      "datasource": {"type": "prometheus", "uid": "${datasource}"},
      "gridPos": {"h": 9, "w": 12, "x": 12, "y": 4},
      "fieldConfig": {
        "defaults": {
          "unit": "none",
          "decimals": 0,
          "min": 0,
          "noValue": "No licenses in use, or no data from this license server",
          "color": {"mode": "palette-classic-by-name"},
          "custom": {"drawStyle": "line", "lineInterpolation": "stepAfter", "lineWidth": 1, "fillOpacity": 60, "showPoints": "never", "spanNulls": false, "stacking": {"mode": "normal", "group": "A"}, "axisLabel": "Licenses"}
        },
        "overrides": []
      },
      "options": {"legend": {"displayMode": "list", "placement": "bottom", "showLegend": true}, "tooltip": {"mode": "multi", "sort": "desc"}},
      "targets": [
        {"refId": "A", "datasource": {"type": "prometheus", "uid": "${datasource}"}, "expr": "sum by (${group:csv}) (tp_licences_in_use{job=\"$job\"})", "range": true, "instant": false, "legendFormat": "{{project}} {{team}}"}
      ]
    },
    {
      "id": 8,
      "type": "timeseries",
      "title": "Refused check-outs by ${group:text}",
      "description": "Check-outs refused because no license was free, per bar (3 minutes or more, with the time range), by the tag chosen in Break down by. Refusals happen only under a license that enforces its limit. Not counted: a refusal by a license server that is not activated, and the first refusal of a project or team that holds no license at that moment.",
      "datasource": {"type": "prometheus", "uid": "${datasource}"},
      "gridPos": {"h": 9, "w": 12, "x": 0, "y": 13},
      "interval": "3m",
      "fieldConfig": {
        "defaults": {
          "unit": "none",
          "decimals": 0,
          "min": 0,
          "noValue": "No refusals, or no data from this license server",
          "color": {"mode": "palette-classic-by-name"},
          "custom": {"drawStyle": "bars", "lineWidth": 1, "fillOpacity": 80, "showPoints": "never", "spanNulls": false, "stacking": {"mode": "normal", "group": "A"}, "axisLabel": "Refusals", "axisSoftMax": 1}
        },
        "overrides": []
      },
      "options": {"legend": {"displayMode": "list", "placement": "bottom", "showLegend": true}, "tooltip": {"mode": "multi", "sort": "desc"}},
      "targets": [
        {"refId": "A", "datasource": {"type": "prometheus", "uid": "${datasource}"}, "expr": "sum by (${group:csv}) (increase(tp_licence_rejections_total{job=\"$job\"}[$__rate_interval]))", "range": true, "instant": false, "legendFormat": "{{project}} {{team}}"}
      ]
    },
    {
      "id": 9,
      "type": "table",
      "title": "By ${group:text}",
      "description": "For each value of the tag chosen in Break down by: licenses in use now, the most in use at once in the time range (sampled every minute), and check-outs refused in the time range.",
      "datasource": {"type": "prometheus", "uid": "${datasource}"},
      "gridPos": {"h": 9, "w": 12, "x": 12, "y": 13},
      "fieldConfig": {
        "defaults": {"unit": "none", "decimals": 0, "noValue": "No licenses used in this time range, or no data from this license server", "custom": {"align": "auto", "minWidth": 80}},
        "overrides": [
          {"matcher": {"id": "byName", "options": "In use now"}, "properties": [{"id": "noValue", "value": "0"}, {"id": "custom.width", "value": 110}]},
          {"matcher": {"id": "byName", "options": "Peak in range"}, "properties": [{"id": "noValue", "value": "0"}, {"id": "custom.width", "value": 120}]},
          {"matcher": {"id": "byName", "options": "Refused in range"}, "properties": [{"id": "noValue", "value": "0"}, {"id": "custom.width", "value": 140}]}
        ]
      },
      "options": {"showHeader": true, "cellHeight": "sm", "footer": {"show": false, "reducer": ["sum"], "fields": ""}},
      "targets": [
        {"refId": "A", "datasource": {"type": "prometheus", "uid": "${datasource}"}, "expr": "sum by (${group:csv}) (tp_licences_in_use{job=\"$job\"})", "format": "table", "instant": true, "range": false},
        {"refId": "B", "datasource": {"type": "prometheus", "uid": "${datasource}"}, "expr": "max_over_time((sum by (${group:csv}) (tp_licences_in_use{job=\"$job\"}))[$__range:1m])", "format": "table", "instant": true, "range": false},
        {"refId": "C", "datasource": {"type": "prometheus", "uid": "${datasource}"}, "expr": "round(sum by (${group:csv}) (increase(tp_licence_rejections_total{job=\"$job\"}[$__range])))", "format": "table", "instant": true, "range": false}
      ],
      "transformations": [
        {"id": "merge", "options": {}},
        {"id": "organize", "options": {"excludeByName": {"Time": true}, "indexByName": {}, "renameByName": {"Value #A": "In use now", "Value #B": "Peak in range", "Value #C": "Refused in range"}}}
      ]
    }
  ]
}
