---
id: w3/m2/t001
title: Resource-metrics backend (CPU/memory/instances) + RBAC
worker: worker3
status: done
estimate: 45m
depends_on: []
---

## Objective

Add a `Metrics` verb to `Core` returning per-instance CPU and memory (from metrics-server) and instance count (from Deployment/pod status) for an App.

## Context

- Resource usage comes from the `metrics.k8s.io` API (metrics-server): `PodMetrics` per pod (`cpu`, `memory`).
- Instance count comes from the App's Deployment status / pod count (`operator/internal/controller/app_controller.go`).
- Render shows CPU vs a limit (e.g. 0.5 CPU) and memory vs a limit (e.g. 512 MB), togglable percentage/total — expose both raw usage and the limit so adapters can compute percentage.
- api RBAC needs `metrics.k8s.io` read access added to `operator/config/api/`.

## Steps

1. Add `Metrics(ctx, appID, opts)` to `Core` (new `operator/internal/api/metrics.go`).
2. Query `metrics.k8s.io` for the App's pods; read Deployment for replica count and resource limits.
3. Extend api RBAC with `metrics.k8s.io` (pods) read.

## Files

- `operator/internal/api/metrics.go` (new), `operator/internal/api/core.go`, `operator/config/api/`

## Acceptance criteria

- [ ] `Core.Metrics` returns per-instance CPU/memory usage + limits + instance count for an App.
- [ ] api RBAC grants `metrics.k8s.io` read; binary reads metrics without escalation.

## Out of scope

- REST/GraphQL adapters (t002), request metrics (t003/t004), cluster enablement (t005).
