Splunk Search

How to convert seconds to days?

mark_chuman
Path Finder

This search:

index=perfstats host=hostname | chart max(System_Up_Time) as "System Uptime" by host

Outputs a value such as this:

85486.676230500001

Just trying to convert this value in seconds to days.

Thanks. Looked at different posts, but can't seem to convert it effectively.

Labels (1)
Tags (2)
0 Karma

Raja
Engager

perfect

0 Karma

pradeepkumarg
Influencer

All that you need is an eval command to do the math and store in a new field

index=perfstats host=hostname | eval Uptime_Days = System_Up_Time/86400 | chart max(Uptime_Days) as "System Uptime" by host

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

The tostring() takes seconds, you've fed it with days. Pick only one way of conversion, not both at once.

0 Karma

mark_chuman
Path Finder

Tried to ensure I'm not using multiple conversions at once by using these two searches:

index=perfstats host=hostname | eval Uptime_Days = System_Up_Time | chart max(Uptime_Days) as "System Uptime" by host | eval System Uptime = tostring('System Uptime', "duration")

index=perfstats host=hostname | chart max(Uptime_Days) as "System Uptime" by host | eval System Uptime = tostring('System Uptime', "duration")

No data found on both. Just an FYI, no need to reply if you don't want. The initial reply is good.

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Another neat thing is this after the chart:

... | eval System Uptime = tostring('System Uptime', "duration")

That will provide a readable string with days, hours, minutes, ...

mark_chuman
Path Finder

you mean like this?

index=perfstats host=hostname | eval Uptime_Days = System_Up_Time/86400 | chart max(Uptime_Days) as "System Uptime" by host | eval System Uptime = tostring('System Uptime', "duration")

I get data like this

00:00:17.723748506149999

Thanks

0 Karma

mark_chuman
Path Finder

Thanks very much.

0 Karma

Raja
Engager

Any idea on how to use round function after 17.723748506149999  like 17.72 
when I use round function values no results found.

0 Karma

PickleRick
SplunkTrust
SplunkTrust

Firstly, a golden shovel award 😉 you dug up a thread from 8 years ago 😄

But seriously. If you have a field which looks like a number but doesn't work like a number (nummerical functions don't give you expected results), you're probably dealing with a text field containing string representation of a number. You have to convert it to number first.

| makeresults
| eval stringfield="17.1654923"
| eval bad=round(stringfield,2)
| eval good=round(tonumber(stringfield),2)
0 Karma

somesoni2
Revered Legend

Try like this

| eval System Uptime = tostring(round('System Uptime',2), "duration")
Tags (1)
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...