| 1 | # Varnish exporter for Prometheus |
| 2 | |
| 3 |  |
| 4 | |
| 5 | Scrapes the `varnishstat -j` JSON output on each Prometheus collect and exposes all reported metrics. Metrics with |
| 6 | multiple backends or varnish defined identifiers (e.g. `VBE.*.happy SMA.*.c_bytes LCK.*.creat`) and other metrics with |
| 7 | similar structure (e.g. `MAIN.fetch_*`) are combined under a single metric name with distinguishable labels. Varnish |
| 8 | naming conventions are preserved as much as possible to be familiar to Varnish users when building queries, while trying to follow Prometheus conventions like lower casing and using `_` separators at the same time. |
| 9 | |
| 10 | Handles runtime Varnish changes like adding new backends via vlc reload. Removed backends are reported by `varnishstat` |
| 11 | until Varnish is restarted. |
| 12 | |
| 13 | Advanced users can use `-n -N`, they are passed to `varnishstat`. |
| 14 | |
| 15 | The following versions of Varnish are known to work: `6.0.0`, `5.2.1`, `5.1.2`, `4.1.1`, `4.1.0`, `4.0.3` and `3.0.5`. |
| 16 | Missing category groupings in 3.x like `MAIN.` are detected and added automatically for label names to be consistent |
| 17 | across versions, assuming of course that the Varnish project does not remove/change the stats. |
| 18 | |
| 19 | I won't make any backwards compatibility promises at this point. Your built queries can break on new versions if metric |
| 20 | names or labels are refined. If you find bugs or have feature requests feel free to create issues or send PRs. |
| 21 | |
| 22 | # Installing and running |
| 23 | |
| 24 | You can find the latest binary releases for linux, darwin, windows, freebsd, openbsd and netbsd from |
| 25 | the [GitHub releases page](https://github.com/otto-de/prometheus_varnish_exporter/releases). |
| 26 | |
| 27 | By default, the exporter listens on port `9131`. See `prometheus_varnish_exporter -h` for available options. |
| 28 | |
| 29 | To test that `varnishstat` is found on the host machine and to preview all exported metrics run |
| 30 | |
| 31 | prometheus_varnish_exporter -test |
| 32 | |
| 33 | # Troubleshooting |
| 34 | |
| 35 | > Could not get hold of varnishd, is it running? |
| 36 | > |
| 37 | > 2020/12/18 20:22:33 [FATAL] Startup test: varnishstat scrape failed: exit status 1 |
| 38 | |
| 39 | The user running the exporter is missing permissions to access varnish services. To avoid using `sudo` see [#62](https://github.com/jonnenauha/prometheus_varnish_exporter/issues/62). |
| 40 | |
| 41 | # Docker |
| 42 | |
| 43 | Scraping metrics from Varnish running in a docker container is possible since 1.4.1. Resolve your Varnish container name |
| 44 | with `docker ps` and run the following. This will use `docker exec <container-name>` to execute varnishstat inside the |
| 45 | specified container. |
| 46 | |
| 47 | prometheus_varnish_exporter -docker-container-name <container_name> |
| 48 | |
| 49 | I still don't have an easy, clear and user-friendly way of running this exporter in a docker container. For community |
| 50 | efforts and solutions see [this issue](https://github.com/jonnenauha/prometheus_varnish_exporter/issues/25#issuecomment-492546458). |
| 51 | |
| 52 | ## Images |
| 53 | |
| 54 | Container images are built and published to our GHCR registry as part of the release process. Images are built for |
| 55 | multiple architectures (amd64, arm64) and for the latest major Varnish/Vinyl versions. |
| 56 | |
| 57 | The image tags are in the format `<version>-varnish-<varnish-version>`. For example `1.7.0-varnish-8.0.0`. |
| 58 | |
| 59 | [ghcr.io/otto-de/prometheus-varnish-exporter](https://github.com/orgs/otto-de/packages/container/package/prometheus-varnish-exporter) |
| 60 | |
| 61 | # Grafana dashboards |
| 62 | |
| 63 | The example dashboard is available [in JSON format](dashboards/jonnenauha/dashboard.json). Feel free to send PRs for additional dashboards or improvements to existing ones. |
| 64 | |
| 65 | # Varnish 4 and VCL UUIDs |
| 66 | |
| 67 | Starting with version 1.2 `backend` and `server` labels are always set. For backend-related metrics and Varnish 4 the |
| 68 | `server` tag will be set to the VCL UUIDs for that backend. Note that there might be multiple VCLs loaded at the same |
| 69 | time and the `server` tag might not be meaningful in that case. |
| 70 | |
| 71 | To aggregate all loaded VCLs into per-backend metric the following |
| 72 | Prometheus [recording rules](https://prometheus.io/docs/querying/rules/) are recommended: |
| 73 | |
| 74 | backend:varnish_backend_bereq_bodybytes:sum = sum(varnish_backend_bereq_bodybytes) without (server) |
| 75 | backend:varnish_backend_bereq_hdrbytes:sum = sum(varnish_backend_bereq_hdrbytes) without (server) |
| 76 | backend:varnish_backend_beresp_bodybytes:sum = sum(varnish_backend_beresp_bodybytes) without (server) |
| 77 | backend:varnish_backend_beresp_hdrbytes:sum = sum(varnish_backend_beresp_hdrbytes) without (server) |
| 78 | backend:varnish_backend_conn:sum = sum(varnish_backend_conn) without (server) |
| 79 | backend:varnish_backend_happy:sum = sum(varnish_backend_happy) without (server) |
| 80 | backend:varnish_backend_pipe_hdrbytes:sum = sum(varnish_backend_pipe) without (server) |
| 81 | backend:varnish_backend_pipe_in:sum = sum(varnish_backend_pipe_in) without (server) |
| 82 | backend:varnish_backend_pipe_out:sum = sum(varnish_backend_pipe_out) without (server) |
| 83 | backend:varnish_backend_req:sum = sum(varnish_backend_req) without (server) |
| 84 | |
| 85 | # Build |
| 86 | |
| 87 | **One time setup** |
| 88 | |
| 89 | This repository uses Golang with go modules. The minimum required version is defined in [go.mod](https://github.com/otto-de/prometheus_varnish_exporter/blob/master/go.mod#L3), later version are supported as well. To install go, [follow the upstream recommendations](https://golang.org/doc/install) or use the Golang package provided by your distribution. |
| 90 | |
| 91 | **Development** |
| 92 | |
| 93 | ```bash |
| 94 | # clone |
| 95 | git clone [email protected]:otto-de/prometheus_varnish_exporter.git |
| 96 | cd prometheus_varnish_exporter |
| 97 | |
| 98 | # build binary to current directory |
| 99 | go build |
| 100 | |
| 101 | # draft local release with cross compilation |
| 102 | goreleaser release --snapshot --clean |
| 103 | ``` |
| 104 | |
| 105 | ## Release |
| 106 | |
| 107 | Releases are done with [goreleaser](https://goreleaser.com/). Make sure you have it installed or use the GitHub Action |
| 108 | for releases. |
| 109 | |
| 110 | To create a new release via the GitHub Action workflow you will have to create a new git tag with is a valid semantic |
| 111 | version. |
| 112 | |
| 113 | 1. Update `CHANGELOG.md` with the changes for the new version and commit the changes. |
| 114 | 2. Create and push a new git tag: |
| 115 | > [!NOTE] |
| 116 | > Replace `v1.7.0` with your desired version number. |
| 117 | ```bash |
| 118 | git tag v1.7.0 |
| 119 | git push origin v1.7.0 |
| 120 | ``` |
| 121 | 3. Check the Actions tab on GitHub for the release workflow to complete. |
| 122 | |
| 123 | This will trigger the release workflow that will build and publish |
| 124 | binaries to the GitHub releases and also build and publish docker images to the GHCR |
| 125 | registry. |