Skip to main content

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

Example Prometheus scrape config:

  • job_name: mocktrics
  • static_configs: ['localhost:8000']

CLI Options

  • -f, --config-file path to YAML configuration file
  • -a, --api-port API port (default 8080)
  • -m, --metrics-port Prometheus metrics port (default 8000)

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, optional unit, a list of labels, and a list of values. Values use a kind discriminator 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 value
  • ramp: linear ramp up to peak over period, optional invert, offset
  • square: square wave with period, magnitude, duty_cycle (0–100), optional invert, offset
  • sine: sine wave with period, amplitude, optional offset
  • gaussian: random gaussian with mean, 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: true in 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mocktrics_exporter-0.1.1.tar.gz (27.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mocktrics_exporter-0.1.1-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file mocktrics_exporter-0.1.1.tar.gz.

File metadata

  • Download URL: mocktrics_exporter-0.1.1.tar.gz
  • Upload date:
  • Size: 27.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mocktrics_exporter-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1c1e394f9da9e1448c4589fef93d4dff542d294bd107d1621e322f41ce1e987e
MD5 654ff92f93601550f875ddbcffa80779
BLAKE2b-256 2c0da4c1792616d16451ffa18146b1b15d372c49c98f698f0264d11ce1b55116

See more details on using hashes here.

File details

Details for the file mocktrics_exporter-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mocktrics_exporter-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 891e4cdd12d6faa082090c8372911accf83dfcb0089724e82ee938bd8f82a78b
MD5 3cf30843ba3384efc90d4990108bc2e7
BLAKE2b-256 ff1c7eb08c5ba6f3d2d4fce25989fc7d09aebb1c421e2b7a7264fbfac42a8426

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page