How to attribute energy to a virtual machine

This guide describes one way to attribute a bare-metal server’s measured energy to the virtual machines (VMs) running on it. Alumet collects host and cgroup-related measurements and exposes them in Prometheus format. Chantico scrapes those metrics and uses a coefficient on each VM’s relationship to its host to calculate the VM’s share.

This setup assumes that Chantico and Prometheus are already running, and that the bare-metal server and its upstream energy measurement (for example, a PDU) are represented in Chantico. For information about defining resources and relationships, see the how to register data center resources.

Topology overview

The diagram shows an example hypervisor hosting two VMs. Alumet runs directly on the hypervisor. The Bare Metal server receives power from two PDU sockets.

In the diagram, the two PDU sockets and Alumet running on the bare metal alongside the Hypervisor. The metrics gathered by the Alumet instance running on the baremetal are used to attribute energy to the VMs running on the baremetal.

1. Install Alumet to perform attribution

The Alumet agent needs to be installed on the baremetal that runs the virtual machines (Ie. it needs to be installed alongside the hypervisor). Follow the Alumet installation guide for your operating system and installation method.

2. Configure Alumet

The example enables Alumet’s Prometheus exporter, cgroups, performance events, and procfs plugins for kernel, memory, network, and process metrics. Enable the exporter so Chantico’s Prometheus instance can scrape its endpoint. The endpoint must be reachable from the cluster.

Configure Alumet so it can observe the host’s cgroups and collect the metrics needed for attribution. If you run Alumet in a container, ensure it has the required access to the host’s cgroups and performance events; an isolated container will not observe the host’s VM processes.

[plugins.prometheus-exporter]
host = "0.0.0.0"
prefix = ""
suffix = "_alumet"
port = 9091
add_attributes_to_labels = true

[plugins.cgroups]
poll_interval = "1s"
disable_sources = false

[plugins.perf]
poll_interval = "1s"
flush_interval = "5s"
events = [
    "REF_CPU_CYCLES",
    "CACHE_MISSES",
    "BRANCH_MISSES",
    "LL_READ_MISS",
]
add_source_in_pause_state = false

[plugins.procfs.kernel]
enabled = true
poll_interval = "5s"

[plugins.procfs.memory]
enabled = true
poll_interval = "5s"
metrics = [
    "MemTotal",
    "MemFree",
    "MemAvailable",
    "Cached",
    "SwapCached",
    "Active",
    "Inactive",
    "Mapped",
]

[plugins.procfs.network]
enabled = true
poll_interval = "5s"

[plugins.procfs.processes]
enabled = true
refresh_interval = "2s"
strategy = "watcher"

[[plugins.procfs.processes.groups]]
exe_regex = ""
poll_interval = "2s"
flush_interval = "4s"
memory_mode = "quick"

[plugins.procfs.processes.events]
poll_interval = "1s"
flush_interval = "4s"
memory_mode = "quick"

Start Alumet using the method for your installation, then check that its Prometheus exporter is available on port 9091 (or the port you configured). The exporter must be reachable from Chantico’s Prometheus pod. If the baremetal is not directly reachable from the cluster, arrange network access before adding the scrape target.

3. Add the Alumet exporter as a measurement target

Create a PhysicalMeasurement that points to the hypervisor’s Alumet exporter. Set spec.ip to an address and port reachable from Prometheus:

# physicalmeasurement-bm-01.yaml
apiVersion: chantico-project.github.io/v1alpha1
kind: PhysicalMeasurement
metadata:
  name: physicalmeasurement-bm-01
  namespace: chantico
spec:
  type: prometheus-exporter
  ip: 192.0.2.10:9091

Apply the manifest:

kubectl apply -f physicalmeasurement-bm-01.yaml

Chantico adds this target to Prometheus’s exporter scrape configuration. Check that it is ready and that Prometheus can scrape it:

kubectl describe -n chantico physicalmeasurement physicalmeasurement-bm-01

In Prometheus, open Status > Targets and confirm the target is UP. You can also query a metric shown by the Alumet endpoint to confirm its series and labels are available.

4. Add VM resources and attribution coefficients

Create a DataCenterResource for each VM and set the bare-metal resource as its parent. Use a coefficient query that selects the series for that VM and returns its share of the host’s energy.

The repository includes a basic Proxmox 9 Alumet template in proxmox_alumet_vm_attribution_basic.yaml. It uses cpu_percent_alumet_ratio and expects resourceName to match the bare-metal host’s PhysicalMeasurement name and vmid to match the VM’s ID in Proxmox. Apply it from the repository root:

kubectl apply -n chantico -f config/samples/attribution-templates/proxmox_alumet_vm_attribution_basic.yaml

If you use a different hypervisor, metric, or label scheme, create your own ConfigMap template with a query that returns a coefficient between 0 and 1. The coefficient represents the proportion of the bare-metal server’s energy attributable to the VM. Change the ConfigMap name in the VM resource to match your own:

# datacenterresource-bm-01-vm-120.yaml
apiVersion: chantico-project.github.io/v1alpha1
kind: DataCenterResource
metadata:
  name: datacenterresource-bm-01-vm-120
  namespace: chantico
spec:
  type: vm
  parents:
    - name: datacenterresource-bm-01
      coefficientFrom:
        valueFrom:
          configMapKeyRef:
            name: proxmox9-alumet-energy-attribution-coefficient-template
            key: template
        templateParameters:
          - name: resourceName
            value: physicalmeasurement-bm-01
          - name: vmid
            value: "120"

Replace datacenterresource-bm-01 with the name of the existing bare-metal DataCenterResource, and set the VM identifier to match the ID assigned to that VM by your hypervisor. Under the hood, the Proxmox template uses this ID to select Alumet metrics for the VM’s cgroup, where Linux accounts for the VM’s resource usage. Repeat the VM resource with each VM’s ID. The ConfigMap and resources must be in the same namespace.

Apply the manifest and check the resource status:

kubectl apply -f datacenterresource-bm-01-vm-120.yaml
kubectl describe -n chantico datacenterresource datacenterresource-bm-01-vm-120

Confirm the coefficient expression returns the intended series in Prometheus. If it returns no series, check the metric name, VM ID and corresponding cgroup selector, labels, and that the Alumet exporter is being scraped. A coefficient is evaluated for the VM’s edge to its parent, so ensure the parent resource is the host whose energy is being apportioned.