Splunk Search

How to find total byte count?

DEAD_BEEF
Builder

I am looking through my firewall logs and would like to find the total byte count between a single source and a single destination. There are multiple byte count values over the 2-hour search duration and I would simply like to see a table listing the source, destination, and total byte count.

I've tried stats and eventstats but nothing seems to work right.

Current query:

index=fw_log src_ip=1.2.3.4 dst_ip=5.6.7.8 | eventstats sum(bytes) AS "Total Bytes" by src_ip | table src_ip,dst_ip,"Total Bytes"

What I want is:

    src_ip     dst_ip   Total Bytes
    1.2.3.4    5.6.7.8  94782161

What I'm getting is:

    src_ip     dst_ip   Total Bytes
    1.2.3.4    5.6.7.8  37473882
    1.2.3.4    5.6.7.8  37473882
    1.2.3.4    5.6.7.8  37473882
    1.2.3.4    5.6.7.8  37473882
0 Karma
1 Solution

sideview
SplunkTrust
SplunkTrust
index=fw_log src_ip=1.2.3.4 dst_ip=5.6.7.8 | stats sum(bytes) AS "Total Bytes" by src_ip dst_ip

That will give you the one row. You don't want to use eventstats here, but rather its bigger brother stats. Stats with a "by foo" or "by foo bar", will output one row for every unique combination of the "by" fields. Eventstats however, will output pretty much exactly the same rows that it received from the prior command, except that it will have tacked on a couple extra fields that it computed in various ways.

If you want to see all pairs of src_ip and dst_ip, that would be

index=fw_log  | stats sum(bytes) AS "Total Bytes" by src_ip dst_ip

View solution in original post

sideview
SplunkTrust
SplunkTrust
index=fw_log src_ip=1.2.3.4 dst_ip=5.6.7.8 | stats sum(bytes) AS "Total Bytes" by src_ip dst_ip

That will give you the one row. You don't want to use eventstats here, but rather its bigger brother stats. Stats with a "by foo" or "by foo bar", will output one row for every unique combination of the "by" fields. Eventstats however, will output pretty much exactly the same rows that it received from the prior command, except that it will have tacked on a couple extra fields that it computed in various ways.

If you want to see all pairs of src_ip and dst_ip, that would be

index=fw_log  | stats sum(bytes) AS "Total Bytes" by src_ip dst_ip

DEAD_BEEF
Builder

Not sure how I missed this, thank you!

0 Karma

velthias
New Member

How do you convert the Total Bytes into mb or gb from this search?

0 Karma

to4kawa
Ultra Champion
index=fw_log  
| stats sum(bytes) AS Total_Bytes
sum(eval(round(bytes/1024))) AS Total_Bytes_MB
sum(eval(round(bytes/1024/1024))) AS "otal_Bytes_GB by src_ip dst_ip

OR

 index=fw_log  
| stats sum(bytes) AS Total_Bytes by src_ip dst_ip
| eval Total_Bytes_MB= round(Total_Bytes/1024)
| eval Total_Bytes_GB=round(Total_Bytes/1024/1024)
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...

How to find the worst searches in your Splunk environment and how to fix them

Everyone knows Splunk is a powerful platform for running searches and doing data analytics. Your ...

Share Your Feedback: On Admin Config Service (ACS)!

Help Us Build a Better Admin Config Service Experience (ACS)   We Want Your Feedback on Admin Config Service ...