Splunk Search

How to get Uptime in Days

priya1926
Path Finder

My output format is 20220129054235.496380-300

I need to convert the value in bold to normal and find the difference of that to now() ie., epoch time.  this will give the uptime in days


Labels (1)
0 Karma
1 Solution

isoutamo
SplunkTrust
SplunkTrust

Hi

here is one way

| makeresults 
| eval time="20220129054235.496380-300"
| eval epoch = strptime(time, "%Y%m%d%H%M%S.%6Q%z")
| eval time2 = strftime(epoch, "%F %T")
| eval UpTime = tostring(round(now()-epoch), "duration")

If you want to calculate with UpTime then you need to convert it by yourself as usually to get days, hours, mins and seconds from it.

r. Ismo 

View solution in original post

isoutamo
SplunkTrust
SplunkTrust

Hi

here is one way

| makeresults 
| eval time="20220129054235.496380-300"
| eval epoch = strptime(time, "%Y%m%d%H%M%S.%6Q%z")
| eval time2 = strftime(epoch, "%F %T")
| eval UpTime = tostring(round(now()-epoch), "duration")

If you want to calculate with UpTime then you need to convert it by yourself as usually to get days, hours, mins and seconds from it.

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!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...