{
  "uid": "traffic-parrot-feature-usage",
  "title": "Feature usage",
  "description": "How Traffic Parrot is used, from each instance's /api/metrics endpoint: requests served, mappings changed, recordings and imports, by team tag. An instance serves the endpoint when started with trafficparrot.telemetry.enabled=true; its counters start at 0 when it starts.",
  "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": "Traffic Parrot instances",
        "description": "The Prometheus job that scrapes the Traffic Parrot instances.",
        "datasource": {"type": "prometheus", "uid": "${datasource}"},
        "definition": "label_values(tp_instance, job)",
        "query": "label_values(tp_instance, 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 four grouped panels, which name project and team.",
        "query": "project,team",
        "current": {"selected": true, "text": ["team"], "value": ["team"]},
        "options": [
          {"selected": false, "text": "project", "value": "project"},
          {"selected": true, "text": "team", "value": "team"}
        ],
        "hide": 0,
        "multi": true,
        "includeAll": false
      }
    ]
  },
  "panels": [
    {
      "id": 1,
      "type": "stat",
      "title": "Instances",
      "description": "Traffic Parrot instances the job scrapes now. An instance that stopped drops out at its next missed scrape.",
      "datasource": {"type": "prometheus", "uid": "${datasource}"},
      "gridPos": {"h": 4, "w": 4, "x": 0, "y": 0},
      "fieldConfig": {
        "defaults": {"unit": "none", "decimals": 0, "noValue": "No instance scraped by this job"},
        "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": "count(tp_instance{job=\"$job\"})", "instant": true, "range": false, "legendFormat": "Instances"}
      ]
    },
    {
      "id": 2,
      "type": "stat",
      "title": "Mappings loaded now",
      "description": "Mappings loaded in the current scenario of every instance, all protocols. A count an instance cannot read (for example HTTP while its virtual service starts) is left out of the sum; while no count can be read, this reads 0.",
      "datasource": {"type": "prometheus", "uid": "${datasource}"},
      "gridPos": {"h": 4, "w": 4, "x": 4, "y": 0},
      "fieldConfig": {
        "defaults": {"unit": "none", "decimals": 0, "noValue": "No instance scraped by this job"},
        "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_mappings{job=\"$job\"} >= 0) or (0 * count(tp_instance{job=\"$job\"}))", "instant": true, "range": false, "legendFormat": "Mappings"}
      ]
    },
    {
      "id": 3,
      "type": "stat",
      "title": "Requests in range",
      "description": "Requests the instances served in the dashboard's time range, every protocol and outcome: HTTP requests, gRPC request messages, WebSocket text messages, and the messages JMS, IBM MQ and file replay received. Not counted: calls to the management API, requests the rate limiter refused and browser CORS preflights.",
      "datasource": {"type": "prometheus", "uid": "${datasource}"},
      "gridPos": {"h": 4, "w": 4, "x": 8, "y": 0},
      "fieldConfig": {
        "defaults": {"unit": "none", "decimals": 0, "noValue": "No instance scraped by this job"},
        "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_requests_total{job=\"$job\"}[$__range]))) or (0 * count(tp_instance{job=\"$job\"}))", "instant": true, "range": false, "legendFormat": "Requests"}
      ]
    },
    {
      "id": 4,
      "type": "stat",
      "title": "Mapping changes in range",
      "description": "HTTP mappings created, updated and deleted in the dashboard's time range through a Traffic Parrot page, the API, the MCP tools, an import or a recording. Mappings loaded from files at start-up, and changes made by rule rather than by id (a reset, a remove by pattern, a cleanup), are not counted.",
      "datasource": {"type": "prometheus", "uid": "${datasource}"},
      "gridPos": {"h": 4, "w": 4, "x": 12, "y": 0},
      "fieldConfig": {
        "defaults": {"unit": "none", "decimals": 0, "noValue": "No instance scraped by this job"},
        "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_mapping_changes_total{job=\"$job\"}[$__range]))) or (0 * count(tp_instance{job=\"$job\"}))", "instant": true, "range": false, "legendFormat": "Mapping changes"}
      ]
    },
    {
      "id": 5,
      "type": "stat",
      "title": "Recordings in range",
      "description": "HTTP recording sessions started in the dashboard's time range, from the Recording page or the Proxy page's Record option.",
      "datasource": {"type": "prometheus", "uid": "${datasource}"},
      "gridPos": {"h": 4, "w": 4, "x": 16, "y": 0},
      "fieldConfig": {
        "defaults": {"unit": "none", "decimals": 0, "noValue": "No instance scraped by this job"},
        "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_recording_sessions_total{job=\"$job\"}[$__range]))) or (0 * count(tp_instance{job=\"$job\"}))", "instant": true, "range": false, "legendFormat": "Recordings"}
      ]
    },
    {
      "id": 6,
      "type": "stat",
      "title": "Imports in range",
      "description": "Imports that added at least one mapping in the dashboard's time range: one per file imported on the HTTP Import page or through its API, and one per MCP generate_mappings_from_openapi call.",
      "datasource": {"type": "prometheus", "uid": "${datasource}"},
      "gridPos": {"h": 4, "w": 4, "x": 20, "y": 0},
      "fieldConfig": {
        "defaults": {"unit": "none", "decimals": 0, "noValue": "No instance scraped by this job"},
        "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_imports_total{job=\"$job\"}[$__range]))) or (0 * count(tp_instance{job=\"$job\"}))", "instant": true, "range": false, "legendFormat": "Imports"}
      ]
    },
    {
      "id": 7,
      "type": "timeseries",
      "title": "Requests per second by protocol and outcome",
      "description": "Requests served per second, stacked. matched: answered by a mapping, or by Traffic Parrot itself; unmatched: nothing matched; proxied: forwarded to another system (recording, proxy mappings, the HTTP Proxy page, the default proxy). Messaging protocols have no proxied series.",
      "datasource": {"type": "prometheus", "uid": "${datasource}"},
      "gridPos": {"h": 9, "w": 12, "x": 0, "y": 4},
      "fieldConfig": {
        "defaults": {
          "unit": "reqps",
          "decimals": 2,
          "min": 0,
          "noValue": "No requests, or no instance scraped by this job",
          "color": {"mode": "palette-classic-by-name"},
          "custom": {"drawStyle": "line", "lineInterpolation": "linear", "lineWidth": 1, "fillOpacity": 60, "showPoints": "never", "spanNulls": false, "stacking": {"mode": "normal", "group": "A"}, "axisLabel": "Requests per second", "axisSoftMax": 0.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 (protocol, outcome) (rate(tp_requests_total{job=\"$job\"}[$__rate_interval]))", "range": true, "instant": false, "legendFormat": "{{protocol}} {{outcome}}"}
      ]
    },
    {
      "id": 8,
      "type": "timeseries",
      "title": "Requests per second by ${group:text}",
      "description": "Requests served per second, every protocol and outcome, stacked by the tag chosen in Break down by.",
      "datasource": {"type": "prometheus", "uid": "${datasource}"},
      "gridPos": {"h": 9, "w": 12, "x": 12, "y": 4},
      "fieldConfig": {
        "defaults": {
          "unit": "reqps",
          "decimals": 2,
          "min": 0,
          "noValue": "No requests, or no instance scraped by this job",
          "color": {"mode": "palette-classic-by-name"},
          "custom": {"drawStyle": "line", "lineInterpolation": "linear", "lineWidth": 1, "fillOpacity": 60, "showPoints": "never", "spanNulls": false, "stacking": {"mode": "normal", "group": "A"}, "axisLabel": "Requests per second", "axisSoftMax": 0.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}) (rate(tp_requests_total{job=\"$job\"}[$__rate_interval]))", "range": true, "instant": false, "legendFormat": "{{project}} {{team}}"}
      ]
    },
    {
      "id": 9,
      "type": "timeseries",
      "title": "Mapping changes by source",
      "description": "HTTP mappings created, updated and deleted per bar (3 minutes or more, with the time range), by where the change was made: gui (a Traffic Parrot page or the HTTP mapping editor), api (any other API call), mcp (the MCP tools), import (one per mapping imported), recording (one per mapping recorded).",
      "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 mapping changes, or no instance scraped by this job",
          "color": {"mode": "palette-classic-by-name"},
          "custom": {"drawStyle": "bars", "lineWidth": 1, "fillOpacity": 80, "showPoints": "never", "spanNulls": false, "stacking": {"mode": "normal", "group": "A"}, "axisLabel": "Mapping changes", "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 (source) (increase(tp_mapping_changes_total{job=\"$job\"}[$__rate_interval]))", "range": true, "instant": false, "legendFormat": "{{source}}"}
      ]
    },
    {
      "id": 10,
      "type": "timeseries",
      "title": "Mapping changes by ${group:text}",
      "description": "HTTP mappings created, updated and deleted per bar (3 minutes or more, with the time range), by the tag chosen in Break down by.",
      "datasource": {"type": "prometheus", "uid": "${datasource}"},
      "gridPos": {"h": 9, "w": 12, "x": 12, "y": 13},
      "interval": "3m",
      "fieldConfig": {
        "defaults": {
          "unit": "none",
          "decimals": 0,
          "min": 0,
          "noValue": "No mapping changes, or no instance scraped by this job",
          "color": {"mode": "palette-classic-by-name"},
          "custom": {"drawStyle": "bars", "lineWidth": 1, "fillOpacity": 80, "showPoints": "never", "spanNulls": false, "stacking": {"mode": "normal", "group": "A"}, "axisLabel": "Mapping changes", "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_mapping_changes_total{job=\"$job\"}[$__rate_interval]))", "range": true, "instant": false, "legendFormat": "{{project}} {{team}}"}
      ]
    },
    {
      "id": 11,
      "type": "timeseries",
      "title": "Recordings and imports",
      "description": "HTTP recording sessions started, and imports that added at least one mapping by format (one per file imported on the HTTP Import page or through its API; one per MCP generate_mappings_from_openapi call), per bar (3 minutes or more, with the time range).",
      "datasource": {"type": "prometheus", "uid": "${datasource}"},
      "gridPos": {"h": 9, "w": 12, "x": 0, "y": 22},
      "interval": "3m",
      "fieldConfig": {
        "defaults": {
          "unit": "none",
          "decimals": 0,
          "min": 0,
          "noValue": "No recordings or imports, or no instance scraped by this job",
          "color": {"mode": "palette-classic-by-name"},
          "custom": {"drawStyle": "bars", "lineWidth": 1, "fillOpacity": 80, "showPoints": "never", "spanNulls": false, "stacking": {"mode": "normal", "group": "A"}, "axisLabel": "Sessions and imports", "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(increase(tp_recording_sessions_total{job=\"$job\"}[$__rate_interval]))", "range": true, "instant": false, "legendFormat": "Recordings"},
        {"refId": "B", "datasource": {"type": "prometheus", "uid": "${datasource}"}, "expr": "sum by (format) (increase(tp_imports_total{job=\"$job\"}[$__rate_interval]))", "range": true, "instant": false, "legendFormat": "Imports, {{format}}"}
      ]
    },
    {
      "id": 12,
      "type": "timeseries",
      "title": "Mappings loaded by protocol",
      "description": "Mappings loaded in the current scenario of every instance, stacked by protocol: what each instance has loaded now, not what was changed. A count an instance cannot read is left out.",
      "datasource": {"type": "prometheus", "uid": "${datasource}"},
      "gridPos": {"h": 9, "w": 12, "x": 12, "y": 22},
      "fieldConfig": {
        "defaults": {
          "unit": "none",
          "decimals": 0,
          "min": 0,
          "noValue": "No instance scraped by this job",
          "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": "Mappings", "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 (protocol) (tp_mappings{job=\"$job\"} >= 0)", "range": true, "instant": false, "legendFormat": "{{protocol}}"}
      ]
    },
    {
      "id": 13,
      "type": "table",
      "title": "By ${group:text}",
      "description": "For each value of the tag chosen in Break down by: instances scraped now, mappings loaded now, and the requests served, mapping changes, recordings and imports in the dashboard's time range.",
      "datasource": {"type": "prometheus", "uid": "${datasource}"},
      "gridPos": {"h": 8, "w": 24, "x": 0, "y": 31},
      "fieldConfig": {
        "defaults": {"unit": "none", "decimals": 0, "noValue": "No instance scraped by this job", "custom": {"align": "auto", "minWidth": 80}},
        "overrides": [
          {"matcher": {"id": "byName", "options": "Instances"}, "properties": [{"id": "noValue", "value": "0"}, {"id": "custom.width", "value": 110}]},
          {"matcher": {"id": "byName", "options": "Mappings now"}, "properties": [{"id": "noValue", "value": "0"}, {"id": "custom.width", "value": 130}]},
          {"matcher": {"id": "byName", "options": "Requests in range"}, "properties": [{"id": "noValue", "value": "0"}, {"id": "custom.width", "value": 160}]},
          {"matcher": {"id": "byName", "options": "Mapping changes in range"}, "properties": [{"id": "noValue", "value": "0"}, {"id": "custom.width", "value": 210}]},
          {"matcher": {"id": "byName", "options": "Recordings in range"}, "properties": [{"id": "noValue", "value": "0"}, {"id": "custom.width", "value": 170}]},
          {"matcher": {"id": "byName", "options": "Imports in range"}, "properties": [{"id": "noValue", "value": "0"}, {"id": "custom.width", "value": 150}]}
        ]
      },
      "options": {"showHeader": true, "cellHeight": "sm", "footer": {"show": false, "reducer": ["sum"], "fields": ""}},
      "targets": [
        {"refId": "A", "datasource": {"type": "prometheus", "uid": "${datasource}"}, "expr": "count by (${group:csv}) (tp_instance{job=\"$job\"})", "format": "table", "instant": true, "range": false},
        {"refId": "B", "datasource": {"type": "prometheus", "uid": "${datasource}"}, "expr": "sum by (${group:csv}) (tp_mappings{job=\"$job\"} >= 0)", "format": "table", "instant": true, "range": false},
        {"refId": "C", "datasource": {"type": "prometheus", "uid": "${datasource}"}, "expr": "round(sum by (${group:csv}) (increase(tp_requests_total{job=\"$job\"}[$__range])))", "format": "table", "instant": true, "range": false},
        {"refId": "D", "datasource": {"type": "prometheus", "uid": "${datasource}"}, "expr": "round(sum by (${group:csv}) (increase(tp_mapping_changes_total{job=\"$job\"}[$__range])))", "format": "table", "instant": true, "range": false},
        {"refId": "E", "datasource": {"type": "prometheus", "uid": "${datasource}"}, "expr": "round(sum by (${group:csv}) (increase(tp_recording_sessions_total{job=\"$job\"}[$__range])))", "format": "table", "instant": true, "range": false},
        {"refId": "F", "datasource": {"type": "prometheus", "uid": "${datasource}"}, "expr": "round(sum by (${group:csv}) (increase(tp_imports_total{job=\"$job\"}[$__range])))", "format": "table", "instant": true, "range": false}
      ],
      "transformations": [
        {"id": "merge", "options": {}},
        {"id": "organize", "options": {"excludeByName": {"Time": true}, "indexByName": {}, "renameByName": {"Value #A": "Instances", "Value #B": "Mappings now", "Value #C": "Requests in range", "Value #D": "Mapping changes in range", "Value #E": "Recordings in range", "Value #F": "Imports in range"}}}
      ]
    }
  ]
}
