Skip to content
GreenKube

Storage Backends

GreenKube’s repository pattern allows you to choose the storage backend that best fits your deployment needs.

Business Logic (Core)
⚙️ DataProcessor Calls repository.save_metric()
interface
Abstract Repository
📐 MetricRepository write_combined_metrics() · read_combined_metrics()
implements
Storage Adapters
🐘 PostgreSQL Production · asyncpg Recommended
📁 SQLite Development · aiosqlite Dev / CI
🔍 Elasticsearch Scale · elasticsearch-py Scale
🏭 Instantiated by core/factory.py based on DB_TYPE config
FeaturePostgreSQLSQLiteElasticsearch
Use CaseProductionDevelopment / CILarge-scale analytics
Persistence✅ StatefulSet⚠️ Lost on pod restart*✅ External cluster
PerformanceHighModerateVery High
SetupHelm chart includedZero configExternal cluster needed
ScalabilityGood (single node)LimitedExcellent (sharded)
Driverasyncpg (native async)aiosqlite (async wrapper)elasticsearch (async)

*SQLite can persist data with a PersistentVolumeClaim.

The default and recommended backend for production deployments.

values.yaml
config:
db:
type: postgres
schema: public
postgres:
enabled: true
auth:
username: greenkube
password: greenkube_password
database: greenkube
persistence:
enabled: true
size: 5Gi
# Or use an external PostgreSQL:
secrets:
dbConnectionString: "postgresql://user:pass@host:5432/greenkube"

Features:

  • Automatic schema creation and migration
  • Connection pooling via asyncpg
  • Transactional integrity
  • Bundled PostgreSQL 17 StatefulSet via Helm
  • Support for external PostgreSQL instances

The primary table storing all processed metrics (33 columns):

ColumnTypeDescription
pod_nameVARCHARPod identifier
namespaceVARCHARKubernetes namespace
timestampTIMESTAMPTZMetric collection time
duration_secondsFLOATCollection interval duration
joulesFLOATEnergy consumption
co2e_gramsFLOATCarbon emissions
grid_intensityFLOATGrid carbon intensity used
pueFLOATPUE factor applied
total_costFLOATAllocated cost
cpu_requestFLOATCPU request (millicores)
cpu_usage_millicoresFLOATActual CPU usage
memory_requestBIGINTMemory request (bytes)
memory_usage_bytesBIGINTActual memory usage
network_receive_bytesBIGINTNetwork bytes in
network_transmit_bytesBIGINTNetwork bytes out
disk_read_bytesBIGINTDisk read bytes
disk_write_bytesBIGINTDisk write bytes
storage_request_bytesBIGINTStorage request
ephemeral_storage_request_bytesBIGINTEphemeral storage
gpu_usage_millicoresFLOATGPU usage
restart_countINTContainer restarts
nodeVARCHARNode name
node_instance_typeVARCHARCloud instance type
node_zoneVARCHARAvailability zone
emaps_zoneVARCHARElectricity Maps zone
owner_kindVARCHAROwner type (Deployment, etc.)
owner_nameVARCHAROwner name
is_estimatedBOOLEANUses estimated values
estimation_reasonsTEXTEstimation details
embodied_co2e_gramsFLOATHardware embodied emissions

Caches carbon intensity lookups:

ColumnTypeDescription
zoneVARCHARElectricity Maps zone code
timestampTIMESTAMPTZIntensity timestamp
intensityFLOATgCO₂e/kWh

Historical node state for accurate time-range reporting:

ColumnTypeDescription
snapshot_timestampTIMESTAMPTZSnapshot time
nameVARCHARNode name
instance_typeVARCHARInstance type
zoneVARCHARAvailability zone
cpu_capacityINTCPU cores
memory_capacityBIGINTMemory bytes

Caches Boavizta API responses:

ColumnTypeDescription
providerVARCHARCloud provider
instance_typeVARCHARInstance type
gwp_manufactureFLOATManufacturing CO₂e (kg)
lifespan_hoursFLOATExpected lifespan
last_updatedTIMESTAMPTZCache timestamp

Stores recommendation snapshots for historical tracking:

ColumnTypeDescription
timestampTIMESTAMPTZWhen the recommendation was generated
pod_nameVARCHARTarget pod name
namespaceVARCHARTarget namespace
typeVARCHARRecommendation type (e.g., ZOMBIE_POD, RIGHTSIZING_CPU)
descriptionTEXTHuman-readable recommendation
reasonTEXTWhy the recommendation was made
priorityVARCHARPriority level (high, medium, low)
potential_savings_co2e_gramsFLOATEstimated CO₂e savings
potential_savings_costFLOATEstimated cost savings

All backends support automatic schema evolution:

  • New columns are added with ALTER TABLE ... ADD COLUMN IF NOT EXISTS
  • Tables are created on first run
  • Migrations run on application startup
  • No manual migration commands needed