first commit

This commit is contained in:
Mateusz Gruszczyński
2026-06-26 11:01:55 +02:00
commit 7ed796f12c
3 changed files with 1194 additions and 0 deletions
+83
View File
@@ -0,0 +1,83 @@
# Varnish Prometheus Business Exporter
Lightweight Python exporter for Varnish. It exposes `/metrics` for Prometheus and focuses on per-domain business/operational statistics rather than only raw counters.
## Requirements
- Python 3
- `varnishstat`
- `varnishlog`
- Access to Varnish shared memory/logs, usually by running as root or with proper permissions
No external Python dependencies are required.
## Quick start
Only varnishstat:
```bash
python3 varnish_exporter.py --modules core,stat
```
Test VSL without sampling:
```bash
sudo python3 varnish_exporter.py --enable-vsl --vsl-sample 1 --profile full
```
Recommended production mode:
```bash
sudo python3 varnish_exporter.py \
--port 9131 \
--enable-vsl \
--profile standard \
--vsl-sample 0.001
```
Then check:
```bash
curl -s http://127.0.0.1:9131/metrics | grep varnish_domain
```
## Profiles
- `minimal`: rps, hit ratio, backend ratio, 5xx ratio, p95 latency
- `standard`: recommended business-oriented domain statistics
- `full`: more detailed derived statistics
- `raw`: full plus raw HTTP counters/histograms
## Modules
- `core`: exporter self metrics
- `stat`: `varnishstat -1 -j`
- `vsl`: `varnishlog -g request`
- `domain`: derived per-domain statistics
- `raw`: raw request counters/histograms
Example:
```bash
sudo python3 varnish_exporter.py --modules core,stat,vsl,domain --profile standard
```
## Domain grouping
Use `config.example.json` as a template:
```bash
sudo python3 varnish_exporter.py \
--config ./config.example.json \
--enable-vsl \
--profile standard
```
If no config is provided, the exporter uses the real Host header as the `site` label.
## Important notes
- Varnish cannot measure real browser render time such as LCP/FCP/DOMContentLoaded.
- Latency here means server-side response time as observed by Varnish.
- For high traffic, avoid `--vsl-sample 1` in production.
- Start production with `--vsl-sample 0.001` or `0.0001`.
+19
View File
@@ -0,0 +1,19 @@
{
"site_rules": [
{
"match": "(^|\\.)example\\.com$",
"site": "example_com"
},
{
"match": "(^|\\.)static\\.example\\.com$",
"site": "static_example_com"
},
{
"match": "(^|\\.)api\\.example\\.com$",
"site": "api_example_com"
}
],
"default_site": "other",
"allowed_methods": ["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
"histogram_buckets": [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10]
}
+1092
View File
File diff suppressed because it is too large Load Diff