README
ΒΆ
varnishmon
varnishmon is a utility inspired by the classic atop tool. It periodically collects metrics from Varnish Cache / Varnish Enterprise using the varnishstat utility, stores them in a DuckDB database, and provides a simple built-in web interface for visualizing the timeseries data. In summary, varnishmon is a tool designed to effortlessly record, visualize, and share historical varnishstat output with minimal setup.

While varnishmon doesn't replace a comprehensive monitoring solutions like Prometheus or Zabbix, it is particularly useful when existing monitoring systems fall short. The most common use case is troubleshooting, where more granular samples (usual monitoring periods may be insufficient) and/or additional metrics (scraping the entire varnishstat output is typically excessive for daily monitoring) are needed. The collected data is stored in a DuckDB database, making it easy to share and analyze with other tools.
varnishmon is a self-contained executable that allows you to start collecting data with minimal effort and explore it through a simple yet effective web interface. In addition to occasional troubleshooting, varnishmon can also be used as a lightweight, permanent service to collect, store, visualize, and rotate Varnish metrics. Similar to running atop in logging mode as a complement to regular monitoring, varnishmon provides valuable context during incident analysis.
π Table of Contents
π Quick Start
-
Download & install
- Download the latest release from the releases page. Choose between a
.tgzfile containing only thevarnishmonexecutable, or a DEB / RPM package if you plan to runvarnishmonas a service. - The executable is self-contained and does not require any additional dependencies.
- Download the latest release from the releases page. Choose between a
-
Collect metrics
- Run the following command to scrape metrics every 15 seconds, store them in
/tmp/varnishmon.db(to use an in-memory database, omit the--dboption), and bind the built-in web interface to port 6100 on all interfaces. Behind the scenes this will run/usr/bin/varnishstat -1 -jperiodically, so ensure your user has the necessary permissions (typically, you need to be in thevarnishgroup):varnishmon --period 15s --db /tmp/varnishmon.db --ip 0.0.0.0 --port 6100 - If running
varnishmonas a service:- Fine-tune the configuration by editing the
/etc/varnishmon/varnishmon.ymlfile and start the service withsystemctl start varnishmon. - By default, the timeseries data will be stored in
/var/lib/varnishmon/varnishmon.dband the logs in/var/log/varnishmon/varnishmon.log.
- Fine-tune the configuration by editing the
- Run the following command to scrape metrics every 15 seconds, store them in
-
Visualize timeseries
- Open your browser and navigate to
http://<host>:6100. - Remember to stop
varnishmonwhen you're done, as it will continue to collect metrics until you kill the process.
- Open your browser and navigate to
π€ Q & A
Usage
-
How do I access the
varnishmonweb interface?First, ensure the
varnishmonAPI is enabled (it is by default) and successfully bound to an IP address and port (default is127.0.0.1:6100). To make it accessible from other hosts, you can bind it to0.0.0.0; however, using an SSH tunnel is typically the best option. Then, open your browser and navigate tohttp://localhost:6100.ssh -L 6100:localhost:6100 user@host -
I need
sudoto runvarnishstat. How can I usevarnishmon?Ideally, you should add your user to the
varnishgroup to avoid usingsudo. If this is not possible, you can use the--varnishstatflag (or thescraper.varnishstatsetting) to specify the commandvarnishmonshould use to collect metrics. Ensure you use the-1 -jflags to output JSON. Note that the full path of thesudocommand is required becausevarnishmondoes not use a shell.varnishmon \ --period 15s \ --db /tmp/varnishmon.db \ --varnishstat '/usr/bin/sudo varnishstat -1 -j' -
Can I use
varnishmonwith Varnish instances running in a container?If you can run
varnishmondirectly within the container, no special configuration is required. However, if you need to execute a command likedocker exec ...to gather thevarnishstatoutput, you can use the--varnishstatflag (or thescraper.varnishstatsetting) to specify an alternative command. Remember to use the-1 -jflags (to ensurevarnishstatoutputs JSON) and to provide the full path to thedockercommand. -
How do I use
varnishmonto collect metrics remotely?You can use the
--varnishstatflag (or thescraper.varnishstatsetting) to specify a command that collects metrics remotely. For example, you can use/usr/bin/ssh <user>@<host> varnishstat -1 -j. Make sure to use SSH keys for passwordless authentication and don't forget to provide the full path to thesshcommand. -
How do I use
varnishmonto visualize metrics previously collected on a different server?Similar to
atop, you can collect metrics on the Varnish server, transfer them to your local machine, and usevarnishmonto visualize them. In this case, you may want to:- Use the
--no-apiflag (or theapi.enabledsetting) on the Varnish server to prevent the web interface from starting there. - Use the
--no-scraperflag (or thescraper.enabledsetting) on your local machine to avoid collecting metrics locally.
- Use the
-
How often does
varnishmoncollect metrics?That depends on the
--periodflag (or thescraper.periodsetting). The default value is set to 60 seconds, but you can adjust it to suit your needs.
Configuration & Customization
-
What are the system requirements for
varnishmon?varnishmonis a lightweight utility. Its embedded DuckDB database is by far the most resource-intensive component, but the default configuration (i.e.,db.memory-limit,db.threads, etc.) limits resource consumption to 512 MiB and 1 CPU core. However, depending on the number of metrics in your Varnish setup and the scraping period, it may require a significant amount of disk space and memory. Plan accordingly and adjust the limits as needed. -
I'm tired of typing the same options every time I run
varnishmon. Can I save them?Command line flags are shortcuts to override settings in the configuration file. Alternatively, you can create a configuration file in one of the standard locations (
/etc/varnish/varnishmon.yml,~/.config/varnishmon.yml, etc.) and letvarnishmonread it automatically. This is the default behavior when runningvarnishmonas a service. -
Is it possible to secure the
varnishmonweb interface?For typical operation (i.e., API bound to
127.0.0.1and accessed through an SSH tunnel), this is likely not a concern. However, the configuration file allows you, (1) to specify a username and password for HTTP Basic Authentication; and (2) to enable HTTPS. -
What if I don't want to run the
varnishmonweb interface?Use the
--no-apiflag (or theapi.enabledsetting) to prevent the web interface from starting. You can still collect metrics and store them in the database. -
Can I customize the metrics collected by
varnishmon?Not directly, as
varnishmonis designed to collect comprehensive information. However, you can use the--varnishstatflag (or thescraper.varnishstatsetting) to specify a wrapper script that filters thevarnishstatoutput (or an inline command if you're up for the quoting challenge). Check out this example wrapper script for inspiration on how to filter and/or extend the metrics collected.varnishmon \ --period 15s \ --db /tmp/varnishmon.db \ --varnishstat "/usr/bin/bash -c 'varnishstat -1 -j | jq \"with_entries(select(.key | test(\\\"^VBE|MEMPOOL[.]\\\") | not))\"'" -
What if I don't want to store the collected data permanently?
To use an in-memory database, set the
--dbflag (or thedb.filesetting) to an empty value. Note that the data will be lost whenvarnishmonexits. Additionally, be aware that an in-memory database may consume a significant amount of memory, depending on (1) the number of metrics; (2) the scraping period; and (3) the durationvarnishmonruns. -
How do I build
varnishmonfrom source?The build process is designed to be executed on the target platform (e.g., Ubuntu Noble, Ubuntu Jammy, etc.) and architecture (
amd64orarm64). The dependencies are minimal (make,git,go,g++, etc.; refer to the Dockerfiles used by GitHub Actions for guidance). To build, simply runmake buildin the root of the repository.
Running as a Service
-
Can I run
varnishmonas a service?Yes,
varnishmonis designed to be run as a service. You can use the DEB / RPM packages available in the releases page or create your own service unit file. -
I'm running
varnishmonas a service. How do I rotate the database?The DEB / RPM packages include
logrotateconfiguration files to manage the rotation of the database and log files. Alternatively, you can manually rotate them by renaming the database and log files, and then sending aSIGHUPsignal to thevarnishmonprocess. This method also works with an in-memory database, discarding the old data.kill -HUP $(pgrep varnishmon) -
Is it necessary to rotate the
varnishmondatabase?While it is not mandatory,
varnishmonis optimized for navigating databases that cover relatively short time periods. For visualizing metrics over extended periods, it is recommended to use a dedicated monitoring tool like Prometheus or Zabbix. -
I'm running
varnishmonas a service. How can I monitor its health?Whether running as a service or as a standalone tool,
varnishmonexposes a/metricsAPI endpoint for health monitoring. You can use a monitoring tool like Prometheus to scrape this endpoint and set up alerts based on the collected metrics.$ curl -s http://localhost:6100/metrics ... # HELP archiver_out_of_order_samples_total Out-of-order samples received by the archiver worker # TYPE archiver_out_of_order_samples_total counter archiver_out_of_order_samples_total 0 # HELP archiver_push_completed_total Successful pushes of metrics by the archiver worker # TYPE archiver_push_completed_total counter archiver_push_completed_total 47248 # HELP archiver_push_failed_total Failed pushes of metrics by the archiver worker # TYPE archiver_push_failed_total counter archiver_push_failed_total 0 # HELP archiver_reset_counters_total Counter resets detected by the archiver worker # TYPE archiver_reset_counters_total counter archiver_reset_counters_total 0 # HELP archiver_truncated_samples_total Samples (bitmaps excluded) truncated by the archiver worker # TYPE archiver_truncated_samples_total counter archiver_truncated_samples_total 0 ...
Miscellaneous
-
Why
varnishstat? Why not use the Varnish shared memory log?While it may seem beneficial to avoid forking the
varnishstatprocess on every scrape, we believe it wouldn't significantly impact performance. Moreover, it would reduce the flexibility provided by the use of a wrapper script, such as filtering metrics or running on a different host. -
How is the collected data stored?
The collected data is stored as timeseries in a DuckDB database using a straightforward schema. The output of
varnishstatis stored mostly as-is, except for counters, which are converted into eps rates to enhance data usability. Download the DuckDB CLI to explore the database on your own. It's very simple.$ duckdb /path/to/varnishmon.db v1.1.3 19864453f7 Enter ".help" for usage hints. D show tables; βββββββββββββββββ β name β β varchar β βββββββββββββββββ€ β metadata β β metric_values β β metrics β βββββββββββββββββ D select * from metric_values; βββββββββββββ¬ββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββ β metric_id β timestamp β value β β int32 β timestamp β union(float64 double, uint64 ubigint) β βββββββββββββΌββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββ€ β 1 β 2025-01-22 18:13:53 β 1 β β 2 β 2025-01-22 18:13:53 β 768 β β 3 β 2025-01-22 18:13:53 β 1467764736 β β 4 β 2025-01-22 18:13:53 β 1020225 β β 5 β 2025-01-22 18:13:53 β 0 β β 6 β 2025-01-22 18:13:53 β 0 β -
Are
varnishstatuint64values fully supported?Counters are stored in the DuckDB database as
float64eps rates for convenience. Otheruint64values (e.g., gauges, bitmaps, etc.) are stored with the most significant bit dropped due to a limitation in Go's SQL package. Additionally, on the client side (JavaScript), we are constrained by the Number type, which is afloat64value. In summary,varnishstatuint64values are supported, but with these minor limitations. -
Why DuckDB?
DuckDB is an ideal choice for
varnishmonbecause it is a lightweight, timeseries-friendly, and easily embeddable in-process analytical database. Its CLI is a simple, statically-linked binary that provides an easy way to analyze and share collected data with other tools. -
Is
varnishmonready for the AI/LLM era?While you already have a powerful brain and may not need to integrate LLMs into every aspect of your life, the answer is yesβjust for fun (and because it was incredibly easy to implement).
varnishmoncan be queried by LLMs using the Model Context Protocol. Specifically, thevarnishmonAPI supports the SSE transport mechanism via the/mcp/sseendpoint. For example, in GitHub Copilot + VS Code, you can enable 'agent' mode and configure thevarnishmonAPI as one of your MCP servers.{ "mcp": { "servers": { "varnishmon": { "type": "sse", "url": "http://127.0.0.1:6100/mcp/sse" } } } }Here's an example prompt: Using
varnishmon, identify the key metric that best represents incoming HTTP traffic. If the number of metrics is overwhelming, fetch them incrementally in manageable chunks, but always fetch all of them. Provide the metric's name, explain its significance, and highlight any unusual spikes or drops. For each anomaly, include the time windows (both as UNIX timestamps and as human-readable strings using thevarnishmon-timestampMCP tool for conversion) and describe how the traffic deviates from the expected pattern. Of course, results may vary due to various factors, including the unpredictable nature of LLMsβbecause, let's be honest, for this kind of analysis, your own brain (a.k.a., your built-in LLM) is probably the best tool for the job. -
I want to contribute to
varnishmon. How can I help?This is a small project, but there are many areas where you can contribute. Feel free to open an issue or a PR, or simply share your thoughts and ideas. A good starting point is to check the cheat sheet in the
docker-compose.ymlfile and start using the development environment.
π License
Please refer to LICENSE.txt for more information.
Copyright (c) Allenta Consulting S.L.
Made with β€ by the Varnish guys at Allenta.
Documentation
ΒΆ
There is no documentation for this package.