Dashboards & Visualizations

How to calculate the Average of the Time coming in sec

aditsss
Motivator

Hi Everyone,

I am getting total time taken field as shown below in my logs

on_1621717537363_2611781,3497 secs,Passed,,E3

621717537363_2611790,926 secs,Passed,,E3

I want to calculate its Average. I tried with this query but its not working:

index=abc source="/xyz"|eval fields=split(_raw,",")|eval job_id=mvindex(fields,0)|eval sourceType=mvindex(fields,1)|eval inputFilePath=mvindex(fields,2)|eval tableName=mvindex(fields,3)|eval inputRecordsCount=mvindex(fields,4)|eval processedRecordsCount=mvindex(fields,5)|eval startTime=mvindex(fields,6)|eval endTime=mvindex(fields,7)|eval loadAppendTimestampCol=mvindex(fields,8)|eval refreshType=mvindex(fields,9)|eval className=mvindex(fields,10)|eval applicationId=mvindex(fields,11)|eval totalTimeTaken=mvindex(fields,12)|eval status=mvindex(fields,13)|eval errorMessage=mvindex(fields,14)|eval Environment=mvindex(fields,15)|stats avg(totalTimeTaken) as AvgExecTime |eval AvgExecTime=round(AvgExecTime,2)

Can someone guide me on this.

Labels (3)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Add this after the mvindex line for totalTimeTaken

| rex field=totalTimeTaken "(?<totalTimeTaken>\d+)"

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

Add this after the mvindex line for totalTimeTaken

| rex field=totalTimeTaken "(?<totalTimeTaken>\d+)"

aditsss
Motivator

@ITWhisperer 

why its not working with Timechart when I am using below query:

index=abc source="xyz"|eval fields=split(_raw,",")|eval job_id=mvindex(fields,0)|eval sourceType=mvindex(fields,1)|eval inputFilePath=mvindex(fields,2)|eval tableName=mvindex(fields,3)|eval inputRecordsCount=mvindex(fields,4)|eval processedRecordsCount=mvindex(fields,5)|eval startTime=mvindex(fields,6)|eval endTime=mvindex(fields,7)|eval loadAppendTimestampCol=mvindex(fields,8)|eval refreshType=mvindex(fields,9)|eval className=mvindex(fields,10)|eval applicationId=mvindex(fields,11)|eval totalTimeTaken=mvindex(fields,12)|rex field=totalTimeTaken "(?<totalTimeTaken>\d+)"|eval status=mvindex(fields,13)|eval errorMessage=mvindex(fields,14)|eval Environment=mvindex(fields,15)|where Environment ="E3"|dedup job_id startTime endTime totalTimeTaken|timechart sum(totalTimeTaken) as TotalExecTime by job_id |eval TotalExecTime=round(TotalExecTime,2)|sort -TotalExecTime limit=10

0 Karma

aditsss
Motivator

@ITWhisperer 

This will give me average in seconds or in minutes?

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Seconds (inferred from the "secs" in the data)

0 Karma

isoutamo
SplunkTrust
SplunkTrust

Hi

this should work.

| makeresults 
| eval _raw = "
on_1621717537363_2611781,3497 secs,Passed,,E3
621717537363_2611790,926 secs,Passed,,E3"
| multikv noheader=t
 ```above generates sample data```
| rex ",(?<secs>\d+) secs,"
| stats avg(secs) as AvgExecTime

 r. Ismo

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!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...