249 lines
5.5 KiB
Markdown
249 lines
5.5 KiB
Markdown
# 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
|
|
```
|