1VARNISHNCSA(1)                                                  VARNISHNCSA(1)
2
3
4

NAME

6       varnishncsa - Display Varnish logs in Apache / NCSA combined log format
7

SYNOPSIS

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

DESCRIPTION

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. This option has no effect without the -w option.
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. If the filename is -, logs
90              are read from the standard input. and cannot work as a daemon.
91
92       -R <limit[/duration]>
93              Restrict the output to the specified limit. Transactions exceed‐
94              ing  the limit will be suppressed. The limit is specified as the
95              maximum number of  transactions  (with  respect  to  the  chosen
96              grouping  method) and an optional time period. If no duration is
97              specified, a default of s is used. The  duration  field  can  be
98              formatted  as  in VCL (e.g. -R 10/2m) or as a simple time period
99              without the prefix (e.g. -R 5/m). When in -g raw grouping  mode,
100              this  setting can not be used alongside -i, -I, -x or -X, and we
101              advise using -q instead.
102
103       -t <seconds|off>
104              Timeout before returning error on initial VSM connection. If set
105              the  VSM  connection  is retried every 0.5 seconds for this many
106              seconds. If zero the connection is attempted only once and  will
107              fail  immediately  if unsuccessful. If set to "off", the connec‐
108              tion will not fail, allowing the utility to start and wait inde‐
109              finetely for the Varnish instance to appear.  Defaults to 5 sec‐
110              onds.
111
112       -V     Print version information and exit.
113
114       -w <filename>
115              Redirect output to file. The file will be overwritten unless the
116              -a option was specified. If the application receives a SIGHUP in
117              daemon mode the file will be reopened allowing the old one to be
118              rotated  away.  This  option  is required when running in daemon
119              mode. If the filename is -, varnishncsa writes to  the  standard
120              output and cannot work as a daemon.
121
122       --optstring
123              Print the optstring parameter to getopt(3) to help writing wrap‐
124              per scripts.
125

MODES

127       The default mode of varnishncsa is "client mode".  In  this  mode,  the
128       log  will  be similar to what a web server would produce in the absence
129       of varnish.  Client mode can be explicitly selected by using -c.
130
131       If the -b switch is specified, varnishncsa  will  operate  in  "backend
132       mode".   In  this  mode,  requests generated by varnish to the backends
133       will be logged.  Unless -c is also specified, client requests  received
134       by varnish will be ignored.
135
136       When  running  varnishncsa  in  both  backend  and  client  mode, it is
137       strongly advised to include the format  specifier  %{Varnish:side}x  to
138       distinguish between backend and client requests.
139
140       Client  requests that results in a pipe (ie. return(pipe) in vcl), will
141       not generate logging in backend mode. This is because  varnish  is  not
142       generating  requests,  but  blindly passes on bytes in both directions.
143       However, a varnishncsa instance running in normal  mode  can  see  this
144       case by using the formatter %{Varnish:handling}x, which will be 'pipe'.
145
146       In  backend mode, some of the fields in the format string get different
147       meanings.  Most notably, the byte counting formatters (%b, %I, %O) con‐
148       siders varnish to be the client.
149
150       It  is possible to keep two varnishncsa instances running, one in back‐
151       end mode, and one in client mode, logging to different files.
152

FORMAT

