Skip to content

feat: expose metering data via tenant API #134

Description

@dennisonbertram

Problem

CPU, memory, and network usage data is already collected in metering.db (tables: usage_events, usage_daily) but there are no API endpoints for tenants to access it. Agents need observability of their resource consumption for cost optimization, quota planning, and auto-scaling decisions.

Proposed Solution

Add two endpoints:

GET /v1/tenant/usage/metrics

Returns aggregated resource usage for the current tenant.

Query parameters:

  • periodhourly | daily (default: daily)
  • since — RFC3339 timestamp (default: 24h ago)
  • until — RFC3339 timestamp (default: now)
  • service_id — optional filter to a specific service

Response:

{
  "metrics": [
    {
      "timestamp": "2026-03-22T00:00:00Z",
      "cpu_seconds": 3600.5,
      "memory_mb_avg": 256.3,
      "network_rx_bytes": 104857600,
      "network_tx_bytes": 52428800,
      "service_id": "svc-abc123"
    }
  ],
  "period": "daily",
  "tenant_id": "tenant-xyz"
}

GET /v1/services/{serviceID}/metrics

Returns resource usage for a specific service. Same query params minus service_id.

Implementation Notes

  • Read from existing metering.db tables — no new data collection needed
  • Add a MeteringStore that wraps the metering SQLite connection
  • Wire into ServerConfig alongside existing Store
  • Respect existing auth middleware (tenant can only see own data)
  • Add pagination (limit/offset) if result sets could be large

Acceptance Criteria

  • GET /v1/tenant/usage/metrics returns aggregated usage data
  • GET /v1/services/{id}/metrics returns per-service usage data
  • period, since, until query params work correctly
  • Tenant isolation enforced (can't see other tenants' data)
  • Unit tests for the metering store and handlers
  • API reference updated

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions