-
Notifications
You must be signed in to change notification settings - Fork 28
Live-Metrics Support #252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Live-Metrics Support #252
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # live-metrics | ||
|
|
||
| A small HTTP API that turns the flat files written by | ||
| `docker/scripts/collect_platform.sh`, `collect_gpu.sh` and `collect_npu.py` | ||
| into a live, pollable JSON time series (CPU / GPU / NPU / memory / power). | ||
|
|
||
| `performance-tools` already ran those collectors inside a privileged Docker | ||
| container (`docker/Dockerfile` + `docker/docker-compose.yaml`, used today by | ||
| `loss-prevention` as a submodule) for **offline benchmarking** -- | ||
| `benchmark-scripts/consolidate_multiple_run_of_metrics.py` only parses the | ||
| results *after* a run finishes. `live-metrics/` adds a second way to consume | ||
| the same collectors: a **live HTTP API** (`metrics_api.py` / | ||
| `metrics_parser.py`), served from inside the same container via an | ||
| additional `supervisord` program, so a UI can poll `GET /metrics` | ||
| continuously while the collectors keep running -- not just after a | ||
| benchmark completes. | ||
|
|
||
| Both use cases run **the exact same collector scripts** under | ||
| `docker/scripts/` -- `live-metrics/` only adds a reader on top, it doesn't | ||
| change what's collected or how. | ||
|
|
||
| ## Running it | ||
|
|
||
| ```bash | ||
| cd docker | ||
| log_dir=./results docker compose build # picks up live-metrics/ automatically, see docker/Dockerfile | ||
| log_dir=./results docker compose up -d | ||
| curl http://localhost:9000/metrics | jq | ||
| ``` | ||
| `docker-compose.yaml` uses `network_mode: host`, so port 9000 is reachable | ||
| directly on the host once the container is up — no port publishing needed. | ||
|
|
||
| ## Environment variables | ||
|
|
||
| | Variable | Default | Meaning | | ||
| |---|---|---| | ||
| | `RESULTS_DIR` | `/tmp/results` | Where the collectors write, and where `metrics_parser.py` reads from. | | ||
| | `NPU_LOG` | `${RESULTS_DIR}/npu_usage.csv` | Override if you need the NPU CSV somewhere else. | | ||
| | `METRICS_HTTP_PORT` | `9000` | Port `metrics_api.py` listens on. | | ||
| | `DEVICE_CONFIG_PATH` | unset | Optional path to a `KEY=VALUE` file for `GET /device-config`; returns `{}` if unset. | | ||
| | `QMASSA_CYCLE_SECONDS` | `0` (disabled) | If set > 0, `collect_gpu.sh` restarts qmassa every N seconds and deletes its output file first, keeping the JSON bounded for long-running live dashboards. `0` reproduces the original, unbounded, single-invocation behavior used by existing offline-benchmarking consumers. **Set this for any 24/7 live-dashboard deployment** (e.g. `180`) -- qmassa never rotates its own output file, and it will otherwise grow unbounded (observed ~600 MB/hour in one production deployment). | | ||
| | `METRICS_GPU_MAX_JSON_MB` | `256` | `build_gpu_series()` refuses to `json.load()` a qmassa file larger than this (defense in depth alongside `QMASSA_CYCLE_SECONDS`). | | ||
| | `METRICS_GPU_MAX_POINTS` | `300` | Caps how many qmassa samples are parsed per request (only the tail is ever plotted). | | ||
|
|
||
| ## Endpoints | ||
|
|
||
| | Method & path | Returns | | ||
| |---|---| | ||
| | `GET /health` | `{"status": "ok"}` | | ||
| | `GET /metrics` | `{"cpu_utilization": [...], "gpu_utilization": [...], "npu_utilization": [...], "memory": [...], "power": [...]}` | | ||
| | `GET /platform-info` | `{"Processor": "...", "iGPU": "...", "NPU": "...", "Memory": "...", "Storage": "..."}` | | ||
| | `GET /memory` | Latest single memory snapshot | | ||
| | `GET /device-config` | `{}` unless `DEVICE_CONFIG_PATH` is set (see above) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| ''' | ||
| * Copyright (C) 2026 Intel Corporation. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| ''' | ||
|
|
||
| """ | ||
| Live metrics HTTP API for performance-tools. | ||
|
|
||
| Served inside the Docker image alongside the collectors (see | ||
| docker/supervisord.conf's [program:metrics_api]); this process only ever | ||
| reads $RESULTS_DIR, it has no other dependency on how the collectors were | ||
| started. | ||
|
|
||
| Endpoints | ||
| --------- | ||
| GET /health -> 200 {"status": "ok"} | ||
| GET /metrics -> time-series JSON (cpu / gpu / npu / memory / power) | ||
| GET /platform-info -> hardware summary (processor, iGPU, NPU, memory, storage) | ||
| GET /memory -> latest single memory snapshot | ||
| GET /device-config -> optional per-workload device summary (see metrics_parser.build_device_config_payload) | ||
| """ | ||
|
|
||
| import os | ||
|
|
||
| from fastapi import FastAPI | ||
| from fastapi.middleware.cors import CORSMiddleware | ||
|
|
||
| from metrics_parser import ( | ||
| build_device_config_payload, | ||
| build_metrics_payload, | ||
| get_platform_info, | ||
| parse_memory_usage, | ||
| ) | ||
|
|
||
| app = FastAPI(title="performance-tools live-metrics") | ||
|
|
||
| app.add_middleware( | ||
| CORSMiddleware, | ||
| allow_origins=[ | ||
| o.strip() | ||
| for o in os.getenv("METRICS_CORS_ORIGINS", "*").split(",") | ||
| if o.strip() | ||
| ], | ||
| allow_credentials=False, | ||
| allow_methods=["*"], | ||
| allow_headers=["*"], | ||
| ) | ||
|
|
||
|
|
||
| @app.get("/health") | ||
| def health() -> dict[str, str]: | ||
| """Health check endpoint.""" | ||
| return {"status": "ok"} | ||
|
|
||
|
|
||
| @app.get("/metrics") | ||
| def metrics() -> dict: | ||
| """Time-series utilization data: CPU, GPU, NPU, memory, power.""" | ||
| return build_metrics_payload() | ||
|
|
||
|
|
||
| @app.get("/platform-info") | ||
| def platform_info() -> dict: | ||
| """Hardware summary: processor, iGPU, NPU, memory, storage.""" | ||
| return get_platform_info() | ||
|
|
||
|
|
||
| @app.get("/memory") | ||
| def memory() -> dict: | ||
| """Latest single memory snapshot.""" | ||
| data = parse_memory_usage() | ||
| return data if data is not None else {"error": "no memory data"} | ||
|
|
||
|
|
||
| @app.get("/device-config") | ||
| def device_config() -> dict: | ||
| """Optional per-workload device summary; {} if not configured.""" | ||
| return build_device_config_payload() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| import uvicorn | ||
|
|
||
| port = int(os.getenv("METRICS_HTTP_PORT", "9000")) | ||
| print( | ||
| f"[live-metrics] starting on 0.0.0.0:{port} " | ||
| f"endpoints: /health /metrics /platform-info /memory /device-config", | ||
| flush=True, | ||
| ) | ||
| uvicorn.run("metrics_api:app", host="0.0.0.0", port=port, reload=False) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.