{
  "__inputs": [
    {
      "name": "DS_PROMETHEUS",
      "label": "Prometheus",
      "description": "The Prometheus that scrapes sharerr's /metrics",
      "type": "datasource",
      "pluginId": "prometheus",
      "pluginName": "Prometheus"
    }
  ],
  "__requires": [
    { "type": "grafana", "id": "grafana", "name": "Grafana", "version": "10.0.0" },
    { "type": "datasource", "id": "prometheus", "name": "Prometheus", "version": "1.0.0" },
    { "type": "panel", "id": "stat", "name": "Stat", "version": "" },
    { "type": "panel", "id": "timeseries", "name": "Time series", "version": "" }
  ],
  "title": "sharerr",
  "uid": "sharerr",
  "description": "What one sharerr instance shares, with whom, and how much has moved. Every panel reads the metrics sharerr's /metrics endpoint exports.",
  "tags": ["sharerr"],
  "editable": true,
  "graphTooltip": 1,
  "refresh": "1m",
  "schemaVersion": 39,
  "time": { "from": "now-7d", "to": "now" },
  "timezone": "browser",
  "templating": {
    "list": [
      {
        "name": "DS_PROMETHEUS",
        "label": "Prometheus",
        "type": "datasource",
        "query": "prometheus",
        "current": {},
        "hide": 0,
        "refresh": 1
      },
      {
        "name": "instance",
        "label": "Instance",
        "type": "query",
        "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
        "query": "label_values(sharerr_items, instance)",
        "refresh": 2,
        "includeAll": false,
        "multi": false,
        "current": {}
      }
    ]
  },
  "panels": [
    {
      "id": 1,
      "type": "stat",
      "title": "Items seeding",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 4, "w": 4, "x": 0, "y": 0 },
      "targets": [{ "refId": "A", "expr": "sharerr_items{instance=\"$instance\", state=\"seeding\"}" }],
      "fieldConfig": { "defaults": { "unit": "none", "color": { "mode": "fixed", "fixedColor": "green" } }, "overrides": [] },
      "options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "none" }
    },
    {
      "id": 2,
      "type": "stat",
      "title": "Shared on disk",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 4, "w": 4, "x": 4, "y": 0 },
      "targets": [{ "refId": "A", "expr": "sharerr_seeding_bytes{instance=\"$instance\"}" }],
      "fieldConfig": { "defaults": { "unit": "bytes", "color": { "mode": "fixed", "fixedColor": "green" } }, "overrides": [] },
      "options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "none" }
    },
    {
      "id": 3,
      "type": "stat",
      "title": "Friends (recent / total)",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 4, "w": 4, "x": 8, "y": 0 },
      "targets": [
        { "refId": "A", "expr": "sharerr_peers{instance=\"$instance\", state=\"recent\"}", "legendFormat": "recent" },
        { "refId": "B", "expr": "sharerr_peers{instance=\"$instance\", state=\"total\"}", "legendFormat": "total" }
      ],
      "fieldConfig": { "defaults": { "unit": "none", "color": { "mode": "fixed", "fixedColor": "blue" } }, "overrides": [] },
      "options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "none", "graphMode": "none", "textMode": "value_and_name" }
    },
    {
      "id": 4,
      "type": "stat",
      "title": "Swarm now (peers / seeders / torrents)",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 4, "w": 6, "x": 12, "y": 0 },
      "targets": [
        { "refId": "A", "expr": "sharerr_swarm_peers{instance=\"$instance\"}", "legendFormat": "peers" },
        { "refId": "B", "expr": "sharerr_swarm_seeders{instance=\"$instance\"}", "legendFormat": "seeders" },
        { "refId": "C", "expr": "sharerr_swarm_torrents{instance=\"$instance\"}", "legendFormat": "torrents" }
      ],
      "fieldConfig": { "defaults": { "unit": "none", "color": { "mode": "fixed", "fixedColor": "purple" } }, "overrides": [] },
      "options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "none", "graphMode": "none", "textMode": "value_and_name" }
    },
    {
      "id": 5,
      "type": "stat",
      "title": "Served all-time",
      "description": "Bytes friends' clients report having downloaded from this tracker's swarms.",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 4, "w": 6, "x": 18, "y": 0 },
      "targets": [{ "refId": "A", "expr": "sharerr_transfer_bytes_total{instance=\"$instance\", direction=\"downloaded\"}" }],
      "fieldConfig": { "defaults": { "unit": "bytes", "color": { "mode": "fixed", "fixedColor": "orange" } }, "overrides": [] },
      "options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "none" }
    },
    {
      "id": 6,
      "type": "stat",
      "title": "Last sync",
      "description": "Green when the last finished pass succeeded outright; red when it errored.",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 4, "w": 4, "x": 0, "y": 4 },
      "targets": [{ "refId": "A", "expr": "sharerr_sync_last_run_ok{instance=\"$instance\"}" }],
      "fieldConfig": {
        "defaults": {
          "mappings": [
            { "type": "value", "options": { "0": { "text": "failed", "color": "red" }, "1": { "text": "ok", "color": "green" } } }
          ],
          "color": { "mode": "thresholds" },
          "thresholds": { "mode": "absolute", "steps": [{ "color": "red", "value": null }, { "color": "green", "value": 1 }] },
          "noValue": "never ran"
        },
        "overrides": []
      },
      "options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "background", "graphMode": "none" }
    },
    {
      "id": 7,
      "type": "stat",
      "title": "Since the last sync",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 4, "w": 4, "x": 4, "y": 4 },
      "targets": [{ "refId": "A", "expr": "time() - sharerr_sync_last_run_timestamp_seconds{instance=\"$instance\"}" }],
      "fieldConfig": {
        "defaults": {
          "unit": "s",
          "color": { "mode": "thresholds" },
          "thresholds": { "mode": "absolute", "steps": [{ "color": "green", "value": null }, { "color": "orange", "value": 3600 }, { "color": "red", "value": 7200 }] },
          "noValue": "never ran"
        },
        "overrides": []
      },
      "options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "none" }
    },
    {
      "id": 8,
      "type": "stat",
      "title": "Last pass did",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 4, "w": 8, "x": 8, "y": 4 },
      "targets": [{ "refId": "A", "expr": "sharerr_sync_last_run{instance=\"$instance\"}", "legendFormat": "{{result}}" }],
      "fieldConfig": { "defaults": { "unit": "none", "color": { "mode": "fixed", "fixedColor": "text" } }, "overrides": [] },
      "options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "none", "graphMode": "none", "textMode": "value_and_name" }
    },
    {
      "id": 9,
      "type": "stat",
      "title": "Sync duration",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 4, "w": 4, "x": 16, "y": 4 },
      "targets": [{ "refId": "A", "expr": "sharerr_sync_last_run_duration_seconds{instance=\"$instance\"}" }],
      "fieldConfig": { "defaults": { "unit": "s", "color": { "mode": "fixed", "fixedColor": "text" } }, "overrides": [] },
      "options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "none", "graphMode": "area" }
    },
    {
      "id": 10,
      "type": "stat",
      "title": "CPU",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 4, "w": 4, "x": 20, "y": 4 },
      "targets": [{ "refId": "A", "expr": "sharerr_system_cpu_percent{instance=\"$instance\"}" }],
      "fieldConfig": { "defaults": { "unit": "percent", "min": 0, "max": 100, "color": { "mode": "thresholds" }, "thresholds": { "mode": "absolute", "steps": [{ "color": "green", "value": null }, { "color": "orange", "value": 70 }, { "color": "red", "value": 90 }] } }, "overrides": [] },
      "options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "area" }
    },
    {
      "id": 11,
      "type": "timeseries",
      "title": "Transfer rate",
      "description": "From the tracker's announces, as the announcing clients report it: downloaded is what left this instance's swarms.",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 8 },
      "targets": [{ "refId": "A", "expr": "rate(sharerr_transfer_bytes_total{instance=\"$instance\"}[$__rate_interval])", "legendFormat": "{{direction}}" }],
      "fieldConfig": { "defaults": { "unit": "Bps", "custom": { "fillOpacity": 10, "lineWidth": 1 } }, "overrides": [] },
      "options": { "legend": { "displayMode": "list", "placement": "bottom" }, "tooltip": { "mode": "multi" } }
    },
    {
      "id": 12,
      "type": "timeseries",
      "title": "Swarm over time",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 8 },
      "targets": [
        { "refId": "A", "expr": "sharerr_swarm_peers{instance=\"$instance\"}", "legendFormat": "peers" },
        { "refId": "B", "expr": "sharerr_swarm_seeders{instance=\"$instance\"}", "legendFormat": "seeders" },
        { "refId": "C", "expr": "sharerr_swarm_torrents{instance=\"$instance\"}", "legendFormat": "torrents" }
      ],
      "fieldConfig": { "defaults": { "unit": "none", "custom": { "fillOpacity": 10, "lineWidth": 1 } }, "overrides": [] },
      "options": { "legend": { "displayMode": "list", "placement": "bottom" }, "tooltip": { "mode": "multi" } }
    },
    {
      "id": 13,
      "type": "timeseries",
      "title": "Items by state",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 16 },
      "targets": [{ "refId": "A", "expr": "sharerr_items{instance=\"$instance\"}", "legendFormat": "{{state}}" }],
      "fieldConfig": { "defaults": { "unit": "none", "custom": { "fillOpacity": 10, "lineWidth": 1 } }, "overrides": [] },
      "options": { "legend": { "displayMode": "list", "placement": "bottom" }, "tooltip": { "mode": "multi" } }
    },
    {
      "id": 14,
      "type": "timeseries",
      "title": "Memory and data directory",
      "datasource": { "type": "prometheus", "uid": "${DS_PROMETHEUS}" },
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 16 },
      "targets": [
        { "refId": "A", "expr": "sharerr_system_memory_bytes{instance=\"$instance\"}", "legendFormat": "memory {{kind}}" },
        { "refId": "B", "expr": "sharerr_system_disk_bytes{instance=\"$instance\"}", "legendFormat": "disk {{kind}}" }
      ],
      "fieldConfig": { "defaults": { "unit": "bytes", "custom": { "fillOpacity": 0, "lineWidth": 1 } }, "overrides": [] },
      "options": { "legend": { "displayMode": "list", "placement": "bottom" }, "tooltip": { "mode": "multi" } }
    }
  ]
}
