Building from Source#
This guide explains how to build Metrics Manager from source code for development, customization, or air-gapped deployments.
Prerequisites#
Before building, ensure you have:
System Requirements: See System Requirements
Source code: Cloned the repository (
git clone https://github.com/open-edge-platform/edge-ai-libraries.git -b main)Platform familiarity: Basic understanding of Docker and Docker Compose
Building in a Docker Container (Recommended)#
The recommended way to build is inside Docker, which handles all dependencies (Rust toolchain, Telegraf, Python) automatically.
Step 2: Copy Environment Configuration#
cp .env.example .env
Edit .env if needed (usually defaults work fine).
Step 3: Build the Docker Image#
docker compose build
This runs a multi-stage build:
Stage 1: Compiles qmassa (Intel GPU reader) from Rust source
Stage 2: Installs Python dependencies (production only, no test packages)
Stage 3: Creates a test image with test dependencies (optional)
Stage 4: Production image based on
python:3.12-slimwith Telegraf, qmassa, and supervisord
First build duration: 3–10 minutes (depends on download speeds and CPU)
Subsequent builds: <1 minute (cached layers)
Step 4: Start the Service#
docker compose up
Or in the background:
docker compose up -d
Step 5: Verify#
curl http://localhost:9090/health
Building Locally (Without Docker)#
If you want to run the service locally without Docker, use the following approach:
Prerequisites#
Python 3.10+ (
python3 --version)uv (fast Python package manager):
pip install uvor see UV DocumentationTelegraf installed on the system (for system metrics)
qmassa binary (for GPU metrics) — compile from qmassa GitHub or skip if not needed
Git
Step 2: Create a Virtual Environment#
python3 -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
Or with uv (faster):
uv venv
source .venv/bin/activate
Step 3: Install Dependencies#
uv sync --group test
Or with pip:
pip install -e ".[test]"
Step 4: Configure the Environment#
cp .env.example .env
Edit .env and set:
# Since Telegraf runs on the host (not in a container), use localhost
TELEGRAF_PORT=9273
TELEGRAF_HTTP_ENDPOINT=http://localhost:8186/write
PROMETHEUS_TELEGRAF_ENDPOINT=http://localhost:9273
Step 5: Start Telegraf#
On your host machine, start Telegraf with the bundled config:
telegraf --config telegraf.conf
This exposes metrics on http://localhost:9273/metrics and listens for writes on http://localhost:8186/write.
Step 6: Run the Application#
uvicorn app.main:app --reload --port 9090
The service will start on http://localhost:9090.
Step 7: Verify#
curl http://localhost:9090/health
curl http://localhost:9273/metrics | head
Running Tests#
Via Docker (Recommended)#
# Run all tests
docker compose --profile test run --rm metrics-manager-test
# Run with coverage
docker compose --profile test run --rm metrics-manager-test \
python -m pytest tests/ -v --cov=app --cov-report=term-missing
Locally#
If you installed dependencies locally:
# Run all tests
pytest
# Run with verbose output
pytest -v
# Run with coverage
pytest --cov=app --cov-report=html
Expected Output#
========================= test session starts ==========================
tests/test_settings.py::... PASSED
tests/test_logging_config.py::... PASSED
tests/test_main.py::... PASSED
tests/test_models.py::... PASSED
tests/test_store.py::... PASSED
tests/test_routes.py::... PASSED
tests/test_metrics.py::... PASSED
tests/test_rate_limit.py::... PASSED
tests/test_sse.py::... PASSED
tests/test_npu_monitor_tool.py::... PASSED
tests/test_npu_reader.py::... PASSED
tests/test_telegraf_integration.py::... SKIPPED (requires Docker)
========================= 179 passed in 1.70s ==========================
Development Setup#
For local development with hot-reload and debugging:
# Install dev dependencies
uv sync --group test --group dev
# Run with auto-reload
uvicorn app.main:app --reload --port 9090
# Run linting and formatting
black app/
ruff check app/
Building the Helm Chart#
If you are deploying to Kubernetes:
# Lint the Helm chart
make helm-lint
# Generate the chart package
make helm-package
# Push to OCI registry (requires authentication)
make helm-push
See Helm Deployment for full Kubernetes instructions.
Customization#
Modifying Telegraf Configuration#
The telegraf.conf file controls system metric collection. To customize:
Edit
telegraf.confin the metrics-manager root directoryOr mount a custom config:
TELEGRAF_CONFIG=./my-telegraf.conf docker compose upOr drop additional
.conffiles in thetelegraf.d/directory
See Environment Variables for Telegraf customization examples.
Extending with Custom Inputs#
Add Python or shell scripts to /app/custom-metrics/:
# Example: create a fan speed monitor
cat > /app/custom-metrics/fan_speed.sh << 'EOF'
#!/bin/sh
rpm=$(cat /sys/class/hwmon/hwmon0/fan1_input)
echo "fan_speed,sensor=cpu_fan rpm=${rpm}i"
EOF
chmod +x /app/custom-metrics/fan_speed.sh
The script runs every 10 seconds and outputs InfluxDB Line Protocol.
Troubleshooting Build Issues#
Error |
Solution |
|---|---|
|
First Docker build compiles Rust. Try |
|
Ensure you’re in the |
|
Change port in |
|
Install Telegraf: |
|
Ensure you run with |
Supporting Resources#
License#
Copyright (C) 2025-2026 Intel Corporation
SPDX-License-Identifier: Apache-2.0