# services/monitoring/grafana-dashboard-mail.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: grafana-dashboard-mail
  labels:
    grafana_dashboard: "1"
data:
  atlas-mail.json: |
    {
      "uid": "atlas-mail",
      "title": "Atlas Mail",
      "folderUid": "atlas-internal",
      "editable": true,
      "panels": [
        {
          "id": 1,
          "type": "stat",
          "title": "Sent (1d)",
          "datasource": {
            "type": "prometheus",
            "uid": "atlas-vm"
          },
          "gridPos": {
            "h": 4,
            "w": 6,
            "x": 0,
            "y": 0
          },
          "targets": [
            {
              "expr": "max(postmark_outbound_sent{window=\"1d\"})",
              "refId": "A"
            }
          ],
          "fieldConfig": {
            "defaults": {
              "color": {
                "mode": "thresholds"
              },
              "mappings": [],
              "thresholds": {
                "mode": "absolute",
                "steps": [
                  {
                    "color": "rgba(115, 115, 115, 1)",
                    "value": null
                  },
                  {
                    "color": "dark-green",
                    "value": 1
                  }
                ]
              },
              "unit": "none",
              "custom": {
                "displayMode": "auto"
              },
              "decimals": 0
            },
            "overrides": []
          },
          "options": {
            "colorMode": "value",
            "graphMode": "area",
            "justifyMode": "center",
            "reduceOptions": {
              "calcs": [
                "lastNotNull"
              ],
              "fields": "",
              "values": false
            },
            "textMode": "value"
          }
        },
        {
          "id": 2,
          "type": "stat",
          "title": "Sent (7d)",
          "datasource": {
            "type": "prometheus",
            "uid": "atlas-vm"
          },
          "gridPos": {
            "h": 4,
            "w": 6,
            "x": 6,
            "y": 0
          },
          "targets": [
            {
              "expr": "max(postmark_outbound_sent{window=\"7d\"})",
              "refId": "A"
            }
          ],
          "fieldConfig": {
            "defaults": {
              "color": {
                "mode": "thresholds"
              },
              "mappings": [],
              "thresholds": {
                "mode": "absolute",
                "steps": [
                  {
                    "color": "rgba(115, 115, 115, 1)",
                    "value": null
                  },
                  {
                    "color": "dark-green",
                    "value": 1
                  }
                ]
              },
              "unit": "none",
              "custom": {
                "displayMode": "auto"
              },
              "decimals": 0
            },
            "overrides": []
          },
          "options": {
            "colorMode": "value",
            "graphMode": "area",
            "justifyMode": "center",
            "reduceOptions": {
              "calcs": [
                "lastNotNull"
              ],
              "fields": "",
              "values": false
            },
            "textMode": "value"
          }
        },
        {
          "id": 3,
          "type": "stat",
          "title": "Mail Bounces (1d)",
          "datasource": {
            "type": "prometheus",
            "uid": "atlas-vm"
          },
          "gridPos": {
            "h": 4,
            "w": 6,
            "x": 12,
            "y": 0
          },
          "targets": [
            {
              "expr": "max(postmark_outbound_bounce_rate{window=\"1d\"})",
              "refId": "A",
              "legendFormat": "Rate"
            },
            {
              "expr": "max(postmark_outbound_bounced{window=\"1d\"})",
              "refId": "B",
              "legendFormat": "Count"
            }
          ],
          "fieldConfig": {
            "defaults": {
              "color": {
                "mode": "thresholds"
              },
              "custom": {
                "displayMode": "auto"
              },
              "thresholds": {
                "mode": "absolute",
                "steps": [
                  {
                    "color": "dark-green",
                    "value": null
                  },
                  {
                    "color": "dark-yellow",
                    "value": 5
                  },
                  {
                    "color": "dark-orange",
                    "value": 8
                  },
                  {
                    "color": "dark-red",
                    "value": 10
                  }
                ]
              },
              "unit": "none"
            },
            "overrides": [
              {
                "matcher": {
                  "id": "byName",
                  "options": "Rate"
                },
                "properties": [
                  {
                    "id": "unit",
                    "value": "percent"
                  }
                ]
              },
              {
                "matcher": {
                  "id": "byName",
                  "options": "Count"
                },
                "properties": [
                  {
                    "id": "unit",
                    "value": "none"
                  }
                ]
              }
            ]
          },
          "options": {
            "colorMode": "value",
            "graphMode": "area",
            "justifyMode": "center",
            "reduceOptions": {
              "calcs": [
                "lastNotNull"
              ],
              "fields": "",
              "values": false
            },
            "textMode": "name_and_value"
          }
        },
        {
          "id": 4,
          "type": "stat",
          "title": "Success Rate (1d)",
          "datasource": {
            "type": "prometheus",
            "uid": "atlas-vm"
          },
          "gridPos": {
            "h": 4,
            "w": 6,
            "x": 18,
            "y": 0
          },
          "targets": [
            {
              "expr": "clamp_min(100 - max(postmark_outbound_bounce_rate{window=\"1d\"}), 0)",
              "refId": "A"
            }
          ],
          "fieldConfig": {
            "defaults": {
              "color": {
                "mode": "thresholds"
              },
              "mappings": [],
              "thresholds": {
                "mode": "absolute",
                "steps": [
                  {
                    "color": "dark-red",
                    "value": null
                  },
                  {
                    "color": "dark-orange",
                    "value": 90
                  },
                  {
                    "color": "dark-yellow",
                    "value": 95
                  },
                  {
                    "color": "dark-green",
                    "value": 98
                  }
                ]
              },
              "unit": "percent",
              "custom": {
                "displayMode": "auto"
              },
              "decimals": 1
            },
            "overrides": []
          },
          "options": {
            "colorMode": "value",
            "graphMode": "area",
            "justifyMode": "center",
            "reduceOptions": {
              "calcs": [
                "lastNotNull"
              ],
              "fields": "",
              "values": false
            },
            "textMode": "value"
          }
        },
        {
          "id": 5,
          "type": "stat",
          "title": "Limit Used (30d)",
          "datasource": {
            "type": "prometheus",
            "uid": "atlas-vm"
          },
          "gridPos": {
            "h": 4,
            "w": 6,
            "x": 0,
            "y": 4
          },
          "targets": [
            {
              "expr": "max(postmark_sending_limit_used_percent)",
              "refId": "A"
            }
          ],
          "fieldConfig": {
            "defaults": {
              "color": {
                "mode": "thresholds"
              },
              "mappings": [],
              "thresholds": {
                "mode": "absolute",
                "steps": [
                  {
                    "color": "dark-green",
                    "value": null
                  },
                  {
                    "color": "dark-yellow",
                    "value": 70
                  },
                  {
                    "color": "dark-orange",
                    "value": 85
                  },
                  {
                    "color": "dark-red",
                    "value": 95
                  }
                ]
              },
              "unit": "percent",
              "custom": {
                "displayMode": "auto"
              },
              "decimals": 1
            },
            "overrides": []
          },
          "options": {
            "colorMode": "value",
            "graphMode": "area",
            "justifyMode": "center",
            "reduceOptions": {
              "calcs": [
                "lastNotNull"
              ],
              "fields": "",
              "values": false
            },
            "textMode": "value"
          }
        },
        {
          "id": 6,
          "type": "stat",
          "title": "Send Limit (30d)",
          "datasource": {
            "type": "prometheus",
            "uid": "atlas-vm"
          },
          "gridPos": {
            "h": 4,
            "w": 6,
            "x": 6,
            "y": 4
          },
          "targets": [
            {
              "expr": "max(postmark_sending_limit)",
              "refId": "A"
            }
          ],
          "fieldConfig": {
            "defaults": {
              "color": {
                "mode": "thresholds"
              },
              "mappings": [],
              "thresholds": {
                "mode": "absolute",
                "steps": [
                  {
                    "color": "rgba(115, 115, 115, 1)",
                    "value": null
                  },
                  {
                    "color": "dark-green",
                    "value": 1
                  }
                ]
              },
              "unit": "none",
              "custom": {
                "displayMode": "auto"
              },
              "decimals": 0
            },
            "overrides": []
          },
          "options": {
            "colorMode": "value",
            "graphMode": "area",
            "justifyMode": "center",
            "reduceOptions": {
              "calcs": [
                "lastNotNull"
              ],
              "fields": "",
              "values": false
            },
            "textMode": "value"
          }
        },
        {
          "id": 7,
          "type": "stat",
          "title": "Last Success",
          "datasource": {
            "type": "prometheus",
            "uid": "atlas-vm"
          },
          "gridPos": {
            "h": 4,
            "w": 6,
            "x": 12,
            "y": 4
          },
          "targets": [
            {
              "expr": "max(postmark_last_success_timestamp_seconds)",
              "refId": "A"
            }
          ],
          "fieldConfig": {
            "defaults": {
              "color": {
                "mode": "thresholds"
              },
              "mappings": [],
              "thresholds": {
                "mode": "absolute",
                "steps": [
                  {
                    "color": "rgba(115, 115, 115, 1)",
                    "value": null
                  },
                  {
                    "color": "dark-green",
                    "value": 1
                  }
                ]
              },
              "unit": "dateTimeAsIso",
              "custom": {
                "displayMode": "auto"
              },
              "decimals": 0
            },
            "overrides": []
          },
          "options": {
            "colorMode": "value",
            "graphMode": "area",
            "justifyMode": "center",
            "reduceOptions": {
              "calcs": [
                "lastNotNull"
              ],
              "fields": "",
              "values": false
            },
            "textMode": "value"
          }
        },
        {
          "id": 8,
          "type": "stat",
          "title": "Exporter Errors",
          "datasource": {
            "type": "prometheus",
            "uid": "atlas-vm"
          },
          "gridPos": {
            "h": 4,
            "w": 6,
            "x": 18,
            "y": 4
          },
          "targets": [
            {
              "expr": "sum(postmark_request_errors_total)",
              "refId": "A"
            }
          ],
          "fieldConfig": {
            "defaults": {
              "color": {
                "mode": "thresholds"
              },
              "mappings": [],
              "thresholds": {
                "mode": "absolute",
                "steps": [
                  {
                    "color": "rgba(115, 115, 115, 1)",
                    "value": null
                  },
                  {
                    "color": "dark-green",
                    "value": 1
                  }
                ]
              },
              "unit": "none",
              "custom": {
                "displayMode": "auto"
              },
              "decimals": 0
            },
            "overrides": []
          },
          "options": {
            "colorMode": "value",
            "graphMode": "area",
            "justifyMode": "center",
            "reduceOptions": {
              "calcs": [
                "lastNotNull"
              ],
              "fields": "",
              "values": false
            },
            "textMode": "value"
          }
        },
        {
          "id": 13,
          "type": "timeseries",
          "title": "Bounce Rate (1d vs 7d)",
          "datasource": {
            "type": "prometheus",
            "uid": "atlas-vm"
          },
          "gridPos": {
            "h": 8,
            "w": 12,
            "x": 0,
            "y": 12
          },
          "targets": [
            {
              "expr": "max by (window) (postmark_outbound_bounce_rate)",
              "refId": "A",
              "legendFormat": "{{window}}"
            }
          ],
          "fieldConfig": {
            "defaults": {
              "unit": "percent"
            },
            "overrides": []
          },
          "options": {
            "legend": {
              "displayMode": "table",
              "placement": "right"
            },
            "tooltip": {
              "mode": "multi"
            }
          }
        },
        {
          "id": 14,
          "type": "timeseries",
          "title": "Bounced (1d vs 7d)",
          "datasource": {
            "type": "prometheus",
            "uid": "atlas-vm"
          },
          "gridPos": {
            "h": 8,
            "w": 12,
            "x": 12,
            "y": 12
          },
          "targets": [
            {
              "expr": "max by (window) (postmark_outbound_bounced)",
              "refId": "A",
              "legendFormat": "{{window}}"
            }
          ],
          "fieldConfig": {
            "defaults": {
              "unit": "none"
            },
            "overrides": []
          },
          "options": {
            "legend": {
              "displayMode": "table",
              "placement": "right"
            },
            "tooltip": {
              "mode": "multi"
            }
          }
        },
        {
          "id": 15,
          "type": "timeseries",
          "title": "Sent (1d vs 7d)",
          "datasource": {
            "type": "prometheus",
            "uid": "atlas-vm"
          },
          "gridPos": {
            "h": 8,
            "w": 12,
            "x": 0,
            "y": 20
          },
          "targets": [
            {
              "expr": "max by (window) (postmark_outbound_sent)",
              "refId": "A",
              "legendFormat": "{{window}}"
            }
          ],
          "fieldConfig": {
            "defaults": {
              "unit": "none"
            },
            "overrides": []
          },
          "options": {
            "legend": {
              "displayMode": "table",
              "placement": "right"
            },
            "tooltip": {
              "mode": "multi"
            }
          }
        },
        {
          "id": 16,
          "type": "timeseries",
          "title": "Exporter Errors",
          "datasource": {
            "type": "prometheus",
            "uid": "atlas-vm"
          },
          "gridPos": {
            "h": 8,
            "w": 12,
            "x": 12,
            "y": 20
          },
          "targets": [
            {
              "expr": "sum(postmark_request_errors_total)",
              "refId": "A"
            }
          ],
          "fieldConfig": {
            "defaults": {
              "unit": "none"
            },
            "overrides": []
          },
          "options": {
            "legend": {
              "displayMode": "table",
              "placement": "bottom"
            },
            "tooltip": {
              "mode": "multi"
            }
          }
        }
      ],
      "time": {
        "from": "now-30d",
        "to": "now"
      },
      "annotations": {
        "list": []
      },
      "schemaVersion": 39,
      "style": "dark",
      "tags": [
        "atlas",
        "mail"
      ]
    }
