{
  "id": null,
  "uid": "mikrotik-poller-status",
  "title": "Poller Status",
  "description": "MikroTik Poller metrics: active devices, poll duration, error rates",
  "tags": ["mikrotik", "poller"],
  "timezone": "browser",
  "schemaVersion": 39,
  "version": 1,
  "refresh": "30s",
  "editable": true,
  "time": {
    "from": "now-1h",
    "to": "now"
  },
  "panels": [
    {
      "id": 1,
      "title": "Active Devices",
      "type": "stat",
      "gridPos": { "h": 5, "w": 6, "x": 0, "y": 0 },
      "datasource": "Prometheus",
      "targets": [
        {
          "expr": "mikrotik_devices_active",
          "legendFormat": "Devices",
          "refId": "A"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "thresholds": {
            "mode": "absolute",
            "steps": [
              { "color": "green", "value": null }
            ]
          }
        },
        "overrides": []
      },
      "options": {
        "reduceOptions": { "calcs": ["lastNotNull"] },
        "colorMode": "value",
        "graphMode": "area",
        "justifyMode": "auto",
        "textMode": "auto"
      }
    },
    {
      "id": 2,
      "title": "Poll Success Rate %",
      "type": "stat",
      "gridPos": { "h": 5, "w": 6, "x": 6, "y": 0 },
      "datasource": "Prometheus",
      "targets": [
        {
          "expr": "rate(mikrotik_poll_total{status=\"success\"}[5m]) / (rate(mikrotik_poll_total[5m]) > 0) * 100",
          "legendFormat": "Success %",
          "refId": "A"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "percent",
          "min": 0,
          "max": 100,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              { "color": "red", "value": null },
              { "color": "yellow", "value": 80 },
              { "color": "green", "value": 95 }
            ]
          }
        },
        "overrides": []
      },
      "options": {
        "reduceOptions": { "calcs": ["lastNotNull"] },
        "colorMode": "value",
        "graphMode": "none"
      }
    },
    {
      "id": 3,
      "title": "Total Polls/s",
      "type": "stat",
      "gridPos": { "h": 5, "w": 6, "x": 12, "y": 0 },
      "datasource": "Prometheus",
      "targets": [
        {
          "expr": "sum(rate(mikrotik_poll_total[5m]))",
          "legendFormat": "Polls/s",
          "refId": "A"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "ops",
          "thresholds": {
            "mode": "absolute",
            "steps": [
              { "color": "blue", "value": null }
            ]
          }
        },
        "overrides": []
      },
      "options": {
        "reduceOptions": { "calcs": ["lastNotNull"] },
        "colorMode": "value",
        "graphMode": "area"
      }
    },
    {
      "id": 4,
      "title": "Connection Errors/s",
      "type": "stat",
      "gridPos": { "h": 5, "w": 6, "x": 18, "y": 0 },
      "datasource": "Prometheus",
      "targets": [
        {
          "expr": "rate(mikrotik_device_connection_errors_total[5m])",
          "legendFormat": "Errors/s",
          "refId": "A"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "ops",
          "thresholds": {
            "mode": "absolute",
            "steps": [
              { "color": "green", "value": null },
              { "color": "yellow", "value": 0.1 },
              { "color": "red", "value": 1 }
            ]
          }
        },
        "overrides": []
      },
      "options": {
        "reduceOptions": { "calcs": ["lastNotNull"] },
        "colorMode": "value",
        "graphMode": "area"
      }
    },
    {
      "id": 5,
      "title": "Avg Poll Duration (seconds)",
      "type": "timeseries",
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 5 },
      "datasource": "Prometheus",
      "targets": [
        {
          "expr": "rate(mikrotik_poll_duration_seconds_sum[5m]) / rate(mikrotik_poll_duration_seconds_count[5m])",
          "legendFormat": "Avg Duration",
          "refId": "A"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "s",
          "custom": {
            "drawStyle": "line",
            "lineInterpolation": "smooth",
            "fillOpacity": 20
          },
          "color": { "mode": "fixed", "fixedColor": "blue" }
        },
        "overrides": []
      },
      "options": {
        "tooltip": { "mode": "single" },
        "legend": { "displayMode": "list", "placement": "bottom" }
      }
    },
    {
      "id": 6,
      "title": "Poll Duration Distribution",
      "type": "heatmap",
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 5 },
      "datasource": "Prometheus",
      "targets": [
        {
          "expr": "sum(increase(mikrotik_poll_duration_seconds_bucket[5m])) by (le)",
          "legendFormat": "{{le}}",
          "refId": "A",
          "format": "heatmap"
        }
      ],
      "fieldConfig": {
        "defaults": {},
        "overrides": []
      },
      "options": {
        "calculate": false,
        "yAxis": { "unit": "s" },
        "color": { "mode": "scheme", "scheme": "Oranges" },
        "cellGap": 1,
        "showValue": "never"
      }
    },
    {
      "id": 7,
      "title": "Poll Rate by Status",
      "type": "timeseries",
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 13 },
      "datasource": "Prometheus",
      "targets": [
        {
          "expr": "rate(mikrotik_poll_total[5m])",
          "legendFormat": "{{status}}",
          "refId": "A"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "ops",
          "custom": {
            "drawStyle": "line",
            "lineInterpolation": "smooth",
            "fillOpacity": 20,
            "stacking": { "mode": "normal" }
          }
        },
        "overrides": [
          {
            "matcher": { "id": "byName", "options": "success" },
            "properties": [{ "id": "color", "value": { "fixedColor": "green", "mode": "fixed" } }]
          },
          {
            "matcher": { "id": "byName", "options": "error" },
            "properties": [{ "id": "color", "value": { "fixedColor": "red", "mode": "fixed" } }]
          },
          {
            "matcher": { "id": "byName", "options": "skipped" },
            "properties": [{ "id": "color", "value": { "fixedColor": "yellow", "mode": "fixed" } }]
          }
        ]
      },
      "options": {
        "tooltip": { "mode": "multi" },
        "legend": { "displayMode": "list", "placement": "bottom" }
      }
    },
    {
      "id": 8,
      "title": "NATS Publish Rate by Subject",
      "type": "timeseries",
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 13 },
      "datasource": "Prometheus",
      "targets": [
        {
          "expr": "sum(rate(mikrotik_nats_publish_total{status=\"success\"}[5m])) by (subject)",
          "legendFormat": "{{subject}} (ok)",
          "refId": "A"
        },
        {
          "expr": "sum(rate(mikrotik_nats_publish_total{status=\"error\"}[5m])) by (subject)",
          "legendFormat": "{{subject}} (err)",
          "refId": "B"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "ops",
          "custom": {
            "drawStyle": "line",
            "lineInterpolation": "smooth",
            "fillOpacity": 10
          }
        },
        "overrides": []
      },
      "options": {
        "tooltip": { "mode": "multi" },
        "legend": { "displayMode": "table", "placement": "bottom", "calcs": ["mean"] }
      }
    },
    {
      "id": 9,
      "title": "Redis Lock Operations/s",
      "type": "timeseries",
      "gridPos": { "h": 8, "w": 24, "x": 0, "y": 21 },
      "datasource": "Prometheus",
      "targets": [
        {
          "expr": "rate(mikrotik_redis_lock_total[5m])",
          "legendFormat": "{{status}}",
          "refId": "A"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "ops",
          "custom": {
            "drawStyle": "line",
            "lineInterpolation": "smooth",
            "fillOpacity": 10
          }
        },
        "overrides": [
          {
            "matcher": { "id": "byName", "options": "obtained" },
            "properties": [{ "id": "color", "value": { "fixedColor": "green", "mode": "fixed" } }]
          },
          {
            "matcher": { "id": "byName", "options": "not_obtained" },
            "properties": [{ "id": "color", "value": { "fixedColor": "yellow", "mode": "fixed" } }]
          },
          {
            "matcher": { "id": "byName", "options": "error" },
            "properties": [{ "id": "color", "value": { "fixedColor": "red", "mode": "fixed" } }]
          }
        ]
      },
      "options": {
        "tooltip": { "mode": "multi" },
        "legend": { "displayMode": "list", "placement": "bottom" }
      }
    }
  ]
}
