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
Revered Legend

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!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...