Splunk Search

Adding computed column in Chart by date

hyp3rf0x
Engager

Hi, I have a search below to compare previous 2 days Splunk usage, but I need additional column that computes the difference between 2 dates. How can we achieve this?

index=_internal source=*license_usage.log TERM(type=Usage) earliest=-2d@d latest=@d
| eval b=round(b/1024/1024/1024,2)

| bin span=1d _time | eval date=strftime(_time,"%d_%b")
| chart sum(b) AS GB over host by date

Labels (1)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

Try this query.  Usually, we use a simple eval to find the difference between two fields, but we can't do that here because the field names aren't known.

index=_internal source=*license_usage.log TERM(type=Usage) earliest=-2d@d latest=@d 
| eval b=round(b/1024/1024/1024+(random()%10),2) 
| bin span=1d _time 
| eval date=strftime(_time,"%d_%b") 
| chart sum(b) AS GB over host by date
| eval diff=0
| foreach *_* [ eval diff=if(diff==0,'<<FIELD>>',diff-'<<FIELD>>')]
---
If this reply helps you, Karma would be appreciated.

View solution in original post

0 Karma

hyp3rf0x
Engager

Wow.. this really helps and achieves what I need. Thank you @richgalloway , much appreciated.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Try this query.  Usually, we use a simple eval to find the difference between two fields, but we can't do that here because the field names aren't known.

index=_internal source=*license_usage.log TERM(type=Usage) earliest=-2d@d latest=@d 
| eval b=round(b/1024/1024/1024+(random()%10),2) 
| bin span=1d _time 
| eval date=strftime(_time,"%d_%b") 
| chart sum(b) AS GB over host by date
| eval diff=0
| foreach *_* [ eval diff=if(diff==0,'<<FIELD>>',diff-'<<FIELD>>')]
---
If this reply helps you, Karma would be appreciated.
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...