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.
Get Updates on the Splunk Community!

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Introducing Splunk 10.0: Smarter, Faster, and More Powerful Than Ever

Now On Demand Whether you're managing complex deployments or looking to future-proof your data ...

Community Content Calendar, September edition

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