1VARNISHNCSA(1) VARNISHNCSA(1)
2
3
4
6 varnishncsa - Display Varnish logs in Apache / NCSA combined log format
7
9 varnishncsa [-a] [-b] [-c] [-C] [-d] [-D] [-E] [-F <format>] [-f <for‐
10 matfile>] [-g <request|vxid>] [-h] [-j] [-L <limit>] [-n <dir>] [-P
11 <file>] [-Q <file>] [-q <query>] [-r <filename>] [-R <limit[/dura‐
12 tion]>] [-t <seconds|off>] [-V] [-w <filename>]
13
15 The varnishncsa utility reads varnishd(1) shared memory logs and
16 presents them in the Apache / NCSA "combined" log format.
17
18 Each log line produced is based on a single Request type transaction
19 gathered from the shared memory log. The Request transaction is then
20 scanned for the relevant parts in order to output one log line. To fil‐
21 ter the log lines produced, use the query language to select the appli‐
22 cable transactions. Non-request transactions are ignored.
23
24 The following options are available:
25
26 -a When writing output to a file, append to it rather than over‐
27 write it.
28
29 -b Log backend requests. If -c is not specified, then only backend
30 requests will trigger log lines.
31
32 -c Log client requests. This is the default. If -b is specified,
33 then -c is needed to also log client requests
34
35 -C Do all regular expression and string matching caseless.
36
37 -d Process log records at the head of the log and exit.
38
39 -D Daemonize.
40
41 -E Show ESI requests, implies client mode.
42
43 -F <format>
44 Set the output log format string.
45
46 -f <formatfile>
47 Read output format from a file. Will read a single line from the
48 specified file, and use that line as the format.
49
50 -g <request|vxid>
51 The grouping of the log records. The default is to group by
52 vxid.
53
54 -h Print program usage and exit
55
56 -j Make format-specifier replacements JSON-compatible. When escap‐
57 ing characters, use JSON-style \uXXXX escape sequences instead
58 of C-style \xXX sequences. Empty strings will be replaced with
59 "" instead of "-", and empty integers will be replaced with
60 null. Use -F or -f in combination with -j to write JSON logs.
61
62 -L <limit>
63 Sets the upper limit of incomplete transactions kept before the
64 oldest transaction is force completed. A warning record is syn‐
65 thesized when this happens. This setting keeps an upper bound on
66 the memory usage of running queries. Defaults to 1000 transac‐
67 tions.
68
69 -n <dir>
70 Specify the varnishd working directory (also known as instance
71 name) to get logs from. If -n is not specified, the host name is
72 used.
73
74 -P <file>
75 Write the process' PID to the specified file.
76
77 -Q <file>
78 Specifies the file containing the VSL query to use. When multi‐
79 ple -Q or -q options are specified, all queries are considered
80 as if the 'or' operator was used to combine them.
81
82 -q <query>
83 Specifies the VSL query to use. When multiple -q or -Q options
84 are specified, all queries are considered as if the 'or' opera‐
85 tor was used to combine them.
86
87 -r <filename>
88 Read log in binary file format from this file. The file can be
89 created with varnishlog -w filename.
90
91 -R <limit[/duration]>
92 Restrict the output to the specified limit. Transactions exceed‐
93 ing the limit will be suppressed. The limit is specified as the
94 maximum number of transactions (with respect to the chosen
95 grouping method) and an optional time period. If no duration is
96 specified, a default of s is used. The duration field can be
97 formatted as in VCL (e.g. -R 10/2m) or as a simple time period
98 without the prefix (e.g. -R 5/m). When in -g raw grouping mode,
99 this setting can not be used alongside -i, -I, -x or -X, and we
100 advise using -q instead.
101
102 -t <seconds|off>
103 Timeout before returning error on initial VSM connection. If set
104 the VSM connection is retried every 0.5 seconds for this many
105 seconds. If zero the connection is attempted only once and will
106 fail immediately if unsuccessful. If set to "off", the connec‐
107 tion will not fail, allowing the utility to start and wait inde‐
108 finetely for the Varnish instance to appear. Defaults to 5 sec‐
109 onds.
110
111 -V Print version information and exit.
112
113 -w <filename>
114 Redirect output to file. The file will be overwritten unless the
115 -a option was specified. If the application receives a SIGHUP in
116 daemon mode the file will be reopened allowing the old one to be
117 rotated away. This option is required when running in daemon
118 mode.
119
120 --optstring
121 Print the optstring parameter to getopt(3) to help writing wrap‐
122 per scripts.
123
125 The default mode of varnishncsa is "client mode". In this mode, the
126 log will be similar to what a web server would produce in the absence
127 of varnish. Client mode can be explicitly selected by using -c.
128
129 If the -b switch is specified, varnishncsa will operate in "backend
130 mode". In this mode, requests generated by varnish to the backends
131 will be logged. Unless -c is also specified, client requests received
132 by varnish will be ignored.
133
134 When running varnishncsa in both backend and client mode, it is
135 strongly advised to include the format specifier %{Varnish:side}x to
136 distinguish between backend and client requests.
137
138 Client requests that results in a pipe (ie. return(pipe) in vcl), will
139 not generate logging in backend mode. This is because varnish is not
140 generating requests, but blindly passes on bytes in both directions.
141 However, a varnishncsa instance running in normal mode can see this
142 case by using the formatter %{Varnish:handling}x, which will be 'pipe'.
143
144 In backend mode, some of the fields in the format string get different
145 meanings. Most notably, the byte counting formatters (%b, %I, %O) con‐
146 siders varnish to be the client.
147
148 It is possible to keep two varnishncsa instances running, one in back‐
149 end mode, and one in client mode, logging to different files.
150
152 Specify the log format to use. If no format is specified the default
153 log format is used:
154
155 %h %l %u %t "%r" %s %b "%{Referer}i" "%{User-agent}i"
156
157 Escape sequences \n and \t are supported.
158
159 Supported formatters are:
160
161 %b In client mode, size of response in bytes, excluding HTTP head‐
162 ers. In backend mode, the number of bytes received from the
163 backend, excluding HTTP headers. In CLF format, i.e. a '-'
164 rather than a 0 when no bytes are sent.
165
166 %D In client mode, time taken to serve the request, in microsec‐
167 onds. In backend mode, time from the request was sent to the
168 entire body had been received. This is equivalent to %{us}T.
169
170 %H The request protocol. Defaults to HTTP/1.0 if not known.
171
172 %h Remote host. Defaults to '-' if not known. In backend mode this
173 is the IP of the backend server.
174
175 %I In client mode, total bytes received from client. In backend
176 mode, total bytes sent to the backend.
177
178 %{X}i The contents of request header X. If the header appears multiple
179 times in a single transaction, the last occurrence is used.
180
181 %l Remote logname. Always '-'.
182
183 %m Request method. Defaults to '-' if not known.
184
185 %{X}o The contents of response header X. If the header appears multi‐
186 ple times in a single transaction, the last occurrence is used.
187
188 %O In client mode, total bytes sent to client. In backend mode,
189 total bytes received from the backend.
190
191 %q The query string. Defaults to an empty string if not present.
192
193 %r The first line of the request. Synthesized from other fields, so
194 it may not be the request verbatim. See the NOTES section.
195
196 %s Status sent to the client. In backend mode, status received
197 from the backend.
198
199 %t In client mode, time when the request was received, in HTTP
200 date/time format. In backend mode, time when the request was
201 sent.
202
203 %{X}t In client mode, time when the request was received, in the for‐
204 mat specified by X. In backend mode, time when the request was
205 sent. The time specification format is the same as for strf‐
206 time(3) with these extensions:
207
208 • %{sec}: number of seconds since the Epoch
209
210 • %{msec}: number of milliseconds since the Epoch
211
212 • %{usec}: number of milliseconds since the Epoch
213
214 • %{msec_frac}: millisecond fraction
215
216 • %{usec_frac}: microsecond fraction
217
218 The extensions can not be combined with each other or strf‐
219 time(3) in the same specification. Use multiple %{X}t specifica‐
220 tions instead.
221
222 %T In client mode, time taken to serve the request, in seconds. In
223 backend mode, time from the request was sent to the entire body
224 had been received. This is equivalent to %{s}T.
225
226 %{X}T In client mode, time taken to serve the request, in the format
227 specified by X. In backend mode, time from the request was sent
228 to the entire body had been received. The time specification
229 format can be one of the following: s (same as %T), ms or us
230 (same as %D).
231
232 %U The request URL without the query string. Defaults to '-' if not
233 known.
234
235 %u Remote user from auth.
236
237 %{X}x Extended variables. Supported variables are:
238
239 Varnish:time_firstbyte
240 Time from when the request processing starts until the
241 first byte is sent to the client, in seconds. For back‐
242 end mode: Time from the request was sent to the backend
243 to the entire header had been received.
244
245 Varnish:hitmiss
246 One of the 'hit' or 'miss' strings, depending on whether
247 the request was a cache hit or miss. Pipe, pass and synth
248 are considered misses.
249
250 Varnish:handling
251 One of the 'hit', 'miss', 'pass', 'pipe' or 'synth'
252 strings indicating how the request was handled.
253
254 Varnish:side
255 Backend or client side. One of two values, 'b' or 'c',
256 depending on where the request was made. In pure backend
257 or client mode, this field will be constant.
258
259 Varnish:vxid
260 The VXID of the varnish transaction.
261
262 VCL_Log:key
263 The value set by std.log("key:value") in VCL.
264
265 VSL:tag:record-prefix[field]
266 The value of the VSL entry for the given tag-record pre‐
267 fix-field combination. Tag is mandatory, the other compo‐
268 nents are optional.
269
270 The record prefix will limit the matches to those records
271 that have this prefix as the first part of the record
272 content followed by a colon.
273
274 The field will, if present, treat the log record as a
275 white space separated list of fields, and only the nth
276 part of the record will be matched against. Fields start
277 counting at 1 and run up to 255.
278
279 Defaults to '-' when the tag is not seen, the record pre‐
280 fix does not match or the field is out of bounds. If a
281 tag appears multiple times in a single transaction, the
282 first occurrence is used.
283
285 • SIGHUP
286
287 Rotate the log file (see -w option) in daemon mode, abort the loop
288 and die gracefully when running in the foreground.
289
290 • SIGUSR1
291
292 Flush any outstanding transactions.
293
295 The %r formatter is equivalent to "%m http://%{Host}i%U%q %H". This
296 differs from apache's %r behavior, equivalent to "%m %U%q %H". Fur‐
297 thermore, when using the %r formatter, if the Host header appears mul‐
298 tiple times in a single transaction, the first occurrence is used.
299
301 Log the second field of the Begin record, corresponding to the VXID of
302 the parent transaction:
303
304 varnishncsa -F "%{VSL:Begin[2]}x"
305
306 Log the entire Timestamp record associated with the processing length:
307
308 varnishncsa -F "%{VSL:Timestamp:Process}x"
309
310 Log in JSON, using the -j flag to ensure that the output is valid JSON
311 for all inputs:
312
313 varnishncsa -j -F '{"size": %b, "time": "%t", "ua": "%{User-Agent}i"}'
314
316 varnishd(1) varnishlog(1) varnishstat(1) vsl(7)
317
319 The varnishncsa utility was developed by Poul-Henning Kamp in coopera‐
320 tion with Verdens Gang AS and Varnish Software AS. This manual page was
321 initially written by Dag-Erling Smørgrav <des@des.no>, and later up‐
322 dated by Martin Blix Grydeland and Pål Hermunn Johansen.
323
325 This document is licensed under the same licence as Varnish itself. See
326 LICENCE for details.
327
328 • Copyright (c) 2006 Verdens Gang AS
329
330 • Copyright (c) 2006-2016 Varnish Software AS
331
332
333
334
335 VARNISHNCSA(1)