154       Specify the log format to use. If no format is  specified  the  default
155       log format is used:
156
157          %h %l %u %t "%r" %s %b "%{Referer}i" "%{User-agent}i"
158
159       Escape sequences \n and \t are supported.
160
161       Supported formatters are:
162
163       %b     In  client mode, size of response in bytes, excluding HTTP head‐
164              ers.  In backend mode, the number of  bytes  received  from  the
165              backend,  excluding  HTTP  headers.   In  CLF format, i.e. a '-'
166              rather than a 0 when no bytes are sent.
167
168       %D     In client mode, time taken to serve the  request,  in  microsec‐
169              onds.   In  backend  mode, time from the request was sent to the
170              entire body had been received. This is equivalent to %{us}T.
171
172       %H     The request protocol. Defaults to HTTP/1.0 if not known.
173
174       %h     Remote host. Defaults to '-' if not known.  In backend mode this
175              is the IP of the backend server.
176
177       %I     In  client  mode,  total bytes received from client.  In backend
178              mode, total bytes sent to the backend.
179
180       %{X}i  The contents of request header X. If the header appears multiple
181              times in a single transaction, the last occurrence is used.
182
183       %l     Remote logname. Always '-'.
184
185       %m     Request method. Defaults to '-' if not known.
186
187       %{X}o  The  contents of response header X. If the header appears multi‐
188              ple times in a single transaction, the last occurrence is used.
189
190       %O     In client mode, total bytes sent to client.   In  backend  mode,
191              total bytes received from the backend.
192
193       %q     The query string. Defaults to an empty string if not present.
194
195       %r     The first line of the request. Synthesized from other fields, so
196              it may not be the request verbatim. See the NOTES section.
197
198       %s     Status sent to the client.  In  backend  mode,  status  received
199              from the backend.
200
201       %t     In  client  mode,  time  when  the request was received, in HTTP
202              date/time format.  In backend mode, time when  the  request  was
203              sent.
204
205       %{X}t  In  client mode, time when the request was received, in the for‐
206              mat specified by X.  In backend mode, time when the request  was
207              sent.   The  time  specification format is the same as for strf‐
208              time(3) with these extensions:
209
210%{sec}: number of seconds since the Epoch
211
212%{msec}: number of milliseconds since the Epoch
213
214%{usec}: number of milliseconds since the Epoch
215
216%{msec_frac}: millisecond fraction
217
218%{usec_frac}: microsecond fraction
219
220              The extensions can not be combined  with  each  other  or  strf‐
221              time(3) in the same specification. Use multiple %{X}t specifica‐
222              tions instead.
223
224       %T     In client mode, time taken to serve the request, in seconds.  In
225              backend  mode, time from the request was sent to the entire body
226              had been received. This is equivalent to %{s}T.
227
228       %{X}T  In client mode, time taken to serve the request, in  the  format
229              specified by X.  In backend mode, time from the request was sent
230              to the entire body had been  received.  The  time  specification
231              format  can  be  one  of the following: s (same as %T), ms or us
232              (same as %D).
233
234       %U     The request URL without the query string. Defaults to '-' if not
235              known.
236
237       %u     Remote user from auth.
238
239       %{X}x  Extended variables.  Supported variables are:
240
241              Varnish:time_firstbyte
242                     Time  from  when  the request processing starts until the
243                     first byte is sent to the client, in seconds.  For  back‐
244                     end  mode:  Time from the request was sent to the backend
245                     to the entire header had been received.
246
247              Varnish:hitmiss
248                     One of the 'hit' or 'miss' strings, depending on  whether
249                     the request was a cache hit or miss. Pipe, pass and synth
250                     are considered misses.
251
252              Varnish:handling
253                     One of the  'hit',  'miss',  'pass',  'pipe'  or  'synth'
254                     strings indicating how the request was handled.
255
256              Varnish:side
257                     Backend  or  client  side. One of two values, 'b' or 'c',
258                     depending on where the request was made. In pure  backend
259                     or client mode, this field will be constant.
260
261              Varnish:vxid
262                     The VXID of the varnish transaction.
263
264              VCL_Log:key
265                     The value set by std.log("key:value") in VCL.
266
267              VSL:tag:record-prefix[field]
268                     The  value of the VSL entry for the given tag-record pre‐
269                     fix-field combination. Tag is mandatory, the other compo‐
270                     nents are optional.
271
272                     The record prefix will limit the matches to those records
273                     that have this prefix as the first  part  of  the  record
274                     content followed by a colon.
275
276                     The  field  will,  if  present, treat the log record as a
277                     white space separated list of fields, and  only  the  nth
278                     part  of the record will be matched against. Fields start
279                     counting at 1 and run up to 255.
280
281                     Defaults to '-' when the tag is not seen, the record pre‐
282                     fix  does  not  match or the field is out of bounds. If a
283                     tag appears multiple times in a single  transaction,  the
284                     first occurrence is used.
285

SIGNALS

287       • SIGHUP
288
289         Rotate  the  log  file (see -w option) in daemon mode, abort the loop
290         and die gracefully when running in the foreground.
291
292       • SIGUSR1
293
294         Flush any outstanding transactions.
295

NOTES

297       The %r formatter is equivalent to  "%m  http://%{Host}i%U%q  %H".  This
298       differs  from  apache's  %r behavior, equivalent to "%m %U%q %H".  Fur‐
299       thermore, when using the %r formatter, if the Host header appears  mul‐
300       tiple times in a single transaction, the first occurrence is used.
301

EXAMPLE

303       Log  the second field of the Begin record, corresponding to the VXID of
304       the parent transaction:
305
306          varnishncsa -F "%{VSL:Begin[2]}x"
307
308       Log the entire Timestamp record associated with the processing length:
309
310          varnishncsa -F "%{VSL:Timestamp:Process}x"
311
312       Log in JSON, using the -j flag to ensure that the output is valid  JSON
313       for all inputs:
314
315          varnishncsa -j -F '{"size": %b, "time": "%t", "ua": "%{User-Agent}i"}'
316

SEE ALSO

318       varnishd(1) varnishlog(1) varnishstat(1) vsl(7)
319

HISTORY

321       The  varnishncsa utility was developed by Poul-Henning Kamp in coopera‐
322       tion with Verdens Gang AS and Varnish Software AS. This manual page was
323       initially  written  by  Dag-Erling Smørgrav <des@des.no>, and later up‐
324       dated by Martin Blix Grydeland and Pål Hermunn Johansen.
325
327       This document is licensed under the same licence as Varnish itself. See
328       LICENCE for details.
329
330       • Copyright (c) 2006 Verdens Gang AS
331
332       • Copyright (c) 2006-2016 Varnish Software AS
333
334
335
336
337                                                                VARNISHNCSA(1)
Impressum