Splunk Search

Computing column differences

ldnail_at_TI
Path Finder

This is result of a query that reflects license consumption by day

Index3/2/20213/3/20213/4/20213/5/20213/6/20213/7/20213/8/2021
index010.0180060.0181280.0180650.0180350.0179440.0179850.018042
index020.0149850.0094440.0548030.0104010.0068070.0050350.008998
index033.4689193.6742773.7865653.1331932.1510942.5481734.531934
index040.0849110.0826370.0907850.0624040.0127950.0311980.084129

 

I'm try to compute a daily difference so we can easily spot variance/trend with the result looking something like this:

Index3/2/20213/3/2021dif day 13/4/2021dif day 23/5/2021dif day 33/6/2021dif day 43/7/2021dif day 53/8/2021dif day 6
index010.0180060.018128-0.000120.0180650.000060.0180350.000030.0179440.000090.017985-0.000040.018042-0.00006
index020.0149850.0094440.0055410.054803-0.045360.0104010.044400.0068070.003590.0050350.001770.008998-0.00396
index033.4689193.674277-0.205363.786565-0.112293.1331930.653372.1510940.982102.548173-0.397084.531934-1.98376
index040.0849110.0826370.0022740.090785-0.008150.0624040.028380.0127950.049610.031198-0.018400.084129-0.05293

 

The query I started from is below & I've tried 20 ways to Sunday get a difference column, but no joy

index=_internal source=*license_usage.log* type=Usage earliest=-7d@d latest=@d host=licenseserver
| eval GB=round(b/1024/1024/1024,6)
| bucket span=1d _time
| eval Time=strftime(_time,"%m/%d/%y")
| chart sum(GB) AS volume_GB over Time by idx limit=0
| transpose 0 column_name=Index header_field=Time

 

I'm not married to chart or transpose, its just where it all started.

 

Any suggestions?

Labels (2)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

index=_internal source=*license_usage.log* type=Usage earliest=-7d@d latest=@d host=licenseserver
| eval GB=round(b/1024/1024/1024,6)
| bucket span=1d _time
| stats sum(GB) as volume_GB by idx _time
| streamstats window=2 list(volume_GB) as diff by idx
| eval diff=tonumber(mvindex(diff,0)) - tonumber(mvindex(diff,1))
| eval volume_GB=mvappend(volume_GB,diff)
| xyseries idx _time volume_GB
| foreach * [ eval <<FIELD>>_diff=if(mvcount('<<FIELD>>') > 1, mvindex('<<FIELD>>', 1), null) | eval <<FIELD>>=mvindex('<<FIELD>>',0) ]
| transpose 0 header_field=idx
| eval column=if(match(column,"_"),strftime(mvindex(split(column,"_"),0),"%m/%d/%Y diff"),strftime(column,"%m/%d/%Y"))
| transpose 0 header_field=column

View solution in original post

ldnail_at_TI
Path Finder

that did the trick... thanks a bunch.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

index=_internal source=*license_usage.log* type=Usage earliest=-7d@d latest=@d host=licenseserver
| eval GB=round(b/1024/1024/1024,6)
| bucket span=1d _time
| stats sum(GB) as volume_GB by idx _time
| streamstats window=2 list(volume_GB) as diff by idx
| eval diff=tonumber(mvindex(diff,0)) - tonumber(mvindex(diff,1))
| eval volume_GB=mvappend(volume_GB,diff)
| xyseries idx _time volume_GB
| foreach * [ eval <<FIELD>>_diff=if(mvcount('<<FIELD>>') > 1, mvindex('<<FIELD>>', 1), null) | eval <<FIELD>>=mvindex('<<FIELD>>',0) ]
| transpose 0 header_field=idx
| eval column=if(match(column,"_"),strftime(mvindex(split(column,"_"),0),"%m/%d/%Y diff"),strftime(column,"%m/%d/%Y"))
| transpose 0 header_field=column
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...