Splunk Search

Displaying stats count as single value but with sparkline and trend indicator

eddychuah
Path Finder

Hi fellow Splunkers, I've read Single Value support docs and it seems to have distinct application for Stats or Timechart. When I use timechart:

sourcetype="error log" severity=ERROR someErrorcode | timechart count

it displays sparkline and trend correctly, however for the single value, it's using the Count of that error at the specific instance of time as opposed to the indicated desired span of time

I want to try to combine the two or have an end result that leverages both stats and timechart. I want to use the total count of events found in my span of time as my single value display but I also want a sparkline/heartbeat below showing the timeline of the event occurrences during my span and an up/down trend indicator

examples available in the Docs are too simplistic and seems to only use values that are already single values - ie. close stock price, temperature...

Thanking you for your help in advance!!!

1 Solution

niketn
Legend

@ eddychuah, Following are couple of your options:

1) Use accum command to keep cumulative count of your events. This way the Single Value Result count will be Final Total Count and the trendline will be based on cumulative count i.e. keep increasing trendline if events are found for specific span and keep trendline at the same level if no events are found in specific span.

Try out following run anywhere search with Single Value visualization:

index=_internal sourcetype=splunkd log_level!=INFO
|  timechart count as Errors
|  accum Errors

2) Use addcoltotals or addtotals command to calculate total count and add to the end of the timechart results. This will show final total with trend lines going up and down as original timechart command. However, the final trend will be incorrect as it will always show a final jump to cumulative total.

Try out following run anywhere search with Single Value visualization:

index=_internal sourcetype=splunkd log_level!=INFO
|  timechart count as Errors
|  addcoltotals label="Total" labelfield="_time"

Please try out and see if one of the above options will work fine or not.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

View solution in original post

eddychuah
Path Finder

Both very valid points

In the end, I ended up using 2 separate searches, 1 using stats count for single point and 1 using timechart for 'sparkline' and combined the two into 1 panel

0 Karma

niketn
Legend

@eddychuah yes sometimes it is better to segregate visualizations which layout different interpretation.

We had actually once built a timechart with column chart indicating real-time data volume and overlaid it with cumulative volume over time and turned on the overlay axis. This gave us a look at real time as well as cumulative volume and turning on Min/Max gave us final cumulative Total (all towards right).

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

eddychuah
Path Finder

@niketnilay excellent point, I've started to treat Splunk as lego and have fun w/ it instead of getting angry at the rigidity of certain visualizations and why it doesn't cover the most basic use cases

and that is also a great example you laid out, i'll def keep that in mind for future projects

cheers!

0 Karma

camillak
Path Finder

@eddychuah I'm having the same issue and reached the same conclusion that this would be the best option, i.e. to do a single value and a timechart, out of curiosity did you use any js to modify the size or position of the timechart? I want to make it look more like the single value sparkline.

0 Karma

eddychuah
Path Finder

Hi camillak, I did not do anything hardcore such as adding my own CSS file into the conf directories. What I was simply create 2 panels to do whatever I want (timechart and single value) and put the 2 panels together and Edited the dashboard, went into the "Source" and removed the

/ panel

/ row
row
panel

tags which bordered between the 2 panels such that it looks like 1 panel encapsulating 2 charts.

I gave up on the sparkline idea in this usecase upon further consideration, I was building a landing page for my app which shows a high level summary of overall system health and sparklines would have had very little value add.

0 Karma

niketn
Legend

@ eddychuah, Following are couple of your options:

1) Use accum command to keep cumulative count of your events. This way the Single Value Result count will be Final Total Count and the trendline will be based on cumulative count i.e. keep increasing trendline if events are found for specific span and keep trendline at the same level if no events are found in specific span.

Try out following run anywhere search with Single Value visualization:

index=_internal sourcetype=splunkd log_level!=INFO
|  timechart count as Errors
|  accum Errors

2) Use addcoltotals or addtotals command to calculate total count and add to the end of the timechart results. This will show final total with trend lines going up and down as original timechart command. However, the final trend will be incorrect as it will always show a final jump to cumulative total.

Try out following run anywhere search with Single Value visualization:

index=_internal sourcetype=splunkd log_level!=INFO
|  timechart count as Errors
|  addcoltotals label="Total" labelfield="_time"

Please try out and see if one of the above options will work fine or not.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

skoelpin
SplunkTrust
SplunkTrust

The problem with ... | stats count is that you lose everything except for the final count. Perhaps you should look into using eventstats which will create a new field of your count and allow you to keep all existing fields?

I'm assuming you want to write a single search as a base search and use the results in multiple panels?

0 Karma
Get Updates on the Splunk Community!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...