Knowledge Management

How do I subtract two search?

politrons
Explorer

I´m making a union of two search, and now I´m trying to make a subtract of the two variables.

 

| set union [search "Output MeshRequestId" | stats avg(time) as avgTimeOut ] [search "Input MeshRequestId" | stats avg(time) as avgTimeInt ]  |stats count(eval(diff=avgTimeOut-avgTimeInt)) as TimeInThrottler

 

Everything fine before the latest count. I can see the definition of two avg variables.

But when I do the stats count(eval(diff=avgTimeOut-avgTimeInt)) as TimeInThrottler

Always return 0. Any idea what is wrong

Labels (2)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

union is producing 2 events, one with avgTimeOut and one with avgTimeInt - the calculation is working on one event at a time from the pipeline, so for each event, one of the fields is null.

Have you considered using appendcols in this scenario?

0 Karma

politrons
Explorer

Thanks for the answer, any example that I can refer of how it should be done using appendcols for this use case?

 

regards 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

search "Output MeshRequestId" | stats avg(time) as avgTimeOut 
| appendcols [search "Input MeshRequestId" | stats avg(time) as avgTimeInt ]  | stats count(eval(diff=avgTimeOut-avgTimeInt)) as TimeInThrottler

FrankVl
Ultra Champion

At that point you could also simply replace that last stats by an eval. (Unless I'm somehow completely missing what you're trying to achieve with that stats)

 

search "Output MeshRequestId"
| stats avg(time) as avgTimeOut 
| appendcols [search "Input MeshRequestId" | stats avg(time) as avgTimeInt ]  | eval TimeInThrottler = avgTimeOut - avgTimeInt

 

 

0 Karma

politrons
Explorer

Thanks for all the answers, after apply both option of union and append. I got same result

Only avgTimeInt is present, and I cannot show the total Difference.

Also I would like to use the result in stats or timechar if is possible

 

splunk_issues.PNG

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

It looks like

"Output MeshRequestId"
| stats avg(time) as avgTimeOut 

is not producing any results - please check the events from the search to make sure they have the time field with that exact name.

politrons
Explorer

Yep silly me the query were wrong, thanks  lot!

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!

Event Series: Splunk Observability Metrics Cost Optimization

Balancing Scale and Spend: Gaining Control Over High-Volume Metrics in Splunk Observability Cloud As ...

Kick the Tires Before You Commit: A Hands-On Tour of the Splunk Observability Cloud ...

Evaluating an enterprise observability platform usually goes like this: fill out a form, get a free trial with ...

Deep insights, no barriers: Splunk Observability Cloud Free Edition

As software delivery cycles continue to accelerate, observability shouldn’t be a luxury — it should be a ...