{
  "dashboard": {
    "id": null,
    "title": "Reversal System - Production Monitoring",
    "tags": [
      "reversal",
      "payments",
      "phase3",
      "production"
    ],
    "style": "dark",
    "timezone": "UTC",
    "refresh": "30s",
    "time": {
      "from": "now-1h",
      "to": "now"
    },
    "timepicker": {
      "refresh_intervals": [
        "5s",
        "10s",
        "30s",
        "1m",
        "5m",
        "15m",
        "30m",
        "1h"
      ]
    },
    "panels": [
      {
        "id": 1,
        "title": "System Health Overview",
        "type": "stat",
        "gridPos": {
          "h": 8,
          "w": 24,
          "x": 0,
          "y": 0
        },
        "targets": [
          {
            "expr": "reversal_system_health_score",
            "refId": "A",
            "legendFormat": "Health Score"
          },
          {
            "expr": "rate(reversal_successes_total[5m]) / (rate(reversal_successes_total[5m]) + rate(reversal_failures_total[5m])) * 100",
            "refId": "B",
            "legendFormat": "Success Rate %"
          },
          {
            "expr": "reversal_queue_size",
            "refId": "C",
            "legendFormat": "Pending Reversals"
          },
          {
            "expr": "reversal_manual_review_queue_size",
            "refId": "D",
            "legendFormat": "Manual Review Queue"
          }
        ],
        "fieldConfig": {
          "defaults": {
            "color": {
              "mode": "thresholds"
            },
            "mappings": [],
            "thresholds": {
              "steps": [
                {
                  "color": "red",
                  "value": null
                },
                {
                  "color": "yellow",
                  "value": 0.7
                },
                {
                  "color": "green",
                  "value": 0.9
                }
              ]
            },
            "unit": "short",
            "min": 0,
            "max": 1
          },
          "overrides": [
            {
              "matcher": {
                "id": "byName",
                "options": "Success Rate %"
              },
              "properties": [
                {
                  "id": "unit",
                  "value": "percent"
                },
                {
                  "id": "max",
                  "value": 100
                }
              ]
            }
          ]
        },
        "options": {
          "reduceOptions": {
            "values": false,
            "calcs": [
              "lastNotNull"
            ],
            "fields": ""
          },
          "orientation": "auto",
          "textMode": "auto",
          "colorMode": "background",
          "graphMode": "area",
          "justifyMode": "auto"
        }
      },
      {
        "id": 2,
        "title": "Reversal Success Rate",
        "type": "timeseries",
        "gridPos": {
          "h": 8,
          "w": 12,
          "x": 0,
          "y": 8
        },
        "targets": [
          {
            "expr": "rate(reversal_successes_total[5m]) / (rate(reversal_successes_total[5m]) + rate(reversal_failures_total[5m])) * 100",
            "refId": "A",
            "legendFormat": "Success Rate %"
          },
          {
            "expr": "rate(reversal_failures_total[5m]) / (rate(reversal_successes_total[5m]) + rate(reversal_failures_total[5m])) * 100",
            "refId": "B",
            "legendFormat": "Failure Rate %"
          }
        ],
        "fieldConfig": {
          "defaults": {
            "color": {
              "mode": "palette-classic"
            },
            "custom": {
              "axisLabel": "",
              "axisPlacement": "auto",
              "barAlignment": 0,
              "drawStyle": "line",
              "fillOpacity": 10,
              "gradientMode": "none",
              "hideFrom": {
                "legend": false,
                "tooltip": false,
                "vis": false
              },
              "lineInterpolation": "linear",
              "lineWidth": 2,
              "pointSize": 5,
              "scaleDistribution": {
                "type": "linear"
              },
              "showPoints": "never",
              "spanNulls": false,
              "stacking": {
                "group": "A",
                "mode": "none"
              },
              "thresholdsStyle": {
                "mode": "off"
              }
            },
            "mappings": [],
            "thresholds": {
              "mode": "absolute",
              "steps": [
                {
                  "color": "green",
                  "value": null
                },
                {
                  "color": "red",
                  "value": 80
                }
              ]
            },
            "unit": "percent",
            "min": 0,
            "max": 100
          }
        },
        "options": {
          "legend": {
            "calcs": [],
            "displayMode": "list",
            "placement": "bottom"
          },
          "tooltip": {
            "mode": "single",
            "sort": "none"
          }
        }
      },
      {
        "id": 3,
        "title": "Queue Sizes",
        "type": "timeseries",
        "gridPos": {
          "h": 8,
          "w": 12,
          "x": 12,
          "y": 8
        },
        "targets": [
          {
            "expr": "reversal_queue_size",
            "refId": "A",
            "legendFormat": "Pending Reversals"
          },
          {
            "expr": "reversal_manual_review_queue_size",
            "refId": "B",
            "legendFormat": "Manual Review Queue"
          }
        ],
        "fieldConfig": {
          "defaults": {
            "color": {
              "mode": "palette-classic"
            },
            "custom": {
              "axisLabel": "",
              "axisPlacement": "auto",
              "barAlignment": 0,
              "drawStyle": "line",
              "fillOpacity": 10,
              "gradientMode": "none",
              "hideFrom": {
                "legend": false,
                "tooltip": false,
                "vis": false
              },
              "lineInterpolation": "linear",
              "lineWidth": 2,
              "pointSize": 5,
              "scaleDistribution": {
                "type": "linear"
              },
              "showPoints": "never",
              "spanNulls": false,
              "stacking": {
                "group": "A",
                "mode": "none"
              },
              "thresholdsStyle": {
                "mode": "off"
              }
            },
            "mappings": [],
            "thresholds": {
              "mode": "absolute",
              "steps": [
                {
                  "color": "green",
                  "value": null
                },
                {
                  "color": "yellow",
                  "value": 10
                },
                {
                  "color": "red",
                  "value": 25
                }
              ]
            },
            "unit": "short",
            "min": 0
          }
        },
        "options": {
          "legend": {
            "calcs": [],
            "displayMode": "list",
            "placement": "bottom"
          },
          "tooltip": {
            "mode": "single",
            "sort": "none"
          }
        }
      },
      {
        "id": 4,
        "title": "Reversal Attempts by Reason",
        "type": "timeseries",
        "gridPos": {
          "h": 8,
          "w": 12,
          "x": 0,
          "y": 16
        },
        "targets": [
          {
            "expr": "rate(reversal_attempts_total[5m])",
            "refId": "A",
            "legendFormat": "{{reason}}"
          }
        ],
        "fieldConfig": {
          "defaults": {
            "color": {
              "mode": "palette-classic"
            },
            "custom": {
              "axisLabel": "Attempts/sec",
              "axisPlacement": "auto",
              "barAlignment": 0,
              "drawStyle": "line",
              "fillOpacity": 10,
              "gradientMode": "none",
              "hideFrom": {
                "legend": false,
                "tooltip": false,
                "vis": false
              },
              "lineInterpolation": "linear",
              "lineWidth": 2,
              "pointSize": 5,
              "scaleDistribution": {
                "type": "linear"
              },
              "showPoints": "never",
              "spanNulls": false,
              "stacking": {
                "group": "A",
                "mode": "none"
              },
              "thresholdsStyle": {
                "mode": "off"
              }
            },
            "mappings": [],
            "thresholds": {
              "mode": "absolute",
              "steps": [
                {
                  "color": "green",
                  "value": null
                },
                {
                  "color": "red",
                  "value": 80
                }
              ]
            },
            "unit": "reqps",
            "min": 0
          }
        },
        "options": {
          "legend": {
            "calcs": [],
            "displayMode": "list",
            "placement": "bottom"
          },
          "tooltip": {
            "mode": "single",
            "sort": "none"
          }
        }
      },
      {
        "id": 5,
        "title": "Performance Metrics",
        "type": "timeseries",
        "gridPos": {
          "h": 8,
          "w": 12,
          "x": 12,
          "y": 16
        },
        "targets": [
          {
            "expr": "histogram_quantile(0.50, rate(reversal_duration_seconds_bucket[5m]))",
            "refId": "A",
            "legendFormat": "P50 Reversal Duration"
          },
          {
            "expr": "histogram_quantile(0.95, rate(reversal_duration_seconds_bucket[5m]))",
            "refId": "B",
            "legendFormat": "P95 Reversal Duration"
          },
          {
            "expr": "histogram_quantile(0.50, rate(reversal_packet_generation_seconds_bucket[5m]))",
            "refId": "C",
            "legendFormat": "P50 Packet Generation"
          },
          {
            "expr": "histogram_quantile(0.50, rate(reversal_network_transmission_seconds_bucket[5m]))",
            "refId": "D",
            "legendFormat": "P50 Network Transmission"
          }
        ],
        "fieldConfig": {
          "defaults": {
            "color": {
              "mode": "palette-classic"
            },
            "custom": {
              "axisLabel": "Seconds",
              "axisPlacement": "auto",
              "barAlignment": 0,
              "drawStyle": "line",
              "fillOpacity": 10,
              "gradientMode": "none",
              "hideFrom": {
                "legend": false,
                "tooltip": false,
                "vis": false
              },
              "lineInterpolation": "linear",
              "lineWidth": 2,
              "pointSize": 5,
              "scaleDistribution": {
                "type": "linear"
              },
              "showPoints": "never",
              "spanNulls": false,
              "stacking": {
                "group": "A",
                "mode": "none"
              },
              "thresholdsStyle": {
                "mode": "off"
              }
            },
            "mappings": [],
            "thresholds": {
              "mode": "absolute",
              "steps": [
                {
                  "color": "green",
                  "value": null
                },
                {
                  "color": "yellow",
                  "value": 2
                },
                {
                  "color": "red",
                  "value": 5
                }
              ]
            },
            "unit": "s",
            "min": 0
          }
        },
        "options": {
          "legend": {
            "calcs": [],
            "displayMode": "list",
            "placement": "bottom"
          },
          "tooltip": {
            "mode": "single",
            "sort": "none"
          }
        }
      },
      {
        "id": 6,
        "title": "System Resources",
        "type": "timeseries",
        "gridPos": {
          "h": 8,
          "w": 12,
          "x": 0,
          "y": 24
        },
        "targets": [
          {
            "expr": "reversal_worker_health",
            "refId": "A",
            "legendFormat": "Cleanup Worker Health"
          },
          {
            "expr": "reversal_available_stan_numbers / 1000",
            "refId": "B",
            "legendFormat": "Available STAN Numbers (K)"
          },
          {
            "expr": "reversal_available_batch_numbers",
            "refId": "C",
            "legendFormat": "Available Batch Numbers"
          }
        ],
        "fieldConfig": {
          "defaults": {
            "color": {
              "mode": "palette-classic"
            },
            "custom": {
              "axisLabel": "",
              "axisPlacement": "auto",
              "barAlignment": 0,
              "drawStyle": "line",
              "fillOpacity": 10,
              "gradientMode": "none",
              "hideFrom": {
                "legend": false,
                "tooltip": false,
                "vis": false
              },
              "lineInterpolation": "linear",
              "lineWidth": 2,
              "pointSize": 5,
              "scaleDistribution": {
                "type": "linear"
              },
              "showPoints": "never",
              "spanNulls": false,
              "stacking": {
                "group": "A",
                "mode": "none"
              },
              "thresholdsStyle": {
                "mode": "off"
              }
            },
            "mappings": [],
            "thresholds": {
              "mode": "absolute",
              "steps": [
                {
                  "color": "green",
                  "value": null
                },
                {
                  "color": "red",
                  "value": 80
                }
              ]
            },
            "unit": "short",
            "min": 0
          }
        },
        "options": {
          "legend": {
            "calcs": [],
            "displayMode": "list",
            "placement": "bottom"
          },
          "tooltip": {
            "mode": "single",
            "sort": "none"
          }
        }
      },
      {
        "id": 7,
        "title": "Error Analysis",
        "type": "piechart",
        "gridPos": {
          "h": 8,
          "w": 12,
          "x": 12,
          "y": 24
        },
        "targets": [
          {
            "expr": "increase(reversal_failures_total[1h])",
            "refId": "A",
            "legendFormat": "{{reason}}"
          }
        ],
        "fieldConfig": {
          "defaults": {
            "color": {
              "mode": "palette-classic"
            },
            "custom": {
              "hideFrom": {
                "legend": false,
                "tooltip": false,
                "vis": false
              }
            },
            "mappings": [],
            "unit": "short"
          }
        },
        "options": {
          "reduceOptions": {
            "values": false,
            "calcs": [
              "lastNotNull"
            ],
            "fields": ""
          },
          "pieType": "pie",
          "tooltip": {
            "mode": "single",
            "sort": "none"
          },
          "legend": {
            "displayMode": "list",
            "placement": "bottom"
          }
        }
      }
    ],
    "annotations": {
      "list": [
        {
          "name": "Deployments",
          "datasource": "-- Grafana --",
          "enable": true,
          "hide": true,
          "iconColor": "rgba(0, 211, 255, 1)",
          "type": "tags",
          "tags": ["deployment"]
        }
      ]
    },
    "variables": {
      "list": [
        {
          "name": "environment",
          "type": "constant",
          "current": {
            "value": "production",
            "text": "production"
          },
          "options": [
            {
              "value": "production",
              "text": "production"
            }
          ]
        }
      ]
    }
  },
  "overwrite": true
}