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!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...