Usually, we use the 'Uptime' command to find how long a Linux system or server has been running. The uptime command will get us the details such as the current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes. Today, I stumbled upon a similar utility named Tuptime, the uptime command's alternative. Tuptime is a command line utility written in Python that reports the historical and statistical real time of a Linux system, keeping it between restarts. It is just like Uptime but displays more interesting output. In this guide, we will see how to find Linux system uptime using Tuptime utility.
Before going further, let me give you a few examples to find the system uptime using "uptime" command.
If you run the uptime command without any arguments;
$ uptime
You will see an output something like below.
09:53:21 up 18 min, 1 user, load average: 0.01, 0.03, 0.06
Here,
- 09:53:21 - Current time,
- up 18 min - Total uptime,
- 1 user - Number of currently logged-in user,
- load average: 0.01, 0.03, 0.06 - The average system load for the past 5, 10 and 15 minutes.
To show only the total uptime, run:
$ uptime -p
Or,
$ uptime --pretty
To display the date and time the system booted up at, run:
$ uptime --s
Or,
$ uptime --since
As you can see, Uptime has only two options (which is enough though).
Compared to Uptime command, the Tuptime utility lists the following additional details:
- The total system uptime from the day you installed the tuptime utility,
- Total number of system startups and shutdowns,
- Total number of shutdowns done correctly or incorrectly,
- System uptime and downtime time counter in percentage,
- Largest / Shortest / Average uptime,
- Largest / Shortest / Average downtime,
- Current uptime.
Install Tuptime
Tuptime is available in AUR, so it can be installed on Arch Linux and its variants using any AUR helper like below.
$ yay -S tuptime
On Debian, Ubuntu, Linux Mint:
$ sudo apt-get install tuptime
Make sure you have enabled [Universe] repository on Ubuntu and its derivatives to install tuptime.
Universe can be enabled using command:
$ sudo add-apt-repository universe
On other Linux distributions, git clone the Tuptime repository using command:
$ git clone https://github.com/rfrail3/tuptime.git
Copy the "tuptime" binary file to your $PATH, for example "/usr/local/bin/":
$ sudo cp tuptime/src/tuptime /usr/local/bin/tuptime
Finally, make it executable:
$ sudo chmod ugo+x /usr/local/bin/tuptime
Find Linux system uptime details using Tuptime
To view your Linux system's uptime details, simply run:
$ tuptime
Sample output:
System startups: 1 since 07:24:35 AM 01/20/2020 System shutdowns: 0 ok - 0 bad System uptime: 100.0 % - 15 minutes and 49 seconds System downtime: 0.0 % - 0 seconds System life: 15 minutes and 49 seconds Largest uptime: 15 minutes and 49 seconds from 07:24:35 AM 01/20/2020 Shortest uptime: 15 minutes and 49 seconds from 07:24:35 AM 01/20/2020 Average uptime: 15 minutes and 49 seconds Largest downtime: 0 seconds Shortest downtime: 0 seconds Average downtime: 0 seconds Current uptime: 15 minutes and 49 seconds since 07:24:35 AM 01/20/2020
Unlike the traditional Uptime command, Tuptime will keep track of the system reboots and shutdowns from the day it has been installed. Today, I installed it in my Ubuntu server and restarted the system twice. Tuptime tracked all the system startups/shutdowns and presented that information in an understandable way.
Have a look at the following output.
$ tuptime 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
See? The system startup and shutdown counts, total uptime/downtime average uptime/downtime details are updated accordingly. The default uptime command will not track such details.
Tuptime options
Tuptime comes with a few useful options to format the output as you please.
Display output in tabular-column view
To display the system uptime in tabular-column format, use -t flag.
$ tuptime -t No. Startup Date Uptime Shutdown Date End Downtime 1 07:24:35 AM 01/20/2020 16 minutes and 6 seconds 07:40:41 AM 01/20/2020 OK 19 seconds 2 07:41:00 AM 01/20/2020 35 minutes and 1 second 08:16:01 AM 01/20/2020 OK 1 hour, 19 minutes and 13 seconds 3 09:35:14 AM 01/20/2020 2 hours, 57 minutes and 58 seconds
List-view
Similarly, we can display the output as a list-view with -l flag.
$ tuptime -l Startup: 1 at 07:24:35 AM 01/20/2020 Uptime: 16 minutes and 6 seconds Shutdown: OK at 07:40:41 AM 01/20/2020 Downtime: 19 seconds Startup: 2 at 07:41:00 AM 01/20/2020 Uptime: 35 minutes and 1 second Shutdown: OK at 08:16:01 AM 01/20/2020 Downtime: 1 hour, 19 minutes and 13 seconds Startup: 3 at 09:35:14 AM 01/20/2020 Uptime: 3 hours, 0 minutes and 42 seconds
Add Kernel details
We can even add Kernel information with the output using -k flag.
$ tuptime -k System startups: 3 since 07:24:35 AM 01/20/2020 System shutdowns: 2 ok <- 0 bad System uptime: 74.54 % - 3 hours, 52 minutes and 54 seconds System downtime: 25.46 % - 1 hour, 19 minutes and 32 seconds System life: 5 hours, 12 minutes and 26 seconds System kernels: 1 Largest uptime: 3 hours, 1 minute and 47 seconds from 09:35:14 AM 01/20/2020 ...with kernel: Linux-4.15.0-74-generic-x86_64-with-Ubuntu-18.04-bionic Shortest uptime: 16 minutes and 6 seconds from 07:24:35 AM 01/20/2020 ...with kernel: Linux-4.15.0-74-generic-x86_64-with-Ubuntu-18.04-bionic Average uptime: 1 hour, 17 minutes and 38 seconds Largest downtime: 1 hour, 19 minutes and 13 seconds from 08:16:01 AM 01/20/2020 ...with kernel: Linux-4.15.0-74-generic-x86_64-with-Ubuntu-18.04-bionic Shortest downtime: 19 seconds from 07:40:41 AM 01/20/2020 ...with kernel: Linux-4.15.0-74-generic-x86_64-with-Ubuntu-18.04-bionic Average downtime: 39 minutes and 46 seconds Current uptime: 3 hours, 1 minute and 47 seconds since 09:35:14 AM 01/20/2020 ...with kernel: Linux-4.15.0-74-generic-x86_64-with-Ubuntu-18.04-bionic
Change date style
It is also possible to change default human readable date style and print times in seconds and dates in epoch.
To do so, use -s flag.
$ tuptime -s System startups: 3 since 1579505075 System shutdowns: 2 ok <- 0 bad System uptime: 74.77 % - 14140.49 System downtime: 25.23 % - 4772.32 System life: 18912.81 Largest uptime: 11073.81 from 1579512914 Shortest uptime: 965.97 from 1579505075 Average uptime: 4713.5 Largest downtime: 4753.29 from 1579508161 Shortest downtime: 19.03 from 1579506041 Average downtime: 2386.16 Current uptime: 11073.81 since 1579512914
Change date format
By default, Tuptime will print the details based on your system locales. You can, however, change the date format as per your liking using -d flag like below.
$ tuptime -d '%H:%M:%S %m-%d-%Y' System startups: 3 since 07:24:35 01-20-2020 System shutdowns: 2 ok <- 0 bad System uptime: 74.89 % - 3 hours, 57 minutes and 15 seconds System downtime: 25.11 % - 1 hour, 19 minutes and 32 seconds System life: 5 hours, 16 minutes and 47 seconds Largest uptime: 3 hours, 6 minutes and 8 seconds from 09:35:14 01-20-2020 Shortest uptime: 16 minutes and 6 seconds from 07:24:35 01-20-2020 Average uptime: 1 hour, 19 minutes and 5 seconds Largest downtime: 1 hour, 19 minutes and 13 seconds from 08:16:01 01-20-2020 Shortest downtime: 19 seconds from 07:40:41 01-20-2020 Average downtime: 39 minutes and 46 seconds
Display output in CSV format
If required, you can print the output in CSV format as well.
$ tuptime --csv "System startups","3","since","07:24:35 AM 01/20/2020" "System shutdowns","2","ok","<-","0","bad" "System uptime","75.2 %","-","4 hours, 1 minute and 10 seconds" "System downtime","24.8 %","-","1 hour, 19 minutes and 32 seconds" "System life","5 hours, 20 minutes and 43 seconds" "Largest uptime","3 hours, 10 minutes and 4 seconds","from","09:35:14 AM 01/20/2020" "Shortest uptime","16 minutes and 6 seconds","from","07:24:35 AM 01/20/2020" "Average uptime","1 hour, 20 minutes and 23 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","3 hours, 10 minutes and 4 seconds","since","09:35:14 AM 01/20/2020"
Display output since one year ago
If you left your system up for years, this option can get the Linux system uptime since a year ago.
$ tuptime --tsince -31557600
More details can be found in the man pages.
$ man uptime
$ man tuptime
Suggested read:
- How To Monitor Linux System Uptime Using Uptimed
- How To Quickly Monitor Multiple Hosts In Linux
- How To Find Out How Long A Process Has Been Running In Linux
Resource:
Thanks for stopping by!
Help us to help you:
- Subscribe to our Email Newsletter : Sign Up Now
- Support OSTechNix : Donate Via PayPal
- Download free E-Books and Videos : OSTechNix on TradePub
- Connect with us: Reddit | Facebook | Twitter | LinkedIn | RSS feeds
Have a Good day!!
1 comment
Good to know this tool. I’m having issues with a chunk server who restarts ramdomly, this is an easy way to view their behaviour.