Splunk Search

How to add an average transaction duration overlay to a timechart with a split by clause?

bradj013
Explorer

Splunk=6.1.4

My search looks like this:
| transaction TransID keepevicted=true | search eventcount=2 | timechart limit=0 span=1m max(duration) by host

Trying to add an average transaction duration overlay (global not by host) to the chart by adding to the search term: "| eventstats avg(max(duration)) as average | eval average=round(average,0)" and selecting "average" as the overlay value. The overlay is blank.

0 Karma
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

Your search is shooting blanks because there is no field duration in the results of your timechart. Try this:

... | timechart ... by host | eval _count = 0 | foreach * [eval _count = _count + 1] | addtotals fieldname=_total | eval average = _total / _count

Configure the chart to overlay the field average.

View solution in original post

martin_mueller
SplunkTrust
SplunkTrust

Your search is shooting blanks because there is no field duration in the results of your timechart. Try this:

... | timechart ... by host | eval _count = 0 | foreach * [eval _count = _count + 1] | addtotals fieldname=_total | eval average = _total / _count

Configure the chart to overlay the field average.

martin_mueller
SplunkTrust
SplunkTrust

Heh. A little walk-through: You have fields named after your hosts, so you can't access one field called duration. Calculating an average is the same as calculating a sum and a count, then dividing the two. That's what I'm doing here:

  • set up the counter
  • count how many fields (hosts) you have
  • sum up the values
  • divide the two

All that is done with _fieldnames starting with an underscore, so there's no need to hide them using fields - _count _total because the chart doesn't see them anyway... yeah, I'm lazy.

landen99
Motivator

Laziness in success drives efficiency.

bradj013
Explorer

Thanks for the quick response. Not sure how this works, but it does.

Get Updates on the Splunk Community!

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...

New! Splunk Observability Search Enhancements for Splunk APM Services/Traces and ...

Regardless of where you are in Splunk Observability, you can search for relevant APM targets including service ...

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...