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!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...