Score:1

How to get all time working hours on Ubuntu Server?

lt flag

I own a server which is a hardware solution, and I want to see the whole amount of time it has worked. Like sum of all the uptimes.

e. g. if it worked 3 hrs and then stopped and after 3 days worked 5 more hours, total working hours are 3+5=8

Server worked over ~2 months. Can I extract this history from some system variables maybe?

Raffa avatar
jp flag
[`tuptime`](https://manpages.ubuntu.com/manpages/jammy/en/man1/uptime.1.html) but that needs to have been installed directly after OS installation ... You can also try summing up logged-in times from [`last`](https://manpages.ubuntu.com/manpages/jammy/man1/last.1.html) it should have logs long enough for you.
Artur Meinild avatar
vn flag
I think your link should have been [`tuptime`](https://manpages.ubuntu.com/manpages/jammy/man1/tuptime.1.html).
Raffa avatar
jp flag
@ArturMeinild You think right but I could swear I linked to `man tuptime` .. Maybe some [AI/GPT](https://askubuntu.com/q/1448782/968501) robot changed it :-D
Score:1
vn flag

You could do several things to track the total uptime of your system.

Track uptime of the system disk

If your system disk is SMART capable (it likely is), and you have smart monitoring enabled, you can watch the total uptime in the SMART report.

If you haven't, install it with:

sudo apt install smartmontools

You can watch the status, including "Power on hours" with this command:

sudo smartctl -a /dev/<device>

In my case it's:

sudo smartctl -a /dev/nvme0n1 | grep "Power On Hours"

Which gives:

Power On Hours:                     25,013

The only caveat with this is that it only tracks uptime of the current system disk. This have an additional hurdle that it is the total power-on time for the disk, including its use in previous systems. So if it's not a new disk, subtract any previous running time since installation from the power-on time.

Install an uptime tracking daemon

Thanks to this answer for inspiration.

You can install uptimed, and set it up so it never discards values (set LOG_MAXIMUM_ENTRIES=0 in /etc/uptimed.conf). Another option is tuptime.

Install uptimed with:

sudo apt install uptimed

When this is running, you can view total uptime with the command:

uprecords

Example output:

    up  1492 days, 02:57:18 | since                     Sat Sep  7 00:50:06 2013
  down    61 days, 08:11:24 | since                     Sat Sep  7 00:50:06 2013
   %up               96.051 | since                     Sat Sep  7 00:50:06 2013

For tuptime, this is simply the default command:

tuptime

Example output:

System startups: 3 since 07:24:35 AM 01/20/2020
System shutdowns: 2 ok <- 0 bad
System uptime: 43.18 % - 1 hour, 0 minutes and 27 seconds
System downtime: 56.82 % - 1 hour, 19 minutes and 32 seconds
System life: 2 hours, 19 minutes and 59 seconds

Largest uptime: 35 minutes and 1 second from 07:41:00 AM 01/20/2020
Shortest uptime: 9 minutes and 20 seconds from 09:35:14 AM 01/20/2020
Average uptime: 20 minutes and 9 seconds

Largest downtime: 1 hour, 19 minutes and 13 seconds from 08:16:01 AM 01/20/2020
Shortest downtime: 19 seconds from 07:40:41 AM 01/20/2020
Average downtime: 39 minutes and 46 seconds

Current uptime: 9 minutes and 20 seconds since 09:35:14 AM 01/20/2020

This method only counts uptime from the point uptimed or tuptime was installed and running.

Score:1
st flag

uptime isn't really great for this, but you could generally presume that the "load average" / "cores" would give you a decent approximation of how much the machine was working over the time since the machine had been booted. After you do this calculation, 1 = maxed out most of the time, 0.5 = half way loaded, etc.

The output of the command itself is relatively useless "between machines" because fully loaded on an 8 core machine is 8.0 on the output, and 1.0 is hardly used. On a dual core / single processor machine a 2.0 would mean you're destroying it, etc. :D

If you have a monitoring software (like these work loads run in a VM/docker image/etc) then the VM host usually can display graphs of all the time the server is working and how long its doing it. You can configure how much data they keep, but most of them only keep graphs for the period of a day or so by default. It's something you'd have to turn on.

Artur Meinild avatar
vn flag
I don't think the OP was asking about load averages, but rather purely a total uptime for the server - at least that's how I read the question.
sean avatar
st flag
@ArturMeinild You can definitely figure this out if you have some sort of orchestration on the machine. Most of the good stuff is paid, unfortunately, so it's a matter of how important it is to you. :D
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.