Configuration Examples

This section provides examples for a wide range of logging scenarios. While not exhaustive of all possibilities (Traffic Server logging is quite flexible), these entries should hopefully get most administrators headed onto the right path.

Unless otherwise noted, the example configurations here are to be applied in logging.config.

Online Event Log Builder

If you need any assistance building your event log, you can try out our online log builder. This is a work in progress, so any comments, critique or suggestions are most welcome.

Emulating Other HTTP Server Formats

Netscape Common

The following figure shows a sample log entry in a Netscape Common log file.

Sample Netscape Common log entry

The numbered sections correspond to the following log fields in Traffic Server:

No.FieldDescription
1chiThe IP address of the client’s host machine.
2This hyphen (-) is always present in Netscape log entries.
3caunThe authenticated client username. A hyphen (-) means no authentication was required.
4cqtnThe date and time of the client request, enclosed in brackets.
5cqtxThe request line, enclosed in quotes.
6psscThe proxy response status code (HTTP reply code).
7psclThe length of the Traffic Server response to the client in bytes.

To recreate this as a log format in logging.config you would define the following format object:

  1. common = format {
  2. Format = '%<chi> - %<caun> [%<cqtn>] "%<cqtx>" %<pssc> %<pscl>'
  3. }

Netscape Extended

The following figure shows a sample log entry in a Netscape Extended log file.

Sample Netscape Extended log entry

In addition to fields 1-7 from the Netscape Common log format, the Extended format adds the following fields:

No.FieldDescription
8ssscThe origin server response status code.
9sshlThe server response transfer length; the body length in the origin server response to Traffic Server, in bytes.
10cqclThe client request transfer length; the body length in the client request to Traffic Server, in bytes.
11pqclThe proxy request transfer length; the body length in the Traffic Server request to the origin server.
12cqhlThe client request header length; the header length in the client request to Traffic Server.
13pshlThe proxy response header length; the header length in the Traffic Server response to the client.
14pqhlThe proxy request header length; the header length in Traffic Server request to the origin server.
15sshlThe server response header length; the header length in the origin server response to Traffic Server.
16ttsThe time Traffic Server spent processing the client request; the number of seconds between the time that the client established the connection with Traffic Server and the time that Traffic Server sent the last byte of the response back to the client.

To recreate this as a log format in logging.config you would define the following format object:

  1. extended = format {
  2. Format = '%<chi> - %<caun> [%<cqtn>] "%<cqtx>" %<pssc> %<pscl> %<sssc> %<sscl> %<cqcl> %<pqcl> %<cqhl> %<pshl> %<pqhl> %<sshl> %<tts>'
  3. }

Netscape Extended-2

The following figure shows a sample log entry in a Netscape Extended2 log file.

Sample Netscape Extended-2 log entry

In addition to fields 1-16 from the Netscape Common and Netscape Extended log formats above, the Extended-2 format adds the following fields:

No.FieldDescription
17phrThe proxy hierarchy route; the route Traffic Server used to retrieve the object.
18cfscThe client finish status code: FIN if the client request completed successfully or INTR if the client request was interrupted.
19pfscThe proxy finish status code: FIN if the Traffic Server request to the origin server completed successfully or INTR if the request was interrupted.
20crcThe cache result code; how the Traffic Server cache responded to the request: HIT, MISS, and so on. Cache result codes are listed in Cache Result Codes.

To recreate this as a log format in logging.config you would define the following format object:

  1. extended2 = format {
  2. Format = '%<chi> - %<caun> [%<cqtn>] "%<cqtx>" %<pssc> %<pscl> %<sssc> %<sscl> %<cqcl> %<pqcl> %<cqhl> %<pshl> %<pqhl> %<sshl> %<tts> %<phr> %<cfsc> %<pfsc> %<crc>'
  3. }

Squid

The following figure shows a sample log entry in a Squid log file.

Sample Squid log entry

The numbered sections correspond to the following log fields in Traffic Server:

No.FieldDescription
1cqtqThe client request timestamp in Squid format. The time of the client request in seconds since January 1, 1970 UTC (with millisecond resolution).
2ttmsThe time Traffic Server spent processing the client request. The number of milliseconds between the time the client established the connection with Traffic Server and the time Traffic Server sent the last byte of the response back to the client.
3chiThe IP address of the client’s host machine.
4crc/psscThe cache result code; how the cache responded to the request: HIT, MISS, and so on. Cache result codes are described in Logging Cache Results. The proxy response status code (HTTP response status code from Traffic Server to client).
5psqlThe length of the Traffic Server response to the client in bytes, including headers and content.
6cqhmThe client request method: GET, POST, and so on.
7caucThe client request canonical URL; blanks and other characters that might not be parsed by log analysis tools are replaced by escape sequences. The escape sequence is a percentage sign followed by the ASCII code number of the replaced character in hex.
8caunThe username of the authenticated client. A hyphen (-) means that no authentication was required.
9phr/pqsnThe proxy hierarchy route. The route Traffic Server used to retrieve the object.
10psctThe proxy response content type. The object content type taken from the Traffic Server response header.

To recreate this as a log format in logging.config you would define the following format object:

  1. squid = format {
  2. Format = '%<cqtq> %<ttms> %<chi> %<crc>/%<pssc> %<psql> %<cqhm> %<cquc> %<caun> %<phr>/%<pqsn> %<psct>'
  3. }

Separating Logs by Origin

The default log_hosts.config file is located in the Traffic Server config directory. To record HTTP transactions for different origin servers in separate log files, you must specify the hostname of each origin server on a separate line in log_hosts.config. For example, if you specify the keyword sports, then Traffic Server records all HTTP transactions from sports.yahoo.com and www.foxsports.com in a log file called squid-sports.log (if the Squid format is enabled).

Important

If Traffic Server is clustered and you enable log file collation, then you should use the same log_hosts.config file on every Traffic Server node in the cluster.

To edit the log hosts list:

  1. Enter the hostname of each origin server on a separate line in log_hosts.config.

    1. webserver1
    2. webserver2
    3. webserver3
  2. Run the command traffic_ctl config reload to apply the changes.

Hourly Rotated Squid Proxy Logs

The following example demonstrates the creation of a Squid-compatible log format, which is then applied to a log object containing an hourly rotation policy.

  1. squid = format {
  2. Format = '%<cqtq> %<ttms> %<chi> %<crc>/%<pssc> %<psql> %<cqhm> %<cquc> %<caun> %<phr>/%<pqsn> %<psct>'
  3. }
  4. log.ascii {
  5. Format = squid,
  6. Filename = 'squid',
  7. RollingEnabled = 1,
  8. RollingIntervalSec = 3600,
  9. RollingOffsetHr = 0
  10. }

Summarizing Number of Requests and Total Bytes Sent Every 10 Seconds

The following example format generates one entry every 10 seconds. Each entry contains the timestamp of the last entry of the interval, a count of the number of entries seen within that 10-second interval, and the sum of all bytes sent to clients:

  1. mysummary = format {
  2. Format = "%<LAST(cqts)> : %<COUNT(*)> : %<SUM(psql)>",
  3. Interval = "10"
  4. }

Dual Output to Compact Binary Logs and ASCII Pipes

This example demonstrates logging the same event data to multiple locations, in a hypothetical scenario where we may wish to keep a compact form of our logs available for archival purposes, while performing live log analysis on a stream of the event data.

  1. ourformat = format {
  2. Format = '%<chi> - %<caun> [%<cqtn>] "%<cqtx>" %<pssc> %<pscl>'
  3. }
  4. log.binary {
  5. Format = ourformat,
  6. Filename = 'archived_events'
  7. }
  8. log.pipe {
  9. Format = ourformat,
  10. Filename = 'streaming_log'
  11. }

Filtering Events to ASCII Pipe for Alerting

This example illustrates a situation in which our Traffic Server cache contains canary objects, which upon their access we want an external alerting system to fire off all sorts of alarms. To accomplish this, we demonstrate the use of a filter object that matches events against these particular canaries and emits log data for them to a UNIX pipe that the alerting software can constantly read from.

  1. canaryformat = format {
  2. Format = '%<chi> - %<caun> [%<cqtn>] "%<cqtx>" %<pssc> %<pscl>'
  3. }
  4. canaryfilter = filter.accept('cqup MATCH "/nightmare/scenario/dont/touch"')
  5. log.pipe {
  6. Format = canaryformat,
  7. Filters = [ canaryfilter ],
  8. Filename = 'alerting_canaries'
  9. }

Summarizing Origin Responses by Hour

This example demonstrates a simple use of aggregation operators to produce an hourly event line reporting on the total number of requests made to origin servers (where we assume that any cache result code without the string HIT in it signals origin access), as well as the average time it took to fulfill the request to clients during that hour.

  1. originrepformat = format {
  2. Format = '%<FIRST(cqtq)> %<COUNT(*)> %<AVERAGE(ttms)>',
  3. Interval = 3600
  4. }
  5. originfilter = filter.reject('crc CONTAINS "HIT"')
  6. log.ascii {
  7. Format = originrepformat,
  8. Filters = [ originfilter ],
  9. Filename = 'origin_access_summary'
  10. }