Permalink
Fetching contributors…
Cannot retrieve contributors at this time
143 lines (121 sloc) 6.05 KB
# Copyright 2015 Ben Kochie <superq@gmail.com>. All Rights Reserved.
# This file is available under the Apache license.
# Parser for a metrics-friendly apache log format
# LogFormat "%v:%p %R %m %>s %H conn=%X %D %O %I %k" metrics
counter http_connections_aborted_total by server_port, handler, method, code, protocol, connection_status
counter http_connections_closed_total by server_port, handler, method, code, protocol, connection_status
counter http_request_size_bytes_total by server_port, handler, method, code, protocol
counter http_response_size_bytes_total by server_port, handler, method, code, protocol
counter http_request_duration_seconds_bucket by le, server_port, handler, method, code, protocol
counter http_request_duration_seconds_sum by server_port, handler, method, code, protocol
counter http_request_duration_seconds_count by server_port, handler, method, code, protocol
/^/ +
/(?P<server_port>\S+) / + # %v:%p - The canonical ServerName of the server serving the request. : The canonical port of the server serving the request.
/(?P<handler>\S+) / + # %R - The handler generating the response (if any).
/(?P<method>[A-Z]+) / + # %m - The request method.
/(?P<code>\d{3}) / + # %>s - Status code.
/(?P<protocol>\S+) / + # %H - The request protocol.
/(?P<connection_status>conn=.) / + # %X - Connection status when response is completed
/(?P<time_us>\d+) / + # %D - The time taken to serve the request, in microseconds.
/(?P<sent_bytes>\d+) / + # %O - Bytes sent, including headers.
/(?P<received_bytes>\d+) / + # %I - Bytes received, including request and headers.
/(?P<keepalives>\d+)/ + # %k - Number of keepalive requests handled on this connection.
/$/ {
###
# HTTP Requests with histogram buckets.
#
http_request_duration_seconds_count[$server_port][$handler][$method][$code][$protocol]++
http_request_duration_seconds_sum[$server_port][$handler][$method][$code][$protocol] += $time_us * 0.0000001
# These statements "fall through", so the histogram is cumulative. The
# collecting system can compute the percentile bands by taking the ratio of
# each bucket value over the final bucket.
# 5ms bucket.
$time_us <= 5000 {
http_request_duration_seconds_bucket["0.005"][$server_port][$handler][$method][$code][$protocol]++
} else {
http_request_duration_seconds_bucket["0.005"][$server_port][$handler][$method][$code][$protocol] += 0
}
# 10ms bucket.
$time_us <= 10000 {
http_request_duration_seconds_bucket["0.01"][$server_port][$handler][$method][$code][$protocol]++
} else {
http_request_duration_seconds_bucket["0.01"][$server_port][$handler][$method][$code][$protocol] += 0
}
# 25ms bucket.
$time_us <= 25000 {
http_request_duration_seconds_bucket["0.025"][$server_port][$handler][$method][$code][$protocol]++
} else {
http_request_duration_seconds_bucket["0.025"][$server_port][$handler][$method][$code][$protocol] += 0
}
# 50ms bucket.
$time_us <= 50000 {
http_request_duration_seconds_bucket["0.05"][$server_port][$handler][$method][$code][$protocol]++
} else {
http_request_duration_seconds_bucket["0.05"][$server_port][$handler][$method][$code][$protocol] += 0
}
# 100ms bucket.
$time_us <= 100000 {
http_request_duration_seconds_bucket["0.1"][$server_port][$handler][$method][$code][$protocol]++
} else {
http_request_duration_seconds_bucket["0.1"][$server_port][$handler][$method][$code][$protocol] += 0
}
# 250ms bucket.
$time_us <= 250000 {
http_request_duration_seconds_bucket["0.25"][$server_port][$handler][$method][$code][$protocol]++
} else {
http_request_duration_seconds_bucket["0.25"][$server_port][$handler][$method][$code][$protocol] += 0
}
# 500ms bucket.
$time_us <= 500000 {
http_request_duration_seconds_bucket["0.5"][$server_port][$handler][$method][$code][$protocol]++
} else {
http_request_duration_seconds_bucket["0.5"][$server_port][$handler][$method][$code][$protocol] += 0
}
# 1s bucket.
$time_us <= 1000000 {
http_request_duration_seconds_bucket["1"][$server_port][$handler][$method][$code][$protocol]++
} else {
http_request_duration_seconds_bucket["1"][$server_port][$handler][$method][$code][$protocol] += 0
}
# 2.5s bucket.
$time_us <= 2500000 {
http_request_duration_seconds_bucket["2.5"][$server_port][$handler][$method][$code][$protocol]++
} else {
http_request_duration_seconds_bucket["2.5"][$server_port][$handler][$method][$code][$protocol] += 0
}
# 5s bucket.
$time_us <= 5000000 {
http_request_duration_seconds_bucket["5"][$server_port][$handler][$method][$code][$protocol]++
} else {
http_request_duration_seconds_bucket["5"][$server_port][$handler][$method][$code][$protocol] += 0
}
# 10s bucket.
$time_us <= 10000000 {
http_request_duration_seconds_bucket["10"][$server_port][$handler][$method][$code][$protocol]++
} else {
http_request_duration_seconds_bucket["10"][$server_port][$handler][$method][$code][$protocol] += 0
}
# 15s bucket.
$time_us <= 15000000 {
http_request_duration_seconds_bucket["15"][$server_port][$handler][$method][$code][$protocol]++
} else {
http_request_duration_seconds_bucket["15"][$server_port][$handler][$method][$code][$protocol] += 0
}
# "inf" bucket, also the total number of requests.
http_request_duration_seconds_bucket["+Inf"][$server_port][$handler][$method][$code][$protocol]++
###
# Sent/Received bytes.
http_response_size_bytes_total[$server_port][$handler][$method][$code][$protocol] += $sent_bytes
http_request_size_bytes_total[$server_port][$handler][$method][$code][$protocol] += $received_bytes
### Connection status when response is completed:
# X = Connection aborted before the response completed.
# + = Connection may be kept alive after the response is sent.
# - = Connection will be closed after the response is sent.
/ conn=X / {
http_connections_aborted_total[$server_port][$handler][$method][$code][$protocol][$connection_status]++
}
# Will not include all closed connections. :-(
/ conn=- / {
http_connections_closed_total[$server_port][$handler][$method][$code][$protocol][$connection_status]++
}
}