A FastAPI-based mock Prometheus exporter with configurable metrics and UI.
Project description
mocktrics-exporter
Small, configurable Prometheus exporter for generating test metrics. It exposes:
- a Prometheus metrics endpoint for scraping
- a small FastAPI HTTP API for defining/updating metrics at runtime
Works great for demos, integration tests, and performance scenarios where you need predictable metrics behavior (static, ramp, square, sine, gaussian) with labels.
Note: The Python package is named mocktrics_exporter (underscore in the import path).
Install
- From PyPI:
pip install mocktrics-exporter
- From source (editable):
pip install -e .
Quick Start
- Run the exporter:
mocktrics-exporter -f config.yaml
- Alternatively from source:
python -m mocktrics_exporter.main -f config.yaml
- Defaults:
- Metrics served on
:8000 - HTTP API served on
:8080
- Metrics served on
Example Prometheus scrape config:
- job_name:
mocktrics - static_configs:
['localhost:8000']
CLI Options
-f, --config-filepath to YAML configuration file-a, --api-portAPI port (default8080)-m, --metrics-portPrometheus metrics port (default8000)
Options can also be provided via environment or process managers as needed.
Configuration
- File:
config.yaml(optional). If provided, metrics are preloaded at startup. - Schema overview: each metric defines a
name,documentation, optionalunit, a list oflabels, and a list ofvalues. Values use akinddiscriminator and fields specific to the chosen kind (see Supported Value Models below).
Example:
disable_units: true
metrics:
- name: combined
documentation: Mock metric for all types
labels: [type]
values:
- kind: static
value: 100
labels: [static]
- kind: ramp
period: 2m
peak: 100
invert: false
labels: [ramp]
- kind: square
period: 2m
magnitude: 100
duty_cycle: 50
labels: [square]
- kind: sine
period: 2m
amplitude: 50
offset: 50
labels: [sine]
Supported Value Models
static: constant numeric valueramp: linear ramp up topeakoverperiod, optionalinvert,offsetsquare: square wave withperiod,magnitude,duty_cycle(0–100), optionalinvert,offsetsine: sine wave withperiod,amplitude, optionaloffsetgaussian: random gaussian withmean,sigma
Helpers:
- Duration strings:
1s,2m,3h,1d - Size strings:
2u,2m,2k,2M,2G
HTTP API
Base URL is the API port (default http://localhost:8080).
Interactive API docs are available at http://localhost:8080/docs (Swagger UI).
Example requests:
# Create a metric
curl -X POST localhost:8080/metric \
-H 'content-type: application/json' \
-d '{
"name": "http_requests",
"documentation": "Demo metric",
"unit": "",
"labels": ["method"],
"values": [{"kind": "static", "labels": ["GET"], "value": 42}]
}'
# Add a value
curl -X POST localhost:8080/metric/http_requests/value \
-H 'content-type: application/json' \
-d '{"kind": "ramp", "labels": ["POST"], "period": "2m", "peak": 100}'
# List metrics
curl localhost:8080/metric/all
# Delete a value
curl -X DELETE 'localhost:8080/metric/http_requests/value?labels=GET'
# Delete metric
curl -X DELETE localhost:8080/metric/http_requests
Prometheus Metrics
- Metrics endpoint runs on the metrics port (default
8000). - Each metric is exported as a Gauge with labels as defined.
- Units in the metric name suffix can be disabled with
disable_units: truein config.
Development
- Run tests:
pytest -q(includes fast API and unit tests) - Run API with autoreload for local dev:
uvicorn mocktrics_exporter.api:api --reload --port 8080 - Code style: Black, isort, autoflake via pre-commit hooks
- Python:
>=3.9
License
Apache 2.0. See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mocktrics_exporter-0.1.4.tar.gz.
File metadata
- Download URL: mocktrics_exporter-0.1.4.tar.gz
- Upload date:
- Size: 31.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a438a5d443e86247de340f76e78689f82ed1c03a609631b4a745ce2588584aef
|
|
| MD5 |
b2749ee8fc45ee009e932285c4174880
|
|
| BLAKE2b-256 |
4ce8276e8ff00a7497a65d0ea10d0fb7254c2305c74d6f6e7c9f21a2fd7dca60
|
File details
Details for the file mocktrics_exporter-0.1.4-py3-none-any.whl.
File metadata
- Download URL: mocktrics_exporter-0.1.4-py3-none-any.whl
- Upload date:
- Size: 18.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70356d75df131aa0436a640fc42389a66a82f2ae97253a2f25454e873c836043
|
|
| MD5 |
d17b45134c898f9a46bc7daceb300bfd
|
|
| BLAKE2b-256 |
a126c1948a10d4f012597f2be02232ccca7e6154c888f5499adebe01dbb36007
|