Skip to content
GreenKube

API Reference

import { Aside } from ‘@astrojs/starlight/components’;

GreenKube exposes a REST API built with FastAPI. Interactive Swagger documentation is available at /api/v1/docs when the server is running.

http://localhost:8000/api/v1

The API currently does not require authentication. It is intended to be accessed within the cluster network or via port-forward.

Health check endpoint. Returns the application status and version.

Response:

{
"status": "healthy",
"version": "0.2.0",
"uptime_seconds": 3600
}

Returns the application version.

Response:

{
"version": "0.2.0"
}

Returns the current configuration (sensitive values are redacted).

Response:

{
"db_type": "postgres",
"cloud_provider": "aws",
"default_zone": "FR",
"default_intensity": 500.0,
"prometheus_url": "http://prometheus:9090",
"api_port": 8000,
"normalization_granularity": "hour"
}

Retrieve per-pod metrics with optional filtering.

Query Parameters:

ParameterTypeDescriptionDefault
namespacestringFilter by namespaceAll
laststringTime range (e.g., 24h, 7d, 30d)24h
podstringFilter by pod name patternAll

Example Request:

Terminal window
curl "http://localhost:8000/api/v1/metrics?namespace=default&last=24h"

Response:

{
"metrics": [
{
"pod_name": "api-deployment-7b5f8c9d6-x2k4p",
"namespace": "default",
"timestamp": "2024-02-21T14:00:00Z",
"duration_seconds": 300,
"joules": 1250.5,
"co2e_grams": 0.174,
"total_cost": 0.0023,
"grid_intensity": 45.2,
"pue": 1.2,
"cpu_request": 250,
"cpu_usage_millicores": 85.3,
"memory_request": 268435456,
"memory_usage_bytes": 134217728,
"network_receive_bytes": 1048576,
"network_transmit_bytes": 524288,
"disk_read_bytes": 2097152,
"disk_write_bytes": 1048576,
"restart_count": 0,
"node": "ip-10-0-1-42",
"node_instance_type": "m5.xlarge",
"emaps_zone": "FR",
"is_estimated": false
}
],
"total": 42,
"period": {
"start": "2024-02-20T14:00:00Z",
"end": "2024-02-21T14:00:00Z"
}
}

Aggregated summary across all pods.

Query Parameters:

ParameterTypeDescriptionDefault
namespacestringFilter by namespaceAll
laststringTime range24h

Response:

{
"total_co2e_grams": 45.2,
"total_cost": 12.35,
"total_energy_joules": 325000,
"total_pods": 42,
"period": {
"start": "2024-02-20T14:00:00Z",
"end": "2024-02-21T14:00:00Z"
}
}

Time-series data for charting.

Query Parameters:

ParameterTypeDescriptionDefault
granularitystringhour, day, week, monthday
laststringTime range7d
namespacestringFilter by namespaceAll

Response:

{
"timeseries": [
{
"timestamp": "2024-02-21T00:00:00Z",
"co2e_grams": 45.2,
"total_cost": 12.35,
"energy_joules": 325000,
"pod_count": 42
}
]
}

List all active namespaces with metrics.

Response:

{
"namespaces": [
{
"name": "default",
"pod_count": 15,
"total_co2e_grams": 12.3,
"total_cost": 3.45
},
{
"name": "production",
"pod_count": 27,
"total_co2e_grams": 32.9,
"total_cost": 8.90
}
]
}

Cluster node inventory with hardware and capacity details.

Response:

{
"nodes": [
{
"name": "ip-10-0-1-42",
"instance_type": "m5.xlarge",
"cloud_provider": "aws",
"zone": "eu-west-1a",
"emaps_zone": "FR",
"cpu_capacity": 4000,
"memory_capacity": 17179869184,
"architecture": "amd64",
"os": "linux"
}
]
}

Optimization recommendations based on recent metrics.

Query Parameters:

ParameterTypeDescriptionDefault
namespacestringFilter by namespaceAll

Response:

{
"recommendations": [
{
"type": "rightsizing",
"severity": "high",
"resource": "api-deployment-7b5f8c9d6-x2k4p",
"namespace": "default",
"details": "CPU usage is 15% of request (250m). Recommend reducing to 50m.",
"current": {"cpu_request": 250, "cpu_usage_avg": 37.5},
"recommended": {"cpu_request": 50},
"estimated_savings": {
"cost_per_day": 0.45,
"co2e_grams_per_day": 2.1
}
}
],
"total": 5
}

All endpoints return standard HTTP status codes:

StatusDescription
200Success
400Bad request (invalid parameters)
404Resource not found
500Internal server error

Error response format:

{
"detail": "Description of the error"
}

When the API is running, visit: