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!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...