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

Observe and Secure All Apps with Splunk

  Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

Splunk Decoded: Business Transactions vs Business IQ

It’s the morning of Black Friday, and your e-commerce site is handling 10x normal traffic. Orders are flowing, ...

Fastest way to demo Observability

I’ve been having a lot of fun learning about Kubernetes and Observability. I set myself an interesting ...