Skip to content
GreenKube

REST API

GreenKube exposes a complete REST API powered by FastAPI, providing programmatic access to all metrics, recommendations, and configuration.

The API is served at http://<service>:8000/api/v1/ and includes:

  • Auto-generated OpenAPI docs at /docs (Swagger UI) and /redoc
  • CORS support for cross-origin dashboard access
  • JSON responses with consistent error handling
  • Pydantic v2 validation on all request/response models
MethodPathDescription
GET/healthHealth check (liveness)
GET/api/v1/versionAPI and app version
GET/api/v1/configCurrent configuration (redacted)
MethodPathDescription
GET/api/v1/metricsLatest metrics snapshot
GET/api/v1/metrics/namespacesMetrics grouped by namespace
GET/api/v1/metrics/nodesPer-node metrics and hardware info
GET/api/v1/metrics/podsPer-pod detailed metrics
MethodPathDescription
GET/api/v1/timeseriesHistorical metrics with filtering
GET/api/v1/timeseries/energyEnergy consumption over time
GET/api/v1/timeseries/carbonCarbon emissions over time
GET/api/v1/timeseries/costCost data over time
MethodPathDescription
GET/api/v1/recommendationsActive recommendations
GET/api/v1/recommendations/historyHistorical recommendations
GET/api/v1/recommendations/summaryAggregated savings potential
MethodPathDescription
GET/metricsPrometheus-format metrics for self-monitoring

Most endpoints support common query parameters:

?from=2024-01-01T00:00:00Z # Start time (ISO 8601)
&to=2024-01-31T23:59:59Z # End time (ISO 8601)
&namespace=production # Filter by namespace
&group_by=daily # Aggregation: hourly/daily/weekly/monthly
&limit=100 # Pagination
&offset=0 # Pagination offset
Terminal window
curl http://localhost:8000/api/v1/metrics | jq
Terminal window
curl "http://localhost:8000/api/v1/timeseries/carbon?namespace=production&from=2024-01-01&group_by=daily"
Terminal window
curl http://localhost:8000/api/v1/recommendations?severity=critical

By default, the API is unauthenticated (designed for cluster-internal use). For external exposure, secure it behind:

  • Kubernetes Ingress with authentication
  • OAuth2 proxy
  • Network policies

CORS is enabled by default to allow the dashboard to communicate with the API:

greenkube:
corsOrigins: "*" # Restrict in production

Use the JSON API data source plugin to pull GreenKube metrics into Grafana dashboards.

Add carbon budget checks to your pipeline:

Terminal window
CARBON=$(curl -s http://greenkube:8000/api/v1/metrics | jq '.total_carbon_grams')
if [ $(echo "$CARBON > 1000" | bc) -eq 1 ]; then
echo "Carbon budget exceeded!"
exit 1
fi

Poll recommendations and send alerts for critical findings.