Splunk Dev

How do I calculate and present values on a day-by-day basis in a bar chart?

lctanlc
New Member

This is how my log file looks like:
2017-06-02 17:07 - SearchTime: 16414
2017-06-02 18:05 - SearchTime: 6450
2017-06-02 18:05 - SearchTime: 2555
2017-06-02 23:51 - SearchTime: 2066
2017-06-03 04:28 - SearchTime: 982
2017-06-05 07:15 - SearchTime: 9568
2017-06-05 09:15 - SearchTime: 7344
2017-06-05 09:25 - SearchTime: 34150
2017-06-06 14:15 - SearchTime: 18875

I could do the following query to calculate the "TotalSearches" and "10sPercentrank" values for the past 5 days and its value is 66.67:
... |eval isOK=if(SearchTime<10000, 1, 0) | stats count as TotalSearches sum(isOK) as isOkTotal | eval 10sPercentrank=(isOkTotal/TotalSearches)*100 | table TotalSearches 10sPercentrank

However, I am now being asked to present the "TotalSearches" and "10sPercentrank" values by day in a chart. E.g.,
On 2017-06-02, the "TotalSearches" and "10sPercentrank" values are 75
On 2017-06-03, the "TotalSearches" and "10sPercentrank" values are 100
On 2017-06-04, the "TotalSearches" and "10sPercentrank" values are 0
On 2017-06-05, the "TotalSearches" and "10sPercentrank" values are 66.67
On 2017-06-06, the "TotalSearches" and "10sPercentrank" values are 0

How should I modify my query to achieve that?

Tags (1)
0 Karma
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

Replace stats with timechart span=1d to get per-day statistics, and then set the visualization to column chart.

View solution in original post

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Replace stats with timechart span=1d to get per-day statistics, and then set the visualization to column chart.

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Remove the table command, that implicitly drops all time information from your results. If you want to hide a field from the chart, use fields - fieldname

0 Karma

lctanlc
New Member

I am running on Splunk 6.4.3.
Everytime I fine-tuned and saved the Splunk dashboard, the spaces in the "fields - fieldname" portion of the query will be removed. Is there a way to prevent such removal?

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

That's a bug in the xml formatter, 6.6.x should not do that any more.

0 Karma

lctanlc
New Member

It met my needs! Thanks a lot!

0 Karma

lctanlc
New Member

I have changed my query to be as follows:
|eval isOK=if(SearchTime<10000, 1, 0) | timechart spen=1d count as TotalSearches sum(isOK) as isOkTotal | eval 10sPercentrank=(isOkTotal/TotalSearches)*100 | table TotalSearches 10sPercentrank
May I know how to make my x-axis to show the date instead of the TotalSearches value?

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...