Dashboards & Visualizations

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

msarkaus
Explorer

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
Explorer

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

0 Karma

msarkaus
Explorer

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
Explorer

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

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...