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
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!

Which Splunk AI cost tool do I need? Token and Cost Monitoring vs. Tokenomics vs. ...

"What are we spending on AI?" sounds like a simple question. In practice, it's more complex and actually ...

See What’s New in Splunk Observability Cloud on December 9

Join Splunk Community HQ and the Splunk Observability HQ chapter on December 9, 10:00–11:00 a.m. PT, for the ...

What You Read the Most in 2026: Splunk Lantern's Most Popular Articles, Top Themes, ...

Splunk Lantern is Splunk's customer success center that provides practical guidance from Splunk experts on key ...