Skip to main content

A Locust plugin to extract test results and push metrics to Victoria Metrics

Project description

locust-victoria-metrics

A Locust plugin to extract test results and push metrics to VictoriaMetrics.

PyPI License


📦 Overview

locust-victoria-metrics is a plugin for Locust that captures test metrics such as request statistics, failures, and custom events, then pushes them to VictoriaMetrics, a fast, cost-effective, and scalable time-series database.

This helps you:

  • Collect detailed performance test data over time
  • Build dashboards using Grafana + VictoriaMetrics
  • Analyze trends and regressions across multiple test runs

🚀 Features

  • Push Locust metrics in real-time or at test end
  • Automatic metric formatting for VictoriaMetrics (Prometheus format)
  • Lightweight and easy to plug into existing Locust tests
  • Supports custom metric tags (test name, environment, etc.)

🛠️ Installation

From PyPI

pip install locust-victoria-metrics

From Source

git clone https://github.com/dsetiawan230294/locust-victoria-metrics.git
cd locust-victoria-metrics
pip install .

🧪 Usage

1. Enable the plugin in your Locust script:

from locust import HttpUser, task, between, events, TaskSet
from locust_victoria_metrics.pusher import VictoriaMetricsPusher

# Initialize the plugin (can be done once globally or inside a test runner)
# Place below snippet code at the end of locust script file.
def on_locust_init(environment, **_kwargs):
    metrics_pusher = VictoriaMetricsPusher(
        locust_host= "http://localhost:8089"
        victoria_host="http://your-victoria-metrics-host:8428/api/v1/import/prometheus",
        interval=5,  
        product_name="Transaction" # for filtering in grafana
    )

    def run_exporter():
        while True:
            try:
                exporter.collect()
            except Exception as e:
                logger.error(f"Error in metrics exporter: {e}")
            time.sleep(1)

    from threading import Thread

    Thread(target=run_exporter, daemon=True).start()

events.init.add_listener(on_locust_init)
  • MANDATORY to run the locust script with argument --autostart --autoquit 1

⚙️ Configuration

Parameter Type Description
locust_host str Locust Exposed Endpoint
victoria_host str VictoriaMetrics HTTP API endpoint (Prometheus format)
interval int Push interval in seconds (default: 10)
product_name str Additional tags/labels to include with each metric

📊 Example Metrics Pushed

locust_request_count{method="GET", name="/api/test", status="200", job="loadtest", instance="test-runner-1"} 123
locust_request_failure_count{method="GET", name="/api/test", job="loadtest"} 4
locust_avg_response_time{name="/api/test"} 245.7

These metrics can be visualized in Grafana using VictoriaMetrics as a data source.


📈 Grafana Dashboard

You can build custom dashboards using:

  • locust_request_count
  • locust_request_failure_count
  • locust_avg_response_time
  • locust_users

🧩 Compatibility

  • ✅ Locust 2.29.1+
  • ✅ Python 3.10+
  • ✅ Tested with VictoriaMetrics single-node and cluster setups

🤝 Contributing

Contributions, issues, and feature requests are welcome!

  1. Fork this repository
  2. Create your feature branch: git checkout -b feature/my-feature
  3. Commit your changes: git commit -am 'Add new feature'
  4. Push to the branch: git push origin feature/my-feature
  5. Open a pull request

📄 License

This project is licensed under the MIT License. See the LICENSE file for details.


👨‍💻 Author

Didit Setiawan
GitHub · Email

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

locust_victoria_metrics-0.0.2.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

locust_victoria_metrics-0.0.2-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file locust_victoria_metrics-0.0.2.tar.gz.

File metadata

  • Download URL: locust_victoria_metrics-0.0.2.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for locust_victoria_metrics-0.0.2.tar.gz
Algorithm Hash digest
SHA256 a22ed0129d0ce2f806d4dda6a81a37ca0417c9acad9720d48c535a514785ea6a
MD5 52be5e7e9dcf0abaa75595dc9d75b614
BLAKE2b-256 f25025a655f779259268015638b9dda014f0302260caeb218f1cedd5f27082fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for locust_victoria_metrics-0.0.2.tar.gz:

Publisher: release.yml on dsetiawan230294/locust-victoria-metrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file locust_victoria_metrics-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for locust_victoria_metrics-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b018df33360f67e89ce64997c206718ccdfb268bcf240228af5c3c1ba1555a27
MD5 887ec79cc1708d6e344b0b7dac2ee6b0
BLAKE2b-256 7a7795ff0bbb2da1745543caca6be29e11736a7d012d46d4866a22c7b816c1e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for locust_victoria_metrics-0.0.2-py3-none-any.whl:

Publisher: release.yml on dsetiawan230294/locust-victoria-metrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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