{
  "id": null,
  "uid": "mikrotik-api-overview",
  "title": "API Overview",
  "description": "TOD API request rates, error rates, and response times",
  "tags": ["mikrotik", "api"],
  "timezone": "browser",
  "schemaVersion": 39,
  "version": 1,
  "refresh": "30s",
  "editable": true,
  "time": {
    "from": "now-1h",
    "to": "now"
  },
  "panels": [
    {
      "id": 1,
      "title": "Request Rate (req/s)",
      "type": "timeseries",
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 0 },
      "datasource": "Prometheus",
      "targets": [
        {
          "expr": "sum(rate(http_requests_total[5m])) by (handler)",
          "legendFormat": "{{handler}}",
          "refId": "A"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "reqps",
          "custom": {
            "drawStyle": "line",
            "lineInterpolation": "smooth",
            "fillOpacity": 10
          }
        },
        "overrides": []
      },
      "options": {
        "tooltip": { "mode": "multi" },
        "legend": { "displayMode": "table", "placement": "bottom", "calcs": ["mean", "max"] }
      }
    },
    {
      "id": 2,
      "title": "Error Rate (4xx/5xx)",
      "type": "timeseries",
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 0 },
      "datasource": "Prometheus",
      "targets": [
        {
          "expr": "sum(rate(http_requests_total{status=~\"4..\"}[5m])) by (handler)",
          "legendFormat": "4xx {{handler}}",
          "refId": "A"
        },
        {
          "expr": "sum(rate(http_requests_total{status=~\"5..\"}[5m])) by (handler)",
          "legendFormat": "5xx {{handler}}",
          "refId": "B"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "reqps",
          "custom": {
            "drawStyle": "line",
            "lineInterpolation": "smooth",
            "fillOpacity": 10
          },
          "color": { "mode": "palette-classic" }
        },
        "overrides": []
      },
      "options": {
        "tooltip": { "mode": "multi" },
        "legend": { "displayMode": "table", "placement": "bottom", "calcs": ["mean", "max"] }
      }
    },
    {
      "id": 3,
      "title": "Response Time P50 (seconds)",
      "type": "timeseries",
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 8 },
      "datasource": "Prometheus",
      "targets": [
        {
          "expr": "histogram_quantile(0.50, sum(rate(http_request_duration_seconds_bucket[5m])) by (le, handler))",
          "legendFormat": "p50 {{handler}}",
          "refId": "A"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "s",
          "custom": {
            "drawStyle": "line",
            "lineInterpolation": "smooth",
            "fillOpacity": 10
          }
        },
        "overrides": []
      },
      "options": {
        "tooltip": { "mode": "multi" },
        "legend": { "displayMode": "table", "placement": "bottom", "calcs": ["mean", "max"] }
      }
    },
    {
      "id": 4,
      "title": "Response Time P95 (seconds)",
      "type": "timeseries",
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 8 },
      "datasource": "Prometheus",
      "targets": [
        {
          "expr": "histogram_quantile(0.95, sum(rate(http_request_duration_seconds_bucket[5m])) by (le, handler))",
          "legendFormat": "p95 {{handler}}",
          "refId": "A"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "s",
          "custom": {
            "drawStyle": "line",
            "lineInterpolation": "smooth",
            "fillOpacity": 10
          }
        },
        "overrides": []
      },
      "options": {
        "tooltip": { "mode": "multi" },
        "legend": { "displayMode": "table", "placement": "bottom", "calcs": ["mean", "max"] }
      }
    },
    {
      "id": 5,
      "title": "Response Time P99 (seconds)",
      "type": "timeseries",
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 16 },
      "datasource": "Prometheus",
      "targets": [
        {
          "expr": "histogram_quantile(0.99, sum(rate(http_request_duration_seconds_bucket[5m])) by (le, handler))",
          "legendFormat": "p99 {{handler}}",
          "refId": "A"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "s",
          "custom": {
            "drawStyle": "line",
            "lineInterpolation": "smooth",
            "fillOpacity": 10
          }
        },
        "overrides": []
      },
      "options": {
        "tooltip": { "mode": "multi" },
        "legend": { "displayMode": "table", "placement": "bottom", "calcs": ["mean", "max"] }
      }
    },
    {
      "id": 6,
      "title": "Requests In Progress",
      "type": "gauge",
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 16 },
      "datasource": "Prometheus",
      "targets": [
        {
          "expr": "sum(http_requests_in_progress)",
          "legendFormat": "In Progress",
          "refId": "A"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "thresholds": {
            "mode": "absolute",
            "steps": [
              { "color": "green", "value": null },
              { "color": "yellow", "value": 10 },
              { "color": "red", "value": 50 }
            ]
          },
          "min": 0,
          "max": 100
        },
        "overrides": []
      },
      "options": {
        "reduceOptions": { "calcs": ["lastNotNull"] },
        "showThresholdLabels": false,
        "showThresholdMarkers": true
      }
    },
    {
      "id": 7,
      "title": "Status Code Distribution (1h)",
      "type": "piechart",
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 24 },
      "datasource": "Prometheus",
      "targets": [
        {
          "expr": "sum by(status) (increase(http_requests_total[1h]))",
          "legendFormat": "{{status}}",
          "refId": "A"
        }
      ],
      "fieldConfig": {
        "defaults": {},
        "overrides": []
      },
      "options": {
        "legend": { "displayMode": "table", "placement": "right", "values": ["value", "percent"] },
        "pieType": "donut",
        "reduceOptions": { "calcs": ["lastNotNull"] }
      }
    },
    {
      "id": 8,
      "title": "Top Endpoints (1h)",
      "type": "table",
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 24 },
      "datasource": "Prometheus",
      "targets": [
        {
          "expr": "topk(10, sum by(handler) (increase(http_requests_total[1h])))",
          "legendFormat": "{{handler}}",
          "refId": "A",
          "format": "table",
          "instant": true
        }
      ],
      "fieldConfig": {
        "defaults": {},
        "overrides": [
          {
            "matcher": { "id": "byName", "options": "Value" },
            "properties": [{ "id": "displayName", "value": "Requests (1h)" }]
          }
        ]
      },
      "options": {
        "showHeader": true,
        "sortBy": [{ "desc": true, "displayName": "Requests (1h)" }]
      },
      "transformations": [
        { "id": "organize", "options": { "excludeByName": { "Time": true } } }
      ]
    }
  ]
}
