locust-victoria-metrics
A Locust plugin to extract test results and push metrics to VictoriaMetrics.
📦 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_countlocust_request_failure_countlocust_avg_response_timelocust_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!
- Fork this repository
- Create your feature branch:
git checkout -b feature/my-feature - Commit your changes:
git commit -am 'Add new feature' - Push to the branch:
git push origin feature/my-feature - Open a pull request
📄 License
This project is licensed under the MIT License. See the LICENSE file for details.
👨💻 Author
Metadata
Release files for locust-victoria-metrics 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| locust_victoria_metrics-0.0.3.tar.gz | 6.1 kB | With provenance | Details for locust_victoria_metrics-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| locust_victoria_metrics-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for locust_victoria_metrics-0.0.3-py3-none-any.whl |
Total release size: 12.0 kB
Release files / locust_victoria_metrics-0.0.3.tar.gz
| Download URL | locust_victoria_metrics-0.0.3.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
be7611288b5daf2984429fe0a8f58c15f6c8e1c26feff6268d65995de3ece40d
|
|
BLAKE2b-256 checksum How to use checksums |
cb8f88140b3adf2cd42e8c230315e6c9ae914cdf7f42c05dd11f9f1a74c476b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 19, 2025.
Transparency logRelease files / locust_victoria_metrics-0.0.3-py3-none-any.whl
| Download URL | locust_victoria_metrics-0.0.3-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
53fdbfcc7ab94d53717b7283731bccfb8e9ed2f3a4d0269c179f072cc1b61496
|
|
BLAKE2b-256 checksum How to use checksums |
39cf3c8179fecf41fc7d8d7e06765882b22ca5223babedb265d33c554f159389
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 19, 2025.
Transparency logSecurity for locust-victoria-metrics 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for locust_victoria_metrics-0.0.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 19, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.