Dashboards & Visualizations

How to achieve average response (span) and convert from ms to secs?

msarkaus
Path Finder

Hello,

I'm struggling to convert two status codes (200 and 400) from ms to secs and display the values in a line chart.

tmdEvntMs is the API response time in ms, and httpStatus is my status codes.

I tried using foreach, and  it just converts the response time back to ms.

 timechart span=6h avg(tmdEvntMs) AS avg_response by httpStatus
| foreach * [eval avg_response=round(avg_response/1000, 2)]

 

msarkaus_0-1664811028929.png

Any suggestions would be greatly appreciated.

Thank you

Labels (1)
0 Karma
1 Solution

johnhuang
Motivator

Why don't you convert the milliseconds to seconds before running the timechart?

For example:

| eval tmdEvntSec=ROUND(tmdEvntMs/1000, 4)
| timechart span=6h avg(tmdEvntSec) AS avg_response by httpStatus

 

View solution in original post

msarkaus
Path Finder

The string is not converting the response time (tmdEvntMs) from milliseconds to seconds.

0 Karma

msarkaus
Path Finder

I used the foreach command because, I couldn't get the response time(tmdEvntMs) to convert from ms to secs. It would return the 6 hour average for both httpstatus codes (200 and 400) but it was showing ms.

| timechart span=6h avg(tmdEvntMs) AS avg_response by httpStatus
| eval avg_response=round(avg_response/1000, 2)

msarkaus_3-1664818358593.png

 

When I remove by httpStatus, it converts the response from ms to secs.

| timechart span=6h avg(tmdEvntMs) AS avg_response
| eval avg_response=round(avg_response/1000, 2)

msarkaus_2-1664818129289.png

I'm apologize if I was not clear, I would like to show the 6 hour average for both status codes (200 and 400).

 

0 Karma

johnhuang
Motivator

Why don't you convert the milliseconds to seconds before running the timechart?

For example:

| eval tmdEvntSec=ROUND(tmdEvntMs/1000, 4)
| timechart span=6h avg(tmdEvntSec) AS avg_response by httpStatus

 

msarkaus
Path Finder

This worked.. Thank you!!

0 Karma

richgalloway
SplunkTrust
SplunkTrust

If your problem is resolved, then please click the "Accept as Solution" button to help future readers.

---
If this reply helps you, Karma would be appreciated.
0 Karma

richgalloway
SplunkTrust
SplunkTrust

Since there's only one avg_response field there's no need for the foreach command.  Just use an eval to make the desired conversion.

 timechart span=6h avg(tmdEvntMs) AS avg_response by httpStatus
| eval avg_response=round(avg_response/1000, 2)
---
If this reply helps you, Karma would be appreciated.
0 Karma
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 ...