Measuring What Your Server Actually Costs in Electricity

Pathfinder runs 45 services around the clock. The compute is ours, but the power bill is real. I forked scaphandre, rebuilt it as glasswing-power, and now I can see exactly how many watts each process, socket, and domain is drawing.

I wrote about building a private datacenter on a powerful workstation. The post ended with a trade-off I was happy to accept: I own the hardware, the power bill, the certificates, the upgrades, and the 2 a.m. page. In exchange, I own the data, the boundaries, and the decisions.

I said "the power bill" like it was a footnote. It isn't.

Pathfinder runs forty-five Docker services around the clock. Ollama loads a 27B model onto the RTX 4090 and keeps it warm. Plex transcodes video on the GPU. OpenObserve ingests logs from every container. Forgejo, Infisical, Postgres, Redis, Vector, the OTel Collector, AdGuard, Dagu, and a dozen more all draw current whether or not I'm looking at them. The machine is never idle. It is working.

And the electricity is not free.

I could look at my utility bill and see a number, but that number is the whole house: the fridge, the lights, the phone charger, the router. It tells me nothing about what Pathfinder is actually consuming, how that consumption changes when I add a service, or whether a 27B model inference is costing me more than a Plex transcode. I needed a meter that pointed at the server, not at the house.

The problem: you can see the containers, but not the watts

Docker gives me CPU and memory per container. Prometheus gives me CPU time, memory bytes, network I/O. OpenObserve gives me logs and traces. None of them answer the question I actually wanted: how many joules of electrical energy did this process consume, and what does that cost me?

CPU time is not power. A process can burn 95% of a core for an hour and draw very little current if it's mostly waiting on memory. A GPU inference can draw hundreds of watts for thirty seconds and then go quiet. The relationship between "work done" and "energy consumed" is not linear, and it's not visible from any of the usual monitoring tools.

What I needed was a sensor that reads the hardware's own power accounting. Modern x86 CPUs, both Intel and AMD, have this built in. It's called RAPL (Running Average Power Limit) and it exposes energy counters through the kernel's powercap interface. The CPU tracks how many microjoules it has consumed, per socket, per power domain (package, DRAM, and on some platforms, the whole system). No external meter, no current clamp, no guesswork. The silicon is counting its own electricity.

The one wrinkle: the Linux kernel module is called rapl (not intel_rapl), and the sysfs entries are named intel-rapl:0, a misleading name that works on AMD too. On Pathfinder's Ryzen 9 7950X, only the generic rapl module is loaded, and the powercap entries work exactly as they do on Intel.

Scaphandre: the tool that already existed

I didn't need to build this from scratch. Scaphandre by Benoit Petit and the hubblo-org team already did exactly this. It's a Rust-based monitoring agent that reads RAPL counters and exports the data to Prometheus, Warp10, Riemann, JSON, or stdout. It tracks power at four granularities:

  • Host: total system power (PSYS domain, or PKG+DRAM fallback)
  • Socket: per CPU socket
  • Domain: per RAPL power domain (package, DRAM)
  • Process: per-process attribution, using CPU usage as a proxy for power share

