Splunk Search

How can I make this nested search faster?

jaxjohnny
Path Finder

This search works, but it's slow. I know nested searches are no longer recommended. Can anyone help me re-write this search for better performance?

xd_index sourcetype="xendesktop:7:icasession" UserName="" host=""
| eval UserName = lower(UserName)
| join UserName HostedMachineName

[search xd_index sourcetype="xendesktop:7:session" UserName="" host="" ClientAddress=* | eval UserName = lower(UserName)] | stats sparkline(avg(LatencySessionAverage), 1m) as "Latency Trend" by UserName LatencyLastRecorded AgentVersion ClientAddress ClientVersion IPAddress ClientPlatform HostedMachineName BrokeringTime

| lookup COSTCENT RACF_ID AS UserName OUTPUT RACF_Name
| fields UserName RACF_Name LatencyLastRecorded "Latency Trend" ClientPlatform ClientVersion ClientAddress IPAddress HostedMachineName BrokeringTime

| sort -LatencyLastRecorded
| dedup HostedMachineName

0 Karma

somesoni2
SplunkTrust
SplunkTrust

Give this a try

`xd_index` sourcetype="xendesktop:7:icasession" UserName="*" host="*" 
[search `xd_index` sourcetype="xendesktop:7:session" UserName="*" host="*" ClientAddress=* | stats count by UserName HostedMachineName| eval UserName = lower(UserName) | table UserName HostedMachineName] 
| eval UserName = lower(UserName)
| join UserName HostedMachineName
| stats sparkline(avg(LatencySessionAverage), 1m) as "Latency Trend" by UserName LatencyLastRecorded AgentVersion ClientAddress ClientVersion IPAddress ClientPlatform HostedMachineName BrokeringTime 
| lookup COSTCENT RACF_ID AS UserName OUTPUT RACF_Name 
| fields UserName RACF_Name LatencyLastRecorded "Latency Trend" ClientPlatform ClientVersion ClientAddress IPAddress HostedMachineName BrokeringTime 
| sort -LatencyLastRecorded 
| dedup HostedMachineName
0 Karma

cmerriman
Super Champion

Possibly something like this. You may need to do an mvexpand after the stats command if you have multiple field values you need split out, or you could have more of those fields after by, I just assumed both sourcetypes didn't have them in common.

(xd_index sourcetype="xendesktop:7:icasession" UserName="" host="" ) OR (xd_index sourcetype="xendesktop:7:session" UserName="" host="" ClientAddress=* )
| eval UserName = lower(UserName)
| stats sparkline(avg(LatencySessionAverage), 1m) as "Latency Trend" values(LatencyLastRecorded) as LatencyLastRecorded values(AgentVersion) as AgentVersion values(ClientAddress) as ClientAddress values(IPAddress) as IPAddress values(ClientVersion) as ClientVersion values(ClientPlatform) as ClientPlatform values(BrokeringTime) as BrokeringTime by UserName HostedMachineName  
| lookup COSTCENT RACF_ID AS UserName OUTPUT RACF_Name 
| fields UserName RACF_Name LatencyLastRecorded "Latency Trend" ClientPlatform ClientVersion ClientAddress IPAddress HostedMachineName BrokeringTime 
| sort -LatencyLastRecorded 
| dedup HostedMachineName
0 Karma

jaxjohnny
Path Finder

Thank you. that re-write is certainly faster, however now all the data values from the LatencyLastRecorded are in the same event. I am looking at the stats parameters now. If I remove the values() portion, I get no results. Definitely good progress! Thank you!

0 Karma

cmerriman
Super Champion

you might be able to add by sourcetype to the stats command to help break that out?

0 Karma
Get Updates on the Splunk Community!

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...