Splunk Search

New User Looking for help comparing values

chorn3567
Engager

Hi All! First post, super new user to Splunk. 

Have a search that i modified from a one a team member previously created, im trying to take the output of ClientVersion and compare the 6wkAvg count to the Today count for same timespan and see what the percentage -/+ is. Ultimately building towards alerting when below a certain threshold. 

| fields _time ClientVersion 
| eval DoW=strftime(_time, "%A")
| eval TodayDoW=strftime(now(), "%A")
| where DoW=TodayDoW
| search ClientVersion=FAPI*
| eval ClientVersion=if((like("ClientVersion=FAPI*","%OR%") OR false()) AND false(), "Combined", ClientVersion)
| bin _time span=5m 
| eval tempTime=strftime(_time,"%m/%d")
| where (tempTime!="null") 
| eval tempTime=if(true() AND _time < relative_time(now(), "@d"), "6wkAvg", "Today")
| stats count by ClientVersion _time tempTime
| eval _time=round(strptime(strftime(now(),"%Y-%m-%d").strftime(_time,"%H:%M:%S"),"%Y-%m-%d%H:%M:%S"),0)
| stats avg(count) as count by ClientVersion _time tempTime
| eval ClientVersion=ClientVersion."-".tempTime 
| eval count=round(count,0)



chorn3567_1-1719424980247.png

 

Labels (3)
0 Karma
1 Solution

yuanliu
SplunkTrust
SplunkTrust

Thank you for updating to text as @gcusello suggested.  It would be better if you can illustrate mock data in text tables as well.

It is hard to see how ClientVersion in 6wkAvg could be useful, but I'll just ignore this point.  Because the only numeric field is Count, I assume that you want percentage change on this field.  Splunk provides a convenient command xyseries to swap fields into row values.  You can do something like this:

 

| xyseries _time tempTime ClientVersion Count
| eval percentChange = round(('Count: Today' - 'Count: 6wkAvg') / 'Count: 6wkAvg' * 100, 2)

 

Your mock data will give

_timeClientVersion: 6wkAvgClientVersion: TodayCount: 6wkAvgCount: TodaypercentChange
2024-06-26 00:00:00FAPI-6wkAvgFAPI-today1582212334.20
2024-06-26 00:05:00FAPI-6wkAvgFAPI-today1491192529.11
2024-06-26 00:10:00FAPI-6wkAvgFAPI-today1888286751.85
2024-06-26 00:15:00FAPI-6wkAvgFAPI-today1983259330.76
2024-06-26 00:20:00FAPI-6wkAvgFAPI-today2882329114.19

Is this something you are looking for?  Here is an emulation you can play with and compare with real data

 

| makeresults format=csv data="ClientVersion,        _time, tempTime, Count
FAPI-6wkAvg,    2024-06-26 00:00:00, 6wkAvg, 1582
FAPI-today,    2024-06-26 00:00:00, Today, 2123
FAPI-6wkAvg,    2024-06-26 00:05:00, 6wkAvg, 1491
FAPI-today,    2024-06-26 00:05:00, Today, 1925
FAPI-6wkAvg,    2024-06-26 00:10:00, 6wkAvg, 1888
FAPI-today,    2024-06-26 00:10:00, Today, 2867
FAPI-6wkAvg,    2024-06-26 00:15:00, 6wkAvg, 1983
FAPI-today,    2024-06-26 00:15:00, Today, 2593
FAPI-6wkAvg,    2024-06-26 00:20:00, 6wkAvg, 2485
FAPI-today,    2024-06-26 00:20:00, Today, 2939
FAPI-6wkAvg,    2024-06-26 00:20:00, 6wkAvg, 2882
FAPI-today,    2024-06-26 00:20:00, Today, 3291"
``` the above emulates
...
| stats avg(count) as count by ClientVersion _time tempTime
| eval ClientVersion=ClientVersion."-".tempTime 
| eval count=round(count,0)
```

 

 

View solution in original post

Tags (1)
0 Karma

yuanliu
SplunkTrust
SplunkTrust

Thank you for updating to text as @gcusello suggested.  It would be better if you can illustrate mock data in text tables as well.

It is hard to see how ClientVersion in 6wkAvg could be useful, but I'll just ignore this point.  Because the only numeric field is Count, I assume that you want percentage change on this field.  Splunk provides a convenient command xyseries to swap fields into row values.  You can do something like this:

 

| xyseries _time tempTime ClientVersion Count
| eval percentChange = round(('Count: Today' - 'Count: 6wkAvg') / 'Count: 6wkAvg' * 100, 2)

 

Your mock data will give

_timeClientVersion: 6wkAvgClientVersion: TodayCount: 6wkAvgCount: TodaypercentChange
2024-06-26 00:00:00FAPI-6wkAvgFAPI-today1582212334.20
2024-06-26 00:05:00FAPI-6wkAvgFAPI-today1491192529.11
2024-06-26 00:10:00FAPI-6wkAvgFAPI-today1888286751.85
2024-06-26 00:15:00FAPI-6wkAvgFAPI-today1983259330.76
2024-06-26 00:20:00FAPI-6wkAvgFAPI-today2882329114.19

Is this something you are looking for?  Here is an emulation you can play with and compare with real data

 

| makeresults format=csv data="ClientVersion,        _time, tempTime, Count
FAPI-6wkAvg,    2024-06-26 00:00:00, 6wkAvg, 1582
FAPI-today,    2024-06-26 00:00:00, Today, 2123
FAPI-6wkAvg,    2024-06-26 00:05:00, 6wkAvg, 1491
FAPI-today,    2024-06-26 00:05:00, Today, 1925
FAPI-6wkAvg,    2024-06-26 00:10:00, 6wkAvg, 1888
FAPI-today,    2024-06-26 00:10:00, Today, 2867
FAPI-6wkAvg,    2024-06-26 00:15:00, 6wkAvg, 1983
FAPI-today,    2024-06-26 00:15:00, Today, 2593
FAPI-6wkAvg,    2024-06-26 00:20:00, 6wkAvg, 2485
FAPI-today,    2024-06-26 00:20:00, Today, 2939
FAPI-6wkAvg,    2024-06-26 00:20:00, 6wkAvg, 2882
FAPI-today,    2024-06-26 00:20:00, Today, 3291"
``` the above emulates
...
| stats avg(count) as count by ClientVersion _time tempTime
| eval ClientVersion=ClientVersion."-".tempTime 
| eval count=round(count,0)
```

 

 

Tags (1)
0 Karma

chorn3567
Engager

simple as that, thank you! worked for me. 

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @chorn3567 ,

please share your search in text mode (using theInsert/Edit code sample button), otherwise it's realy difficoult to help you.

Ciao.

Giuseppe

0 Karma

chorn3567
Engager

updated post, thank you for the tip! 

 

0 Karma
Get Updates on the Splunk Community!

Splunk Enterprise Security(ES) 7.3 is approaching the end of support. Get ready for ...

Hi friends!    At Splunk, your product success is our top priority. With Enterprise Security (ES), we're here ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk, and empower your SOC to reach new heights! Duration: 1 hour  Prepare to ...

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...