Splunk Search

Could you introduce and use dynamic statistics in eval commands?

DouglasSmithers
Engager

I'm trying to calculate an average column in a chart by renaming the Total column (created with the addtotals command) and diving it by the number of columns summed by addtotal, but the average will change as new events are added so I wouldn't prefer to simply use the current average, as that would require routinely updating the code. Is there a way to create the average within the eval command so that it would update automatically as new data is added? It would simply require that the Average (formerly Total) column would be divided by a distinct count of one of the categories being analysed.

I won't post all of the code in my search, as, at this point, I've created a chart, transposed it, appended a column, added totals and altered them with eval, and repeated that last step to different effect (I'm quite a way through a dashboard at this point). The last snippet of code which describes the current point is as follows.

| table pWeekInQuarter 1 2 3 4 5 6 7 8 9 10 11 12 13
| addcoltotals labelfield="pWeekInQuarter" label="Average"
| transpose column_name=pWeekInQuarter header_field=pWeekInQuarter 0
| eval "Average"=$Average$/[search index=breakdown | stats dc($pQuarter$)]

In the last line, you can see a subsearch to pull the statistic required for the average. That, however, wouldn't work. It is where that subsearch is, following the slash, that I need to place an actively updated statistic.

Tags (1)
0 Karma

mayurr98
Super Champion

Hi it would better to solve your problem if you update your question with the search query you are using currently, o/p you are getting and the expected o/p?

0 Karma

DouglasSmithers
Engager

Sure. I won't post all of the code in my search, as, at this point, I've created a chart, transposed it, appended a column, added totals and altered them with eval, and repeated that last step to different effect (I'm quite a way through a dashboard at this point). The last snippet of code which describes the current point is as follows.

| table pWeekInQuarter 1 2 3 4 5 6 7 8 9 10 11 12 13
| addcoltotals labelfield="pWeekInQuarter" label="Average"
| transpose column_name=pWeekInQuarter header_field=pWeekInQuarter 0
| eval "Average"=$Average$/[search index=breakdown | stats dc($pQuarter$)]

In the last line, you can see a subsearch to pull the statistic required for the average. That, however, wouldn't work. It is where that subsearch is, following the slash, that I need to place an actively updated statistic.

Is that enough information?

0 Karma
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...