Back to articles
Technology Insight

Building a Green DevOps Infrastructure on VPS: Automatically Measuring and Optimizing Docker Container Energy Consumption with Scaphandre

May 26, 2026

Introduction to Green DevOps in the Cloud Era

As cloud computing and containerization continue to drive modern software architectures, the environmental impact of digital infrastructure has come under intense scrutiny. Data centers worldwide consume vast amounts of electricity, contributing significantly to global carbon emissions. In response, Green DevOps has emerged as a crucial paradigm, integrating environmental sustainability into the traditional culture of continuous integration and continuous deployment (CI/CD).

For businesses utilizing Virtual Private Servers (VPS) to host microservices, optimizing resource allocation is no longer just about cutting cloud bills—it is about reducing environmental impact. This technical guide explores how to build a sustainable "Green DevOps" infrastructure on a standard VPS. We will focus on automatically measuring and optimizing the energy consumption of Docker containers using Scaphandre, an open-source carbon reporting tool designed for bare-metal and virtualized environments.

The Core Challenge: Measuring Power Consumption on a VPS

In a bare-metal environment, engineering teams can often read energy metrics directly from the hardware via tools like Intel's Running Average Power Limit (RAPL) or Intelligent Platform Management Interface (IPMI). However, when operating within a Virtual Private Server (VPS), developers encounter significant hurdles:

  • Hardware Abstraction: Virtualization layers abstract the physical CPU and RAM, hiding direct energy metrics from the guest operating system.
  • Shared Resources: Multiple virtual machines share the same physical host, making it difficult to isolate the exact power consumption of a specific tenant's workloads.
  • Container Granularity: Even if host-level metrics are available, attributing power draw to individual Docker containers requires a highly sophisticated estimation framework.

This is where Scaphandre becomes indispensable. Developed by Hubblo, Scaphandre acts as a metrics provider that estimates power consumption when direct hardware access is restricted. It uses advanced mathematical models to calculate power draw based on CPU time and resource utilization metrics available within the virtualized environment.

Setting Up Scaphandre on Your VPS Infrastructure

Prerequisites

Before initiating the installation, ensure your VPS meets the following baseline requirements:

  1. A Linux-based operating system (Ubuntu 22.04 LTS or newer recommended).
  2. Docker and Docker Compose installed and properly configured.
  3. Root or sudo administrative privileges.
  4. Prometheus and Grafana installed for metrics aggregation and visualization.

Deploying Scaphandre via Docker

Deploying Scaphandre as a Docker container is the most efficient method for integration into a containerized ecosystem. Because Scaphandre requires access to the host system's process metrics, it must be granted specific permissions. Create a docker-compose.yml file with the following configuration:

version: '3.8'

services:
  scaphandre:
    image: hubblo/scaphandre:latest
    container_name: scaphandre
    volumes:
      - /proc:/proc
      - /sys/class/powercap:/sys/class/powercap
    ports:
      - "8080:8080"
    command: "prometheus"
    restart: unless-stopped
    security_opt:
      - no-new-privileges:true

Execute the deployment command: docker compose up -d. Scaphandre will begin monitoring the /proc filesystem, calculating the energy footprint of every process running on the system, and exposing those metrics in a Prometheus-compatible format on port 8080.

Configuring the Green DevOps Metrics Pipeline

To achieve automation, raw metrics from Scaphandre must be collected, aggregated, and visualized. The standard architecture for a Green DevOps observability stack consists of Scaphandre > Prometheus > Grafana.

1. Prometheus Scraping Configuration

Append the following scrape job configuration to your existing prometheus.yml file to instruct Prometheus to collect energy metrics from Scaphandre every 15 seconds:

scrape_configs:
  - job_name: 'scaphandre'
    scrape_interval: 15s
    static_configs:
      - targets: ['scaphandre:8080']

2. Identifying Docker Containers via Process IDs

Scaphandre tracks metrics at the process level (PID). Since Docker containers run as isolated processes on the host Linux kernel, Scaphandre can attribute power metrics back to specific containers by cross-referencing process IDs with the container runtime. The primary metric to observe is scaph_process_power_consumption_microwatts, which can be filtered using PromQL expressions.

Key Concept: By multiplying the percentage of CPU time a specific container uses by the overall host power consumption estimate, Scaphandre delivers a highly accurate approximation of per-container energy draw, measured in microwatts.

Automating Energy Optimization and Remediation

Measurement is only the first step; true Green DevOps involves automated action. Once energy metrics flow into Prometheus, engineering teams can configure automated workflows to optimize infrastructure dynamically.

Setting Energy Budgets with Prometheus Alertmanager

Define an alert rule in Prometheus to trigger when a specific service exceeds its allocated carbon or energy budget. For instance, if a background worker container consumes more than 15 Watts continuously for over 10 minutes, an alert can be routed to a webhook:

groups:
  - name: green_devops_alerts
    rules:
    - alert: HighContainerEnergyConsumption
      expr: sum(scaph_process_power_consumption_microwatts) by (container_name) / 1000000 > 15
      for: 10m
      labels:
        severity: warning
      annotations:
        summary: "Container {{ $labels.container_name }} exceeded energy budget."

Automated Scaling and Throttling Policies

When an alert triggers, automated scripts or orchestrators can execute remediation strategies to lower energy consumption:

  • Dynamic CPU Throttling: Use Docker's native resource constraints to dynamically limit a runaway container's CPU allocation: docker update --cpus="0.5" .
  • Load Shifting: Move heavy, non-time-sensitive asynchronous cron jobs or batch-processing workloads to hours when the local grid's carbon intensity is lowest.
  • Automated Downscaling: If a microservice is idling but still drawing base power, trigger an automated horizontal pod autoscaler (HPA) or script to scale the container replicas down to zero or one during off-peak hours.

Conclusion: The Future of Sustainable Infrastructure

Building a Green DevOps infrastructure on a VPS is a highly effective methodology for aligning modern software engineering with corporate sustainability goals. By utilizing Scaphandre to bridge the virtualization visibility gap, organizations gain the granular data necessary to transform abstract environmental goals into concrete, measurable engineering key performance indicators (KPIs).

As carbon taxes emerge and energy efficiency increasingly dictates operational margins, integrating automated power measurement and remediation into your CI/CD and infrastructure management pipelines is not merely an ethical choice—it is a strategic business imperative. Start monitoring your containers today, optimize your code for energy efficiency, and contribute directly to a sustainable digital future.

Building a Green DevOps Infrastructure on VPS: Automatically Measuring and Optimizing Docker Container Energy Consumption with Scaphandre | DPTCloud