Using varnish is quite simple, but configure and interpret varnish needs some time to understand. This section gives you the most important sources and commands to understand varnish better.
Varnish VCL is the most important part of varnish. In this file you can define the behaviour of varnish. For example what and how long a request gets cached. In the sources section are some links to get more familiar with a varnish VCL.
Watch and Interpret Varnish Metrics
If you want to check the health of varnish, you will use the tool
varnishstat. There is a huge amount of metrics. The most important metrics can be viewed with this command
docker exec -t <container-name> /usr/bin/varnishstat -f MAIN.sess_conn -f MAIN.client_req -f MAIN.sess_dropped -f MAIN.cache_hit -f MAIN.cache_miss -f MAIN.cache_hitpass -f MAIN.n_lru_nuked -f MAIN.n_expired -f MAIN.thread_queue_len -f MAIN.backend_conn -f MAIN.backend_fail -f MAIN.backend_unhealthy -f MAIN.backend_busy -f MAIN.backend_req -f SMA.s0.g_bytes -f SMA.s0.g_space
|Cumulative number of accepted client connections by Varnish Cache
|Cumulative number of received client requests. Increments after a request is received, but before Varnish responds
|Number of connections dropped due to a full queue
|Cumulative number of times a file was served from Varnish’s cache
|Cumulative number of times a file was requested but was not in the cache, and was therefore requested from the backend
|Cumulative number of hits for a “pass” file
|Least Recently Used Nuked Objects: Cumulative number of cached objects that Varnish has evicted from the cache because of a lack of space
|Cumulative number of expired objects for example due to TTL
Thread Related Metrics
|Current queue length: number of requests waiting on worker thread to become available
|Cumulative number of successful TCP connections to the backend
|Cumulative number of failed connections to the backend. Should be 0 or near 0
|Cumulative number of backend connections which were not attempted because the backend has been marked as unhealthy
|Cumulative number of times the maximum amount of connections to the backend has been reached.
|Number of requests to the backend
|Bytes of cache used
|Bytes of cache left