Dashboards & Visualizations

Adding a Linear Trendline and customizing chart

aquinojason
Path Finder

Hi,

I have this on my splunk query

index=xxxxxxx sourcetype="xxxxxx" EXPRSSN=IBM4D* | eval DATE=strftime(strptime(DATE,"%d%b%Y"),"%Y-%m-%d") | table EXPRSSN DATE MIPS | eval _time=strptime(DATE." "."00:00:00","%Y-%m-%d %H:%M:%S") | chart values(MIPS) over _time by EXPRSSN 

I wanted to add a linear trendline on my chart. Hoping I could re-create this

aquinojason_0-1641921060830.png

 

How do I customize also the my line chart? I wanted to have the other one filled as well. I am getting the one in below from splunk

aquinojason_1-1641921179727.png

 

Labels (1)
0 Karma

tscroggins
Influencer

@aquinojason 

To easily summarize values over time, you can use the timechart command:

index=xxxxxxx sourcetype="xxxxxx" EXPRSSN=IBM4D*
| timechart span=1d avg(MIPS) ```or max(MIPS), p90(MIPS), etc.```

Core Splunk does not include a linear trendline command, but you can create one yourself using SPL. See https://wiki.splunk.com/Community:Plotting_a_linear_trendline for an old example.

Splunk Machine Learning Toolkit does include a linear regression algorithm for the fit command:

index=xxxxxxx sourcetype="xxxxxx" EXPRSSN=IBM4D*
| timechart span=1d avg(MIPS) as MIPS
| fit LinearRegression MIPS from _time

You can visualize your data as an area chart and then configure predicted(MIPS) as an overlay to show a linear trend.

Here's an example using Splunk introspection events:

| tstats max(data.normalized_pct_cpu) as pct_cpu where index=_introspection host=splunk by _time span=10s 
| fit LinearRegression pct_cpu from _time

aquinojason_linear_regression.png

I'm not sure what the red line in your chart represents. If you want to add a moving average to your chart, you can use the trendline command:

| tstats max(data.normalized_pct_cpu) as pct_cpu where index=_introspection host=splunk by _time span=10s 
| trendline sma6(pct_cpu)
| fit LinearRegression pct_cpu from _time

 

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...