Splunk Search

Problems with rounding

rgcox1
Communicator

Having difficulty with simple rounding.

 index=_internal  group=per_sourcetype_thruput | eval gb=round(kb/1048576, 2)| stats sum(gb) sum(kb) by series |sort -sum(gb) 

Incorrect GB in result:
series                      sum(gb)                sum(kb)
wineventlog:security 1.66                      4727905.487416

index=_internal  group=per_sourcetype_thruput | eval gb=kb/1048576| stats sum(gb) sum(kb) by series |sort -sum(gb) 

Correct GB in result without rounding:
series                      sum(gb)                sum(kb)
wineventlog:security 4.5088820335775   4727905.487416

Have tried various versions of the base formula:
gb=round(kb/104856)
gb=round((kb/1024/1024), 2)
gb=round(((kb/1024)/1024), 2)
gb=round(kb/1024/1024)

But nothing works. What am I doing wrong?

Tags (1)
0 Karma
1 Solution

gkanapathy
Splunk Employee
Splunk Employee

If you round before summing up the values, you round off most of it before you can actually add it up. Most of the kb values are small. If you divide any number less than 10,000 by 1,000,000 (or 1,048,576) and round to 2 places, it comes out to zero, so you end up adding up a whole bunch of zeros.

The solution is to round after you sum, e.g.:

index=_internal group=per_sourcetype_thruput
| stats sum(kb) as sum_kb by series
| eval sum_gb=round(sum_kb/1048576,2)

View solution in original post

ashishganger
New Member

I think you need to sum the data in KB by Host rather than series. Each host has multiple sources and source types. It would be better to monitor the data throughput per host then series. Use the below search query:

index=_internal group=per_sourcetype_thruput | stats sum(kb) as DataKB, avg(kbps) as AVG-KBPS by host | eval DataGB=round(DataKB/1048576,2) | sort DataGB

0 Karma

ashishganger
New Member

Also mind that there should be no space while using the round function 🙂

0 Karma

assaftoval
New Member

The solution above it not working..

0 Karma

gkanapathy
Splunk Employee
Splunk Employee

If you round before summing up the values, you round off most of it before you can actually add it up. Most of the kb values are small. If you divide any number less than 10,000 by 1,000,000 (or 1,048,576) and round to 2 places, it comes out to zero, so you end up adding up a whole bunch of zeros.

The solution is to round after you sum, e.g.:

index=_internal group=per_sourcetype_thruput
| stats sum(kb) as sum_kb by series
| eval sum_gb=round(sum_kb/1048576,2)

rishiaggarwal
Explorer

I downvoted this post because solution is not working

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!

Observability Simplified: Combining User Experience, Application Performance & ...

Tech Talk Observability Simplified: Combining User Experience, Application Performance & Network ...

Event Series May & June: From Network Visibility to Service Intelligence

Unifying the Network: Moving from Alert Noise to Service Intelligence with Splunk ITSI In today’s hybrid ...

Global Splunk User Group Events: May + June 2026

Your Splunk Community Awaits: Discover Upcoming User Group Events Worldwide    Staying ahead in the fast-paced ...