{
  "dashboard": {
    "title": "Booking Modification Monitoring",
    "tags": ["modification", "booking", "monitoring"],
    "timezone": "browser",
    "schemaVersion": 16,
    "version": 1,
    "refresh": "30s",
    "panels": [
      {
        "id": 1,
        "title": "Modification Success Rate",
        "type": "graph",
        "gridPos": {"x": 0, "y": 0, "w": 12, "h": 8},
        "targets": [
          {
            "expr": "(sum(rate(business_modification_success_total[5m])) / sum(rate(business_modification_attempt_total[5m]))) * 100",
            "legendFormat": "Success Rate %",
            "refId": "A"
          }
        ],
        "yaxes": [
          {"format": "percent", "min": 0, "max": 100}
        ],
        "alert": {
          "conditions": [
            {
              "evaluator": {"params": [95], "type": "lt"},
              "operator": {"type": "and"},
              "query": {"params": ["A", "5m", "now"]},
              "reducer": {"params": [], "type": "avg"},
              "type": "query"
            }
          ],
          "executionErrorState": "alerting",
          "frequency": "60s",
          "handler": 1,
          "name": "Modification Success Rate alert",
          "noDataState": "no_data",
          "notifications": []
        }
      },
      {
        "id": 2,
        "title": "Modification Attempts by Type",
        "type": "graph",
        "gridPos": {"x": 12, "y": 0, "w": 12, "h": 8},
        "targets": [
          {
            "expr": "sum(rate(business_modification_attempt_by_type_total[5m])) by (type)",
            "legendFormat": "{{type}}",
            "refId": "A"
          }
        ],
        "yaxes": [
          {"format": "ops", "min": 0}
        ]
      },
      {
        "id": 3,
        "title": "API Error Rate",
        "type": "graph",
        "gridPos": {"x": 0, "y": 8, "w": 12, "h": 8},
        "targets": [
          {
            "expr": "(sum(rate(business_modification_api_error_total[5m])) / sum(rate(business_modification_attempt_total[5m]))) * 100",
            "legendFormat": "API Error Rate %",
            "refId": "A"
          }
        ],
        "yaxes": [
          {"format": "percent", "min": 0}
        ],
        "alert": {
          "conditions": [
            {
              "evaluator": {"params": [5], "type": "gt"},
              "operator": {"type": "and"},
              "query": {"params": ["A", "5m", "now"]},
              "reducer": {"params": [], "type": "avg"},
              "type": "query"
            }
          ],
          "executionErrorState": "alerting",
          "frequency": "60s",
          "handler": 1,
          "name": "API Error Rate alert",
          "noDataState": "no_data",
          "notifications": []
        }
      },
      {
        "id": 4,
        "title": "Rollback Rate",
        "type": "graph",
        "gridPos": {"x": 12, "y": 8, "w": 12, "h": 8},
        "targets": [
          {
            "expr": "(sum(rate(business_modification_rollback_total[5m])) / sum(rate(business_modification_attempt_total[5m]))) * 100",
            "legendFormat": "Rollback Rate %",
            "refId": "A"
          }
        ],
        "yaxes": [
          {"format": "percent", "min": 0}
        ],
        "alert": {
          "conditions": [
            {
              "evaluator": {"params": [1], "type": "gt"},
              "operator": {"type": "and"},
              "query": {"params": ["A", "5m", "now"]},
              "reducer": {"params": [], "type": "avg"},
              "type": "query"
            }
          ],
          "executionErrorState": "alerting",
          "frequency": "60s",
          "handler": 1,
          "name": "Rollback Rate alert",
          "noDataState": "no_data",
          "notifications": []
        }
      },
      {
        "id": 5,
        "title": "Processing Time Percentiles",
        "type": "graph",
        "gridPos": {"x": 0, "y": 16, "w": 12, "h": 8},
        "targets": [
          {
            "expr": "histogram_quantile(0.50, sum(rate(business_modification_processing_duration_seconds_bucket[5m])) by (le))",
            "legendFormat": "p50",
            "refId": "A"
          },
          {
            "expr": "histogram_quantile(0.95, sum(rate(business_modification_processing_duration_seconds_bucket[5m])) by (le))",
            "legendFormat": "p95",
            "refId": "B"
          },
          {
            "expr": "histogram_quantile(0.99, sum(rate(business_modification_processing_duration_seconds_bucket[5m])) by (le))",
            "legendFormat": "p99",
            "refId": "C"
          }
        ],
        "yaxes": [
          {"format": "s", "min": 0}
        ]
      },
      {
        "id": 6,
        "title": "Average Modification Cost",
        "type": "graph",
        "gridPos": {"x": 12, "y": 16, "w": 12, "h": 8},
        "targets": [
          {
            "expr": "avg(business_modification_cost) by (type)",
            "legendFormat": "{{type}}",
            "refId": "A"
          }
        ],
        "yaxes": [
          {"format": "currencyUSD", "min": 0}
        ]
      },
      {
        "id": 7,
        "title": "Wallet Transaction Volume",
        "type": "graph",
        "gridPos": {"x": 0, "y": 24, "w": 12, "h": 8},
        "targets": [
          {
            "expr": "sum(rate(business_modification_wallet_transaction_total{type=\"DEBIT\"}[5m]))",
            "legendFormat": "Debits/min",
            "refId": "A"
          },
          {
            "expr": "sum(rate(business_modification_wallet_transaction_total{type=\"CREDIT\"}[5m]))",
            "legendFormat": "Credits/min",
            "refId": "B"
          }
        ],
        "yaxes": [
          {"format": "ops", "min": 0}
        ]
      },
      {
        "id": 8,
        "title": "Failure Reasons",
        "type": "piechart",
        "gridPos": {"x": 12, "y": 24, "w": 12, "h": 8},
        "targets": [
          {
            "expr": "sum(rate(business_modification_failure_by_type_total[5m])) by (reason)",
            "legendFormat": "{{reason}}",
            "refId": "A"
          }
        ]
      },
      {
        "id": 9,
        "title": "Success Rate by Type",
        "type": "table",
        "gridPos": {"x": 0, "y": 32, "w": 24, "h": 8},
        "targets": [
          {
            "expr": "(sum(rate(business_modification_success_by_type_total[5m])) by (type) / sum(rate(business_modification_attempt_by_type_total[5m])) by (type)) * 100",
            "format": "table",
            "instant": true,
            "refId": "A"
          }
        ],
        "transformations": [
          {
            "id": "organize",
            "options": {
              "excludeByName": {},
              "indexByName": {},
              "renameByName": {
                "type": "Modification Type",
                "Value": "Success Rate %"
              }
            }
          }
        ]
      }
    ]
  }
}
