Splunk Search

How to search Apache access_log data to find bandwidth usage as total number of bytes?

spunkyg
Engager

I can pull the Apache access_log into Splunk, but I can't figure out now to write a search that will give the total number of bytes that Apache sends to browsers over a period of time. Anyone have one to share?

Thanks.

0 Karma
1 Solution

wongea
Explorer

Hope this helps you.

Apache access_log sample:
127.0.0.1 - - [22/Jun/2016:15:19:48 -0700] "GET /uri/sample/path HTTP/1.1" 200 20 15515

I created an extracted field called apache_byte_size on the second column from the very right. In this example the number of bytes = 20. I change the search to the time frame that I want.

Sample Splunk search:
index=apache host=hostname sourcetype=access_log | stats sum(apache_byte_size)

View solution in original post

wongea
Explorer

Hope this helps you.

Apache access_log sample:
127.0.0.1 - - [22/Jun/2016:15:19:48 -0700] "GET /uri/sample/path HTTP/1.1" 200 20 15515

I created an extracted field called apache_byte_size on the second column from the very right. In this example the number of bytes = 20. I change the search to the time frame that I want.

Sample Splunk search:
index=apache host=hostname sourcetype=access_log | stats sum(apache_byte_size)

spunkyg
Engager

Based on your answer, I created the following search that works in our load-balanced environment. Thank you!

source="/var/log/httpd/access_log" host="webprod-1.example.com" OR host="webprod-2.example.com" | stats sum(bytes)

0 Karma

sk314
Builder

what's the format of your logs? can you show some sample events with fields?

0 Karma

spunkyg
Engager

I think we are using the combined log format. In the sample entries below, empty fields are indicated by hyphens. The number of bytes sent to the client browser is indicated in the seventh field from the left. In the first sample, the value for bytes is 12. In the second sample, it is 8369.

10.107.88.13 - - [22/Jun/2016:03:43:24 -0500] "GET /" 200 12 "-" "-" - - - "-" "-" libweb-devel-cluster.example.com 80 SSL-off 2507 49683 -

68.180.229.190 - - [22/Jun/2016:04:22:49 -0500] "GET /tejanovoices/interview.php?cmasno=113 HTTP/1.1" 200 8369 "-" "Mozilla/5.0 (c
ompatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)" - - - "-" "library.example.com" library.example.com 80 SSL-off 4447
1 44226 +

0 Karma
Get Updates on the Splunk Community!

What You Read The Most: Splunk Lantern’s Most Popular Articles!

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...

Index This | What goes away as soon as you talk about it?

May 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this month’s ...