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.