Splunk Search

How to Split Group by Values?

user33
Path Finder

Hello, I am very new to Splunk. I am wondering how to split these two values into separate rows. The "API_Name" values are grouped but I need them separated by date. Any assistance is appreciated!

SPL:

 

 

index=...

| fields source, timestamp, a_timestamp, transaction_id, a_session_id, a_api_name, api_name, API_ID
| convert timeformat="%Y-%m-%d" ctime(_time) AS date
| eval sessionID=coalesce(a_session_id, transaction_id)
| stats values(date) as date dc(source) as cnt values(timestamp) as start_time values(a_timestamp) as end_time values(api_name) as API_Name by sessionID | where cnt>1
| eval start=strptime(start_time, "%F %T.%Q")
| eval end=strptime(end_time, "%FT%T.%Q")
| eval duration(ms)=abs((end-start)*1000)
| stats count, 
perc95(duration(ms)) as 95thPercentileRespTime(ms) values(API_Name) as API_Name by date

 

 

Splunk1.PNG

Labels (2)
0 Karma
1 Solution

yuanliu
SplunkTrust
SplunkTrust

To group by date and api_name, you put both in groupby clause, right?

index=...

| fields source, timestamp, a_timestamp, transaction_id, a_session_id, a_api_name, api_name, API_ID
| convert timeformat="%Y-%m-%d" ctime(_time) AS date
| eval sessionID=coalesce(a_session_id, transaction_id)
| stats values(date) as date dc(source) as cnt values(timestamp) as start_time values(a_timestamp) as end_time values(api_name) as API_Name by sessionID | where cnt>1
| eval start=strptime(start_time, "%F %T.%Q")
| eval end=strptime(end_time, "%FT%T.%Q")
| eval duration(ms)=abs((end-start)*1000)
| stats count, perc95(duration(ms)) as 95thPercentileRespTime(ms) by date API_Name

 Does this give you what you expect?

View solution in original post

yuanliu
SplunkTrust
SplunkTrust

Your screenshot shows two values under "date", meaning that your last stats command is working to separate values by date.  Can you explain why this is not meeting your requirement?  In other words, what exact output are you expecting?

0 Karma

user33
Path Finder

Hello, I am looking to separate by date and API_Name. I am looking for something like the below. I need a count and 95thPercentileRespTime(ms) specifically for accountstatements-v1 and a count and 95thPercentileRespTime(ms) specifically for Realtime_Image_Access_Service_V2 organized by date.

datecount95thPercentileRespTime(ms)API_Name
2022-11-05xxaccountstatements-v1
2022-11-06xxRealtime_Image_Access_Service_V2
2022-11-06xxaccountstatements-v1
0 Karma

yuanliu
SplunkTrust
SplunkTrust

To group by date and api_name, you put both in groupby clause, right?

index=...

| fields source, timestamp, a_timestamp, transaction_id, a_session_id, a_api_name, api_name, API_ID
| convert timeformat="%Y-%m-%d" ctime(_time) AS date
| eval sessionID=coalesce(a_session_id, transaction_id)
| stats values(date) as date dc(source) as cnt values(timestamp) as start_time values(a_timestamp) as end_time values(api_name) as API_Name by sessionID | where cnt>1
| eval start=strptime(start_time, "%F %T.%Q")
| eval end=strptime(end_time, "%FT%T.%Q")
| eval duration(ms)=abs((end-start)*1000)
| stats count, perc95(duration(ms)) as 95thPercentileRespTime(ms) by date API_Name

 Does this give you what you expect?

user33
Path Finder

I get an error even if I use a comma between: date, API_Name.

0 Karma

user33
Path Finder

It does not unfortunately. I get errors:

user33_0-1667769954783.png

 

0 Karma

yuanliu
SplunkTrust
SplunkTrust

You didn't try the command in my post; it doesn't contain values(API_Name).  (Whether you use comma or not is immaterial.)

0 Karma

user33
Path Finder

Apologies! You are correct. I had a typo. This works perfectly! Thank you very much yuanliu!!

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!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...