Sync vault notes: April-November 2026 sessions, projects, and architecture

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
garfieldandClaude Sonnet 5.5 committed 2026-11-13 11:00:53 -05:00
1 parent fe4fe656be
commit 994c7ae577
379 files changed
+55216 -107

No files matched your search

@@ -0,0 +1,87 @@
# Observability Runbook Index
**Folder:** `SquareMCP/runbooks/observability/`
**Cluster:** `art0` (single-node MicroK8s)
**Grafana:** https://dashboard.fetcherpay.com
**Login:** `admin` / `admin_secure_2024`
---
## What this folder covers
Operational documentation for monitoring, logging, tracing, and alerting across FetcherPay and SquareMCP. This includes everything added or fixed in the 2026-06-16 monitoring session:
- OpenTelemetry Collector (traces, logs, metrics)
- FetcherPay Prometheus + remote-write receiver
- Redis exporter (new)
- Loki / Tempo operational dashboards
- Comprehensive health overview dashboard
- Alertmanager email + Slack routing
- Known unhealthy services and their root causes
---
## Quick links
| Resource | URL / Location |
|----------|----------------|
| Main health dashboard | https://dashboard.fetcherpay.com/d/fetcherpay-health-overview/fetcherpay-squaremcp-e28094-health-overview |
| Loki Operational | https://dashboard.fetcherpay.com/d/MQHVDmtWk/loki-operational |
| Tempo Operational | https://dashboard.fetcherpay.com/d/5BcHdkRgz/tempo-operational |
| Blackbox Exporter | imported dashboard in Grafana |
| MySQL Overview | imported dashboard in Grafana |
| Node Exporter Full | imported dashboard in Grafana |
| K8s cluster | imported dashboard in Grafana |
---
## Files in this runbook
| File | Purpose |
|------|---------|
| `01-monitoring-architecture.md` | What is monitored, by what, and where the data lives |
| `02-dashboards-and-queries.md` | Dashboard inventory + reusable PromQL queries |
| `03-api-reference.md` | How to query Prometheus/Loki/Tempo/Grafana via API |
| `04-alerts-and-response.md` | Alert routes, what they mean, and how to respond |
| `05-ai-agent-guide.md` | How an AI agent should use this observability stack |
| `06-human-guide.md` | How a human uses Grafana day-to-day |
| `07-known-issues.md` | Pre-existing unhealthy services and why |
---
## One-line status commands
```bash
# Cluster overview
microk8s kubectl get nodes
microk8s kubectl get pods -n fetcherpay
microk8s kubectl get pods -n observability
# Core observability health
microk8s kubectl get pods -n observability -l app=otel-collector
microk8s kubectl get pods -n fetcherpay -l app=prometheus
microk8s kubectl get pods -n observability -l app.kubernetes.io/name=grafana
# Quick Prometheus query (FetcherPay)
curl -u admin:admin_secure_2024 \
'https://dashboard.fetcherpay.com/api/datasources/proxy/uid/ffpaxh13af2f4e/api/v1/query?query=up'
```
---
## Datasource UIDs (for API use)
| Datasource | UID | Type |
|------------|-----|------|
| Prometheus (FetcherPay) | `ffpaxh13af2f4e` | prometheus |
| Prometheus (K8s Observability) | `ffpaxh1q3zo5cc` | prometheus |
| Loki | `afpb0s2gdn6yoc` | loki |
| Tempo | `efpb0sa7zs0e8f` | tempo |
| Alertmanager | `afpb0sgrf7hmoa` | alertmanager |
---
## Related vault notes
- Phase 1 Communications deploy handoff: `SquareMCP/deployments/2026-06-15-phase1-communications-deploy-handoff.md`
- Monitoring deploy session: `SquareMCP/deployments/2026-06-16-otel-collector-remote-write-loki-tempo-dashboards.md`
@@ -0,0 +1,113 @@
# Monitoring Architecture
**Stack:** Prometheus + Grafana + Loki + Tempo + Alertmanager + OpenTelemetry Collector
**Cluster:** single-node MicroK8s on `art0`
**Namespaces:**
- `fetcherpay` — app workloads and custom Prometheus/blackbox/MySQL/Redis exporters
- `observability` — kube-prometheus-stack (Grafana, K8s Prometheus, Loki, Tempo, Alertmanager, node-exporter, kube-state-metrics)
---
## Data flow
```
Applications / Websites / Host
│
├──► Blackbox exporter ──► FetcherPay Prometheus
├──► MySQL exporter ─────► FetcherPay Prometheus
├──► Redis exporter ─────► FetcherPay Prometheus
├──► OTel Collector ─────► FetcherPay Prometheus (remote write)
│ │
│ ├── metrics dashboards
│ └── Alertmanager rules
│
├──► OTel Collector ─────► Tempo (traces)
└──► OTel Collector ─────► Loki (logs)
Kube-prometheus-stack (observability namespace)
│
├──► K8s Prometheus ─────► Grafana + Alertmanager
├──► node-exporter ─────► K8s Prometheus
└──► kube-state-metrics ─► K8s Prometheus
```
---
## What is monitored where
### FetcherPay Prometheus (`prometheus.fetcherpay:9090`)
| Job | Source | Metrics |
|-----|--------|---------|
| `prometheus` | itself | Prometheus health / remote-write stats |
| `blackbox-http` | 18 HTTPS endpoints | `probe_success`, `probe_duration_seconds`, SSL expiry |
| `mysql` | host MySQL via `mysql-exporter:9104` | `mysql_*` connections, queries, replication |
| `redis` | Redis via `redis-exporter:9121` | `redis_*` memory, clients, hit ratio |
| `node-exporter` | K8s node-exporter | CPU / memory / disk / network (duplicates K8s prom) |
| `kube-state-metrics` | K8s kube-state-metrics | cluster-level pod/deployment/service state |
| `otel-collector` | OTel collector self-metrics | `otelcol_*` exporter throughput, queue size |
### K8s Observability Prometheus (`kube-prom-stack-kube-prome-prometheus.observability:9090`)
| Job | Source | Metrics |
|-----|--------|---------|
| `kubernetes-apiservers` | API server | K8s control plane |
| `kubernetes-cAdvisor` | kubelet | container resource usage |
| `kubernetes-nodes` | kubelet | node metrics |
| `kubernetes-pods` | pod service discovery | any pod with prometheus.io annotations |
| `kube-state-metrics` | kube-state-metrics | object state |
| `node-exporter` | node-exporter | hardware/OS metrics |
### Loki (`loki.observability:3100`)
- Receives logs via OTel Collector `otlp_http/loki` exporter.
- Labels: `cluster`, `job`, `namespace`, `pod`, `container` (when available).
### Tempo (`tempo.observability:4317` gRPC, `3100` HTTP)
- Receives traces via OTel Collector `otlp_grpc/tempo` exporter.
- Supports Jaeger/Zipkin/OTLP receivers on the collector.
---
## Kubernetes manifests
All manifests live in `hermes-mcp/monitoring/`:
| File | Deploys |
|------|---------|
| `opentelemetry-collector.yaml` | OTel collector Deployment/ConfigMap/Service in `observability` |
| `prometheus-deployment.yaml` | FetcherPay Prometheus Deployment in `fetcherpay` |
| `prometheus-config.yaml` | ConfigMap mounted into FetcherPay Prometheus |
| `blackbox-exporter.yaml` | Blackbox exporter in `fetcherpay` |
| `mysql-exporter.yaml` | MySQL exporter (hostNetwork) in `fetcherpay` |
| `redis-exporter.yaml` | Redis exporter in `fetcherpay` |
| `grafana-deployment.yaml` | Custom Grafana with SMTP env vars |
| `alertmanager-config.yaml` | Alertmanager config (email + Slack) |
---
## Networking and ports
| Service | Namespace | Ports | Notes |
|---------|-----------|-------|-------|
| `prometheus` | `fetcherpay` | 9090 | ClusterIP; remote-write enabled |
| `blackbox-exporter` | `fetcherpay` | 9115 | ClusterIP |
| `mysql-exporter` | `fetcherpay` | 9104 | ClusterIP; uses `hostNetwork: true` to reach host MySQL |
| `redis-exporter` | `fetcherpay` | 9121 | ClusterIP |
| `otel-collector` | `observability` | 4317, 4318, 14250, 14268, 9411, 8888 | OTLP/Jaeger/Zipkin/metrics |
| `kube-prom-stack-grafana` | `observability` | 3000 | ClusterIP; exposed via ingress |
| `kube-prom-stack-kube-prome-prometheus` | `observability` | 9090 | ClusterIP |
| `loki` | `observability` | 3100 | ClusterIP |
| `tempo` | `observability` | 3100, 4317 | ClusterIP |
| `nginx-ingress-microk8s` | `ingress` | 80, 443, 10254 | `hostNetwork: true` edge router |
---
## Notes for AI agents
- FetcherPay Prometheus is the source of truth for custom app/site/infrastructure health.
- K8s Prometheus is the source of truth for cluster/node/container metrics.
- Grafana dashboards can pull from both; the health overview dashboard uses both.
- Loki/Tempo are fed by the OTel collector, not directly by apps.
- The `kubelet` TLS cert on `art0` does not include `104.190.60.129`, so `kubectl exec`, `port-forward`, and `logs` may fail. Use `--insecure-skip-tls-verify-backend=true` for logs, or `kubectl proxy` for HTTP health checks.
@@ -0,0 +1,192 @@
# Dashboards and Queries
**Grafana:** https://dashboard.fetcherpay.com
**Login:** `admin` / `admin_secure_2024`
---
## Dashboard inventory
### Custom / session-built dashboards
| Dashboard | URL | Purpose |
|-----------|-----|---------|
| **FetcherPay / SquareMCP — Health Overview** | `/d/fetcherpay-health-overview/fetcherpay-squaremcp-e28094-health-overview` | All websites, K8s pods, DB/cache, infra health in one place |
| **Loki Operational** | `/d/MQHVDmtWk/loki-operational` | Loki ingest/query performance |
| **Tempo Operational** | `/d/5BcHdkRgz/tempo-operational` | Tempo trace ingest/query performance |
### Imported dashboards (kube-prometheus-stack + grafana.com)
| Dashboard | Source | Purpose |
|-----------|--------|---------|
| Blackbox Exporter | grafana.com | HTTPS endpoint probes |
| MySQL Overview | grafana.com | MySQL performance |
| Node Exporter Full | grafana.com | Linux node metrics |
| Kubernetes cluster | kube-prometheus-stack | K8s cluster overview |
| Kubernetes cluster monitoring | kube-prometheus-stack | K8s workload monitoring |
---
## How to create or edit a dashboard
### Human workflow
1. Log in to Grafana.
2. Click **+ → Dashboard** or open an existing dashboard and click the gear for **Settings**.
3. Add a panel. Choose the datasource:
- **Prometheus (FetcherPay)** for app/site/DB metrics
- **Prometheus (K8s Observability)** for cluster/node metrics
- **Loki** for logs
- **Tempo** for traces
4. Write the query (see reusable queries below).
5. Save. Give it a clear title, tag it (`health`, `squaremcp`, `fetcherpay`), and pick a folder.
### AI-agent workflow (API)
Use the Grafana API to import/export dashboards. See `03-api-reference.md` for full examples.
Quick import from a dashboard JSON file:
```bash
curl -u admin:admin_secure_2024 \
-X POST https://dashboard.fetcherpay.com/api/dashboards/db \
-H 'Content-Type: application/json' \
-d @dashboard.json
```
---
## Reusable PromQL queries
### Websites / external endpoints
```promql
# All sites up/down (1 = up)
probe_success{job="blackbox-http"}
# Percentage of healthy sites
avg(probe_success{job="blackbox-http"}) * 100
# Response time
probe_duration_seconds{job="blackbox-http"}
# SSL certificate days remaining
(probe_ssl_earliest_cert_expiry{job="blackbox-http"} - time()) / 86400
```
### Infrastructure services
```promql
# Up/down for all infra exporters
up{job=~"mysql|redis|node-exporter|kube-state-metrics|prometheus|otel-collector"}
# Combined single table (infra + websites)
label_replace(
up{job=~"mysql|redis|node-exporter|kube-state-metrics|prometheus|otel-collector"},
"server", "$1", "instance", "(.+)"
)
or
label_replace(
probe_success{job="blackbox-http"},
"server", "$1", "instance", "(.+)"
)
```
### Kubernetes
```promql
# Pod running ratio
sum(kube_pod_status_phase{phase="Running"}) / sum(kube_pod_status_phase)
# Pods by namespace and phase
sum by (namespace, phase) (kube_pod_status_phase)
# Top restarting containers
topk(10, kube_pod_container_status_restarts_total)
# Ingress controller restarts
kube_pod_container_status_restarts_total{namespace="ingress", pod=~".*nginx-ingress.*"}
# Node CPU %
100 - (avg by (instance) (irate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)
# Node memory %
100 * (1 - ((node_memory_MemAvailable_bytes) / node_memory_MemTotal_bytes))
# Node disk usage %
100 - ((node_filesystem_avail_bytes{mountpoint="/"} * 100) / node_filesystem_size_bytes{mountpoint="/"})
```
### Databases and caches
```promql
# MySQL up
up{job="mysql"}
# MySQL connections
mysql_global_status_threads_connected
mysql_global_status_threads_running
# MySQL slow queries/sec
irate(mysql_global_status_slow_queries[5m])
# Redis up
redis_up
# Redis memory
redis_memory_used_bytes
# Redis clients
redis_connected_clients
# Redis hit ratio
rate(redis_keyspace_hits_total[5m]) /
clamp_min(rate(redis_keyspace_hits_total[5m]) + rate(redis_keyspace_misses_total[5m]), 1)
```
### OpenTelemetry Collector
```promql
# Collector uptime
otelcol_process_uptime_total
# Metrics sent per second
rate(otelcol_exporter_sent_metric_points_total[5m])
# Exporter queue size
otelcol_exporter_queue_size
# Failed sends/sec
rate(otelcol_exporter_send_failed_metric_points_total[5m])
```
---
## Recommended new panels
If you extend the health dashboard, consider adding:
- **SSL expiry alert panel** — min of `(probe_ssl_earliest_cert_expiry - time()) / 86400` with threshold 14 days.
- **Top memory-consuming pods** — from K8s Prometheus: `topk(10, container_memory_usage_bytes{container!=""})`.
- **Error log rate** — from Loki: `{job="hermes-mcp"} |= "error"` or `{namespace="fetcherpay"} |= "ERROR"`.
- **Trace error rate** — from Tempo: search for spans with `status:error`.
---
## How to add a new website to monitor
1. Edit `monitoring/prometheus-config.yaml`.
2. Add the URL under `static_configs.targets` in the `blackbox-http` job.
3. Apply: `microk8s kubectl apply -f monitoring/prometheus-config.yaml`.
4. Restart Prometheus to reload: `microk8s kubectl rollout restart deployment/prometheus -n fetcherpay`.
5. Verify: `curl -u admin:admin_secure_2024 'https://dashboard.fetcherpay.com/api/datasources/proxy/uid/ffpaxh13af2f4e/api/v1/query?query=probe_success{instance="https://new-site.com"}'`.
---
## How to add a new exporter
1. Create or reuse a Deployment + Service manifest in `monitoring/`.
2. Add a scrape job to `monitoring/prometheus-config.yaml`.
3. Apply both.
4. Restart Prometheus.
5. Add a panel to the health dashboard.
@@ -0,0 +1,248 @@
# API Reference
All examples assume Grafana login `admin` / `admin_secure_2024`.
---
## Datasource UIDs
| Datasource | UID |
|------------|-----|
| Prometheus (FetcherPay) | `ffpaxh13af2f4e` |
| Prometheus (K8s Observability) | `ffpaxh1q3zo5cc` |
| Loki | `afpb0s2gdn6yoc` |
| Tempo | `efpb0sa7zs0e8f` |
| Alertmanager | `afpb0sgrf7hmoa` |
---
## Prometheus Query API
### FetcherPay Prometheus
```bash
DS=ffpaxh13af2f4e
QUERY='up{job="redis"}'
curl -u admin:admin_secure_2024 \
-G "https://dashboard.fetcherpay.com/api/datasources/proxy/uid/${DS}/api/v1/query" \
--data-urlencode "query=${QUERY}" \
| python3 -m json.tool
```
### Range query
```bash
DS=ffpaxh13af2f4e
QUERY='rate(otelcol_exporter_sent_metric_points_total[5m])'
curl -u admin:admin_secure_2024 \
-G "https://dashboard.fetcherpay.com/api/datasources/proxy/uid/${DS}/api/v1/query_range" \
--data-urlencode "query=${QUERY}" \
--data-urlencode "start=$(date -d '1 hour ago' +%s)" \
--data-urlencode "end=$(date +%s)" \
--data-urlencode "step=60" \
| python3 -m json.tool
```
### K8s Prometheus
```bash
DS=ffpaxh1q3zo5cc
QUERY='sum by (namespace, phase) (kube_pod_status_phase)'
curl -u admin:admin_secure_2024 \
-G "https://dashboard.fetcherpay.com/api/datasources/proxy/uid/${DS}/api/v1/query" \
--data-urlencode "query=${QUERY}" \
| python3 -m json.tool
```
---
## Grafana API
### List datasources
```bash
curl -u admin:admin_secure_2024 \
https://dashboard.fetcherpay.com/api/datasources \
| python3 -m json.tool
```
### Search dashboards
```bash
curl -u admin:admin_secure_2024 \
"https://dashboard.fetcherpay.com/api/search?query=health" \
| python3 -m json.tool
```
### Get dashboard JSON by UID
```bash
UID=fetcherpay-health-overview
curl -u admin:admin_secure_2024 \
"https://dashboard.fetcherpay.com/api/dashboards/uid/${UID}" \
| python3 -m json.tool
```
### Import / update a dashboard
Save this as `dashboard.json`, then:
```bash
curl -u admin:admin_secure_2024 \
-X POST https://dashboard.fetcherpay.com/api/dashboards/db \
-H 'Content-Type: application/json' \
-d @dashboard.json
```
Example `dashboard.json`:
```json
{
"dashboard": {
"title": "My New Dashboard",
"tags": ["squaremcp"],
"timezone": "browser",
"schemaVersion": 36,
"refresh": "30s",
"panels": [
{
"id": 1,
"title": "Website Healthy %",
"type": "stat",
"targets": [
{
"expr": "avg(probe_success{job=\"blackbox-http\"}) * 100",
"refId": "A",
"datasource": {"uid": "ffpaxh13af2f4e", "type": "prometheus"}
}
],
"gridPos": {"h": 4, "w": 12, "x": 0, "y": 0}
}
]
},
"folderId": 0,
"overwrite": true,
"message": "Imported via API"
}
```
### Import from grafana.com
Find the dashboard ID (e.g. `13407` for Loki), download, then upload:
```bash
DASHBOARD_ID=13407
curl -s "https://grafana.com/api/dashboards/${DASHBOARD_ID}/revisions/latest/download" \
| python3 -c '
import json, sys
d = json.load(sys.stdin)
d.pop("id", None)
print(json.dumps({"dashboard": d, "folderId": 0, "overwrite": True}))
' > /tmp/import.json
curl -u admin:admin_secure_2024 \
-X POST https://dashboard.fetcherpay.com/api/dashboards/db \
-H 'Content-Type: application/json' \
-d @/tmp/import.json
```
---
## Loki API
### Query logs
```bash
DS=afpb0s2gdn6yoc
QUERY='{namespace="fetcherpay"} |~ "ERROR|error|Error"'
curl -u admin:admin_secure_2024 \
-G "https://dashboard.fetcherpay.com/api/datasources/proxy/uid/${DS}/loki/api/v1/query_range" \
--data-urlencode "query=${QUERY}" \
--data-urlencode "start=$(date -d '1 hour ago' +%s)000000000" \
--data-urlencode "end=$(date +%s)000000000" \
--data-urlencode "limit=100" \
| python3 -m json.tool
```
### Label values
```bash
curl -u admin:admin_secure_2024 \
"https://dashboard.fetcherpay.com/api/datasources/proxy/uid/afpb0s2gdn6yoc/loki/api/v1/label/namespace/values" \
| python3 -m json.tool
```
---
## Tempo API
### Search recent traces
```bash
curl -u admin:admin_secure_2024 \
-G "https://dashboard.fetcherpay.com/api/datasources/proxy/uid/efpb0sa7zs0e8f/api/search" \
--data-urlencode "limit=20" \
| python3 -m json.tool
```
### Query by Trace ID
```bash
TRACE_ID=<trace-id>
curl -u admin:admin_secure_2024 \
"https://dashboard.fetcherpay.com/api/datasources/proxy/uid/efpb0sa7zs0e8f/api/traces/${TRACE_ID}" \
| python3 -m json.tool
```
---
## Alertmanager API
### Active alerts
```bash
curl -u admin:admin_secure_2024 \
"https://dashboard.fetcherpay.com/api/datasources/proxy/uid/afpb0sgrf7hmoa/api/v2/alerts" \
| python3 -m json.tool
```
### Silences
```bash
curl -u admin:admin_secure_2024 \
"https://dashboard.fetcherpay.com/api/datasources/proxy/uid/afpb0sgrf7hmoa/api/v2/silences" \
| python3 -m json.tool
```
---
## Kubernetes API via `kubectl proxy`
Because the kubelet TLS cert does not include `104.190.60.129`, `kubectl exec`/`port-forward`/`logs` can fail. `kubectl proxy` works because it talks to the API server.
```bash
microk8s kubectl proxy --port=8000 &
# Access a service HTTP endpoint through the proxy
curl http://localhost:8000/api/v1/namespaces/observability/services/otel-collector:metrics/proxy/metrics
# Stop proxy when done
kill %1
```
---
## Hermes Communications API (cross-reference)
The monitoring stack watches `https://hermes.squaremcp.com/health`. For the Hermes business API, see `SquareMCP/deployments/2026-06-15-phase1-communications-deploy-handoff.md`.
Quick health check:
```bash
curl -s https://hermes.squaremcp.com/health
```
@@ -0,0 +1,162 @@
# Alerts and Incident Response
**Alertmanager:** configured in `monitoring/alertmanager-config.yaml`
**Receivers:**
- Email → `garfield@squaremcp.com` via Azure Comm Services (`smtp.azurecomm.net:587`)
- Slack → `#alerts` via existing webhook
---
## Current alert routing
| Alert | Severity | Route | Action |
|-------|----------|-------|--------|
| Default alerts | critical/warning | Slack `#alerts` + email | Page/notify |
| `InfoInhibitor` | info | `null` | Suppressed |
| `Watchdog` | none | `null` | Heartbeat, no notification |
---
## Alerts to pay attention to
### Website down
**Likely cause:** certificate expiry, DNS issue, ingress misconfig, service crash, host/network outage.
**PromQL:** `probe_success{job="blackbox-http"} == 0`
**Response:**
1. Check `probe_duration_seconds` to see if it is a timeout vs. connection refused.
2. Test manually: `curl -I https://<site>`.
3. Check ingress: `microk8s kubectl get ingress -A` and `microk8s kubectl get pods -n ingress`.
4. Check the backing pod logs: `microk8s kubectl logs -n <namespace> -l app=<app> --insecure-skip-tls-verify-backend=true`.
5. Check SSL expiry: `(probe_ssl_earliest_cert_expiry - time()) / 86400`.
### MySQL down
**PromQL:** `up{job="mysql"} == 0` or `mysql_up == 0`
**Response:**
1. MySQL runs as a Docker container on the host at `:3306`.
2. Check container: `docker ps | grep mysql` or `ss -tlnp | grep 3306`.
3. If stopped, restart from the `fetcherpay_mysql_data` volume (see previous deployment notes).
4. Check mysql-exporter pod: `microk8s kubectl get pods -n fetcherpay -l app=mysql-exporter`.
### Redis down
**PromQL:** `up{job="redis"} == 0` or `redis_up == 0`
**Response:**
1. Check Redis pod: `microk8s kubectl get pods -n fetcherpay -l app=redis`.
2. Check logs: `microk8s kubectl logs -n fetcherpay -l app=redis --insecure-skip-tls-verify-backend=true`.
3. Verify exporter: `microk8s kubectl get pods -n fetcherpay -l app=redis-exporter`.
### Prometheus down
**PromQL:** `up{job="prometheus"} == 0`
**Response:**
1. Check pod: `microk8s kubectl get pods -n fetcherpay -l app=prometheus`.
2. Check logs; common issue is invalid config.
3. If ConfigMap changed, restart: `microk8s kubectl rollout restart deployment/prometheus -n fetcherpay`.
### OTel collector down
**PromQL:** `up{job="otel-collector"} == 0` or absent `otelcol_process_uptime_total`
**Response:**
1. Check pod: `microk8s kubectl get pods -n observability -l app=otel-collector`.
2. Common failure: invalid YAML config. Fix and reapply `monitoring/opentelemetry-collector.yaml`.
3. Restart: `microk8s kubectl rollout restart deployment/otel-collector -n observability`.
### High container restart rate
**PromQL:** `rate(kube_pod_container_status_restarts_total[5m]) > 0.01`
**Response:**
1. Identify pod/namespace from labels.
2. Check events: `microk8s kubectl describe pod -n <ns> <pod>`.
3. Check logs (with TLS skip flag if needed).
4. Investigate resource limits, OOM, liveness probe failures.
### Node CPU / memory / disk high
**PromQL:**
- CPU: `100 - (avg by (instance) (irate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 85`
- Memory: `100 * (1 - (node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes)) > 85`
- Disk: `100 - ((node_filesystem_avail_bytes{mountpoint="/"} * 100) / node_filesystem_size_bytes{mountpoint="/"}) > 85`
**Response:**
1. Identify which pod/container is consuming resources via K8s Prometheus.
2. Scale, restart, or optimize the offending workload.
3. For disk: clean logs, old images (`docker system prune -a`), or expand storage.
### SSL certificate expiring
**PromQL:** `(probe_ssl_earliest_cert_expiry{job="blackbox-http"} - time()) / 86400 < 14`
**Response:**
1. Renew the cert (likely cert-manager handles this).
2. Check cert-manager: `microk8s kubectl get certificates -A`.
3. Force renewal if stuck.
---
## Pre-existing issues that will trigger alerts
These are already unhealthy and will show red in dashboards. They are not caused by recent deployments.
### `fetcherpay-leads-api` / `fetcherpay-leads-worker` ImagePullBackOff
**Why:** stale image references to dead registry `23.120.207.35:32000`. Current registry is `localhost:32000`, and tag `v16-import-fix` does not exist.
**Fix options:**
1. Update Deployments to use `localhost:32000/fetcherpay/leads-api:latest`.
2. Delete the Deployments if the leads feature is abandoned.
### `nginx-ingress-microk8s-controller` restarts
**Why:** chronic single-node instability (~1 restart/day over 9 months). Likely OOM, liveness timeouts, or containerd sandbox churn.
**Mitigation:**
- Add memory request/limit to the ingress DaemonSet.
- Monitor `kube_pod_container_status_restarts_total{namespace="ingress"}`.
- Check `dmesg` / kernel OOM logs if restarts spike.
---
## How to add a new alert rule
1. Edit the Prometheus ConfigMap or kube-prometheus-stack PrometheusRule CRDs.
2. For FetcherPay Prometheus, add a `rule_files` section or use `recording_rules`/`alerting_rules` in `monitoring/prometheus-config.yaml`.
3. Apply and restart Prometheus.
4. Verify in Alertmanager: `https://dashboard.fetcherpay.com/alerting/` or API.
Example simple rule:
```yaml
groups:
- name: fetcherpay
rules:
- alert: WebsiteDown
expr: probe_success{job="blackbox-http"} == 0
for: 2m
labels:
severity: critical
annotations:
summary: "Website {{ $labels.instance }} is down"
```
---
## Runbook quick-decision tree
```
ALERT fires
│
├─ Is it a website? → check probe_success, curl manually, check ingress
├─ Is it MySQL/Redis/Prometheus/OTel? → check pod status, restart if needed
├─ Is it a pod restart spike? → describe pod, check OOM/probes
├─ Is it node resource pressure? → identify top consumer, scale/restart
└─ Is it a known pre-existing issue? → document, do not page unless it worsens
```
@@ -0,0 +1,127 @@
# AI Agent Guide — Observability Stack
This guide is written for coding/operations AI agents working on FetcherPay / SquareMCP.
---
## Your job
Use the observability stack to:
1. Verify system health before and after changes.
2. Diagnose failures quickly.
3. Avoid false alarms by understanding pre-existing issues.
4. Document what you find back into this vault.
---
## Checklist before making changes
- [ ] Open the health dashboard: https://dashboard.fetcherpay.com/d/fetcherpay-health-overview
- [ ] Confirm no unexpected red panels (ignore known issues in `07-known-issues.md`).
- [ ] If touching Hermes, hit `https://hermes.squaremcp.com/health`.
- [ ] If touching MySQL, confirm `redis_up` and MySQL `up` are 1.
- [ ] If touching ingress, confirm `nginx-ingress-microk8s-controller` is Running.
---
## How to query state programmatically
Use the APIs in `03-api-reference.md`. Preferred pattern:
```python
import json, urllib.request, urllib.error, base64
GRAFANA_URL = 'https://dashboard.fetcherpay.com'
AUTH = base64.b64encode(b'admin:admin_secure_2024').decode()
def prom_query(uid, q):
url = f'{GRAFANA_URL}/api/datasources/proxy/uid/{uid}/api/v1/query?query={urllib.parse.quote(q)}'
req = urllib.request.Request(url)
req.add_header('Authorization', f'Basic {AUTH}')
with urllib.request.urlopen(req, timeout=30) as r:
return json.loads(r.read())
# Example: are all websites healthy?
res = prom_query('ffpaxh13af2f4e', 'avg(probe_success{job="blackbox-http"})')
healthy_pct = float(res['data']['result'][0]['value'][1]) * 100
print(f'{healthy_pct:.0f}% websites healthy')
```
---
## Common agent tasks
### Check if a pod is running
```bash
microk8s kubectl get pods -n <namespace> -l app=<app>
```
If direct `logs`/`exec` fails with TLS error, use:
```bash
microk8s kubectl logs -n <namespace> -l app=<app> --insecure-skip-tls-verify-backend=true --tail=50
```
Or use `kubectl proxy` for HTTP health endpoints:
```bash
microk8s kubectl proxy --port=8000 &
curl http://localhost:8000/api/v1/namespaces/<ns>/services/<svc>:<port>/proxy/<path>
```
### Add a new website to the health dashboard
1. Edit `hermes-mcp/monitoring/prometheus-config.yaml`.
2. Add URL to `blackbox-http` targets.
3. Commit, push, apply.
4. Restart Prometheus.
5. Verify with `probe_success{instance="https://new-site.com"}`.
### Add a new metric panel to a dashboard
1. Get the dashboard JSON via `/api/dashboards/uid/<uid>`.
2. Add a panel object with a PromQL target.
3. POST back to `/api/dashboards/db` with `overwrite: true`.
4. Test the query first via the Prometheus query API.
### Investigate an alert
1. Read the alert labels (severity, instance, job).
2. Look up the matching PromQL in `04-alerts-and-response.md`.
3. Query the metric directly.
4. Check pod status and logs.
5. Fix or silence, then document the outcome in this vault.
---
## What NOT to do
- **Do not** restart the ingress controller unless it is actually failing requests.
- **Do not** delete the `fetcherpay-leads-*` pods expecting them to fix themselves — they have stale image refs.
- **Do not** run `docker system prune` without checking if MySQL or MT5 containers are running.
- **Do not** leave `kubectl proxy` background processes running indefinitely.
- **Do not** change `monitoring/alertmanager-config.yaml` without testing SMTP/Slack delivery.
---
## Decision tree
```
User asks "Is X down?"
│
├─ Check health dashboard first
├─ If red, query probe_success / up metric
├─ If pod-related, check kubectl get pods / logs
├─ If known issue (leads, nginx restarts), explain root cause
└─ Update this vault if the failure is new or unresolved
```
---
## Vault update discipline
After every significant investigation or change:
1. Update the relevant runbook file.
2. If it is a deployment, also add/update `SquareMCP/deployments/YYYY-MM-DD-*.md`.
3. Cross-link from `00-index.md` if a new topic is introduced.
@@ -0,0 +1,98 @@
# Human Guide — Observability Stack
For humans monitoring FetcherPay / SquareMCP.
---
## Daily workflow
1. Open the main dashboard: https://dashboard.fetcherpay.com/d/fetcherpay-health-overview
2. Scan for red panels.
3. Ignore the known pre-existing issues:
- `fetcherpay-leads-api` / `fetcherpay-leads-worker` ImagePullBackOff
- `nginx-ingress-microk8s-controller` restart count slowly climbing
4. Anything else red → investigate using this runbook.
---
## Grafana basics
- **Login:** `admin` / `admin_secure_2024`
- **Time picker:** top-right. Default is "Last 1 hour". Use "Last 6 hours" or "Last 24 hours" for trends.
- **Refresh:** next to the time picker. Set to 30s for live views, Off when investigating history.
- **Variables:** some dashboards have dropdowns at the top (namespace, pod, job).
- **Panel menu:** click the panel title → **Edit** to see the query, **Inspect → Data** to see raw values.
---
## Reading the health overview dashboard
| Section | What to watch |
|---------|---------------|
| **Websites** | "Websites Healthy %" should be 100. Red rows in "Website Status" mean a site is down or returning non-2xx. |
| **Kubernetes Cluster** | "Pods Running Ratio" should be close to 1. "Ingress Controller Restarts" slowly climbing is known; a sudden spike is bad. |
| **Databases & Caches** | MySQL and Redis panels should be green/healthy. Memory graphs show normal usage over time. |
| **Infrastructure & Observability** | Prometheus, OTel collector, Blackbox exporter should be up. "OTel Metrics Sent / sec" should be > 0. |
---
## Investigating a problem
### A website is red
1. Hover over the "Website Status" row to see which URL is failing.
2. Open a terminal and test it: `curl -I https://<site>`.
3. Check the "Website Response Time" panel — timeout vs fast failure tells you if it is DNS/network vs app crash.
4. If the site is a K8s service, check the backing pod: `microk8s kubectl get pods -n <namespace>`.
### MySQL or Redis is red
1. Check the service pod is Running.
2. Look at the error log panel if available.
3. For MySQL, it runs in Docker on the host — check `docker ps | grep -i mysql`.
### A pod keeps restarting
1. Note the namespace/pod from the "Top Container Restarts" panel.
2. Run: `microk8s kubectl describe pod -n <ns> <pod>`.
3. Look at the **Events** and **Last State** sections for OOMKilled, Error, or CrashLoopBackOff.
4. If logs are needed, use the TLS skip flag: `microk8s kubectl logs -n <ns> <pod> --previous --insecure-skip-tls-verify-backend=true`.
### You get an email/Slack alert
1. Read the alert summary.
2. Open Grafana and find the matching metric.
3. Follow the response steps in `04-alerts-and-response.md`.
4. If it is a known issue, acknowledge and move on.
5. If it is new, fix it and document it.
---
## Adding a human-readable note to a dashboard
1. Open the dashboard → **Settings** (gear icon) → **General**.
2. Add a description or tags.
3. Save with a meaningful message.
---
## Keyboard shortcuts
- `d + s` — dashboard settings
- `e` — edit panel (when focused)
- `v` — toggle view mode
- `t` — change time range
- `r` — refresh
---
## Who to notify
| Issue | Notify |
|-------|--------|
| Site-wide outage | `#alerts` Slack + garfield@squaremcp.com |
| Hermes API down | Engineering + product |
| MySQL/Redis down | Engineering immediately |
| SSL cert < 7 days | Engineering |
| Slow website response | Engineering + infrastructure |
| Known issues unchanged | No action needed unless worsening |
@@ -0,0 +1,113 @@
# Known Issues
Last updated: 2026-06-16
These issues are pre-existing and not caused by recent deployments. They will show as unhealthy in dashboards/alerts.
---
## `fetcherpay-leads-api` — `ImagePullBackOff`
| | |
|---|---|
| **Pod** | `fetcherpay-leads-api-789995b658-c2dp2` |
| **Image** | `23.120.207.35:32000/fetcherpay/leads-api:latest` |
| **Status** | `ImagePullBackOff` |
| **Restarts** | 173 |
**Root cause:** the image registry IP `23.120.207.35:32000` no longer responds. The current registry is `localhost:32000`, and `fetcherpay/leads-api:latest` exists there.
**Fix:** update the Deployment image to `localhost:32000/fetcherpay/leads-api:latest`.
**Impact:** leads API is unavailable.
---
## `fetcherpay-leads-worker` — `ImagePullBackOff`
| | |
|---|---|
| **Pod** | `fetcherpay-leads-worker-85b96f8b56-kshdf` |
| **Image** | `23.120.207.35:32000/fetcherpay/leads-api:v16-import-fix` |
| **Status** | `ImagePullBackOff` |
| **Restarts** | 0 (new pod) |
**Root cause:** same dead registry IP, and tag `v16-import-fix` does not exist in `localhost:32000`. Available tags: `latest`, `v15-clean-imports`, `v14-import-fix`, `v13-ssl-fix`, `v11-smtp-fix`.
**Fix:** repoint to a valid tag such as `localhost:32000/fetcherpay/leads-api:v15-clean-imports` or `latest`.
**Impact:** leads background worker is unavailable.
---
## `nginx-ingress-microk8s-controller` — chronic restarts
| | |
|---|---|
| **Pod** | `nginx-ingress-microk8s-controller-w8ddl` |
| **Namespace** | `ingress` |
| **Restarts** | 314+ over ~269 days (~1.17/day) |
| **Current state** | Running, Ready |
**Root cause:** chronic single-node instability. Most likely memory pressure / OOMKilled, liveness probe timeouts, or containerd/CRI-o sandbox churn. No recent events because the pod is currently healthy.
**Mitigation:**
- Add memory request/limit to the ingress DaemonSet.
- Monitor restart rate; sudden spikes warrant investigation.
- Check kernel OOM logs (`dmesg | grep -i kill`) after the next restart.
**Impact:** brief edge-routing blips during restarts; ingress recovers automatically.
---
## `cm-acme-http-solver-k5m82` — high restart count
| | |
|---|---|
| **Namespace** | `fetcherpay` |
| **Restarts** | 189 |
| **Current state** | Running |
**Root cause:** cert-manager ACME challenge solver pod. Frequent restarts may indicate certificate renewal churn or challenge failures.
**Action:** check cert-manager logs if SSL expiry alerts appear.
---
## Kubelet TLS cert mismatch
**Symptom:** `kubectl exec`, `port-forward`, `logs`, `attach` fail with:
```
tls: failed to verify certificate: x509: certificate is valid for 23.120.207.35, 172.17.0.1, ... not 104.190.60.129
```
**Root cause:** the kubelet serving certificate does not include the public IP `104.190.60.129`.
**Workarounds:**
- For logs: `kubectl logs ... --insecure-skip-tls-verify-backend=true`
- For HTTP checks: `kubectl proxy --port=8000` and use the API server proxy URL.
- For shell access: use `kubectl debug` node or SSH directly to `art0`.
---
## MT5 Docker port bindings
**Started:** 2026-06-16
**Container:** `mt5` (`gmag11/metatrader5_vnc:1.1`)
**Host ports bound:** `0.0.0.0:3000`, `0.0.0.0:8001`
**Notes:**
- K8s services internally use ports 3000 and 8001 as ClusterIP, but those are not bound on the host.
- NodePorts use the 30000–32767 range.
- MT5 does **not** currently conflict with K8s.
- If you later need to `kubectl port-forward` to `localhost:3000` or `:8001`, stop MT5 first.
---
## Recommended cleanup actions
1. **Decide on leads service fate.** Either fix image refs or delete the Deployments.
2. **Stabilize ingress controller.** Add memory limits and monitor restart rate.
3. **Regenerate kubelet cert** to include `104.190.60.129` if direct pod exec becomes critical.
4. **Add alert rules** for the issues above so severity is known and routed correctly.