Splunk Search

timechart calculated grouped value

ppediaditis
New Member

I have a query in the form

eventtype="search" | stats count as search_count by host | appendcols [search application=flights eventtype="pay_success" | stats count as buy_count by host] | eval conversion=(buy_count/search_count)*100

which works fine and gives me conversions per host,
however, if I want to chart this over time replacing stats with timechart , it doesn't work the way I expect it to.

Is there any way to timechart a calculated value grouped by another value?

Thanks!

Tags (3)
0 Karma

BobM
Builder

I think you could do this by using the bucket function and stats

eventtype="search" | bucket _time span=1h | stats count as search_count by host _time | appendcols [search application=flights eventtype="pay_success" | bucket _time span=1h | stats count as buy_count by host _time ] | eval conversion=(buy_count/search_count)*100 | timechart first(conversion) by host

The bucket command groups data into hour blocks (you can change that to any period you wish) and then the stats now also groups by host and _time so it should now be possible to timechart.

BobM
Builder

Timechart has to use a function and the result has to be numerical but the function could be for example "values(field)".

In the above, conversion was a field name and not a function and I knew it only had one value so I used first as the function.

0 Karma

ppediaditis
New Member

Nice! However, it doesn't allow me to use timechart with something other than a function (in this case conversion), is there some other syntax I should use?

0 Karma
Get Updates on the Splunk Community!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk on November 6 at 11AM PT, and empower your SOC to reach new heights! Duration: ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...