The process attribution is the clever part. It doesn't try to measure each process's current draw directly (that's not possible without per-core power sensors). Instead, it takes the total power of the topology and distributes it proportionally to each process's CPU usage percentage. A process using 25% of a 4-core machine gets 25% of the socket's power. It's an approximation, but it's a useful approximation, and it's the same approach most power-attribution tools use.

Scaphandre was exactly what I needed. The upstream project still exists, but it's been unmaintained for a while. The architecture was sound; I just needed to make it fit my use case.

Forking, renaming, making it ours

The code was good: clean Rust, a sensible two-layer architecture (sensors collect, exporters deliver), and a metric contract that mapped directly onto Prometheus. But it was built for a different use case: a general-purpose monitoring agent for anyone who wanted to track power.

My use case was narrower and more specific. I wanted to know what my server was consuming, attribute it to my services, and feed it into my observability stack. I didn't need Windows support. I didn't need Riemann. I didn't need the mdbook documentation site. I needed the Linux RAPL sensor, the Prometheus exporter, and the process attribution math.

So I forked it, renamed it to glasswing-power, relicensed it to MIT, and started making it fit.

The changes were substantial:

  • Dropped Windows support. Fifteen files, 1,440 lines of MSR-based sensor code, Windows service integration, and Inno Setup packaging. Gone. The project is Linux-only, which is where RAPL lives anyway.
  • Split the monolithic modules. sensors/mod.rs was 1,586 lines mixing traits, structs, and logic. It's now seven files: traits.rs, topology.rs, socket.rs, core.rs, domain.rs, record.rs, and a slim mod.rs that re-exports the public API. Same for exporters/mod.rs, 1,030 lines down to three files.
  • Fixed the bugs. The get_load_avg() function returned the 5-minute load average for both the 5-minute and 15-minute slots. A typo in a metric label (scaphandredrv_rapl_pkg). Thirty-one panic! calls where seven were legitimate. All resolved.
  • Added AMD support. The check_module() function only accepted intel_rapl, intel_rapl_msr, and intel_rapl_common, but on AMD systems, only the generic rapl module is loaded. Now it accepts rapl too. Verified on the Ryzen 9 7950X: 42,695 metrics, host power reading 78.7W.
  • Upgraded the dependencies. sysinfo 0.28 → 0.40, warp10 2.0 → 3.0, procfs 0.15 → 0.18. The "eat the frog" strategy: highest-risk packages first.
  • Removed the stale references. 77 files, 5,780 lines of old scaphandre documentation, mdbook theme, and Windows packaging that no longer applied.

The result is in pain459/glasswing-power. It's a single Rust crate, ~8,500 lines, MIT licensed, Linux-only. It reads RAPL counters from /sys/class/powercap, tracks processes via sysinfo and procfs, and exports 40+ metrics with the scaph_ prefix (kept intentionally for dashboard backward compatibility).

What the metrics actually tell me

The Prometheus exporter on port 8081 gives me a clean set of gauges and counters:

scaph_host_power_microwatts{value_source="PSYS"}          128450000
scaph_host_energy_microjoules{value_source="PSYS"}        4823000000000
scaph_socket_power_microwatts{socket_id="0"}              95200000
scaph_domain_power_microwatts{domain_name="PKG",socket_id="0"}  82100000
scaph_domain_power_microwatts{domain_name="DRAM",socket_id="0"} 13100000
scaph_process_power_consumption_microwatts{pid="1234",exe="ollama"}  45000000
scaph_process_power_consumption_microwatts{pid="5678",exe="plex"}   32000000
scaph_process_cpu_usage_percentage{pid="1234",exe="ollama"}  187.5

That last pair is the one I care about. Ollama is drawing 45 watts while using 187.5% of CPU (across 4 cores, that's about 47% of total capacity). Plex is drawing 32 watts. The GPU inference is the dominant consumer, and now I can see it in the same dashboard as everything else.

The attribution math is straightforward:

process_power = topology_power × (process_cpu_pct / 100)

Where process_cpu_pct is normalized by the total core count. It's not perfect: a memory-bound process will be over-attributed, a GPU-bound process will be under-attributed because the GPU power isn't in the RAPL counter, but it's good enough to answer the questions I actually ask: which services are the biggest consumers, and how does that change when I add or remove one?

The dashboard that made it real

Metrics in Prometheus are useful, but they don't answer the question I actually care about: how much is this costing me, in the currency I pay my electricity bill in?

So I built a Grafana dashboard: Glasswing Power - Power Cost (INR / USD). It takes the raw RAPL readings and converts them into money. The rate is 9 INR/kWh (my local tariff), with USD conversion at 94.66 INR/USD.

Glasswing Power - Power Cost dashboard showing live power draw, burn rate, actuals, and cost projections

The dashboard has four sections:

Live Power & Burn Rate. Three stat panels at the top: current power draw in watts, burn rate in INR/hr, and burn rate in USD/hr. The INR/hr panel is the one I glance at. It tells me, right now, how fast I'm spending.

Actuals (Since Glasswing Power Started). Five stat panels: total energy consumed in kWh, total cost in INR, total cost in USD, session average power, and peak power. These are cumulative since the glasswing-power container started. The "Total Cost (INR)" panel is the number that makes the power bill feel real.

Cost Projections (at Current Power). Seven stat panels projecting the current power draw forward: per hour, per day, per week, per month, and per year, in both INR and USD. This is the "what if this keeps going" section. At a steady 78W, that's roughly 1,580 INR/month. Not a lot, but it's visible now, and it's the number I can act on.

Top Processes (Who is Burning Your Money). A table of the top 15 processes by power draw, with columns for power in watts, cost per hour (INR and USD), and cost per day (INR and USD). Sorted by power, descending. This is the panel that answers the question I started with: which service is the biggest consumer?

The dashboard JSON is in the docker-compose directory of the repo. Import it into Grafana, point it at your Prometheus, and you have a working power cost dashboard in about a minute.

Running it on Pathfinder

The deployment is simple. A Docker container with access to the host's /sys/class/powercap:

docker run -d \
  --name glasswing-power \
  -p 8081:8080 \
  -v /sys/class/powercap:/sys/class/powercap:ro \
  glasswing-power:latest prometheus --port 8080

Prometheus scrapes it. Grafana shows it. The metrics land in the same OpenObserve pipeline as everything else. No new infrastructure, no new agent to babysit.

The full stack (glasswing-power, Prometheus, Grafana, and the dashboards) is in the docker-compose directory of the repo. docker compose up -d --build and you have a working power monitoring setup in about thirty seconds.

Why I released it

I could have kept this as a private tool. A fork in a corner of my machine, measuring my own server, answering my own questions. And for a while, that's exactly what it was.

But the more I used it, the more I realized the problem wasn't mine alone. Anyone who self-hosts on Intel or AMD hardware has the same question: what is this actually costing me in electricity? The RAPL counters are there on every modern x86 CPU. The kernel exposes them. The only thing missing is a clean, maintained tool that reads them and gives you per-process attribution.

Scaphandre was that tool, but it's been unmaintained for a while. glasswing-power is the continuation: the same architecture, the same metric contract, the same attribution math, updated and pointed at the use case that actually motivated it: a self-hosted server where the owner wants to know what the power bill is really for.

The repo is at pain459/glasswing-power. MIT licensed. Linux-only. If you have an Intel or AMD machine running services you care about, point it at the powercap interface and see what your server is actually drawing.

The compute is ours. Now the power is visible too.