The primary task of the system administrators is monitoring and examine Linux system and how long its been promenade. This article demonstrates use of Tuptime tool that help’s System Administrators to analyse how long Linux machine is up and running.
Tuptime tool counts accidental system restarts and not just only uptime of system. When tuptime is installed on system it registers first boot time after installation. Once the first boot time is registered from there onwards it checks for system tuptime and downtime and represents it in Percentage (%). Tuptime also registers current tuptime of system from last restart. Reports Largest Running system Time, Shortest Running System Time & Average of both.
Lets start with installation and drive down deep understanding different options available. The below installation is performed on Ubuntu 18.04.
Note: This installation needs python 3.X and above version.
Installing tuptime is simple as copying and pasting the directory. Yes, four simple commands and installation is done.
$ sudo git clone https://github.com/rfrail3/tuptime.git
Copy executable files. from “/src/tuptime” to “/usr/bin/tuptime” and change the permissions to executable only for all users except root.
$ sudo cp tuptime/src/tuptime /usr/bin/tuptime $ sudo chmod 755 /usr/bin/tuptime
Copy cron.d directory from “tuptime/src/cron.d/tuptime” to “tuptime/src/cron.d/tuptime” and change permissions for user
$ sudo cp tuptime/src/cron.d/tuptime tuptime/src/cron.d/tuptime $ sudo chmod 644 /etc/cron.d/tuptime
Add Tuptime user
Tuptime does not run as a daemon process, it needs execution when the init manager or system Admin startup and shutdown the system.
$ sudo useradd -d /var/lib/tuptime -s /bin/sh tuptime $ sudo chown -R tuptime:tuptime /var/lib/tuptime
Check for system type
To check if system is systemd or init.. use ‘ps 1’ command.
$ ps 1
For systemd systems: PID TTY STAT TIME COMMAND 1 ? Ss 0:07 /usr/lib/systemd/systemd --switched-root --system --deserialize 21
For init systems: PID TTY STAT TIME COMMAND 1 ? Ss 0:06 /sbin/init splash
Add service Manually
If system is systemd.. Add service manually:
$ sudo cp tuptime/src/systemd/tuptime.service /lib/systemd/system $ sudo chmod 644 /lib/systemd/system/tuptime.service $ sudo systemctl enable tuptime.service
Created symlink from /etc/systemd/system/basic.target.wants/tuptime.service to /lib/systemd/system/tuptime.service.
### OR ###
If system is init.. Add service manually:
$ sudo cp tuptime/src/init.d/debian/tuptime /etc/init.d/tuptime $ sudo chmod 755 /etc/init.d/tuptime $ sudo update-rc.d tuptime defaults $ sudo /etc/init.d/tuptime start
After service is been added run and check for system reports using simple command “tuptime”. this commands shows different values representing when system was started, any unwanted system shutdowns from the date. System uptime and downtime in % and hours count. Largest, Shortest & Average uptime as well as downtime of system.
Enumerate system life as list
$ tuptime -l
Startup: 1 at 05:57:06 Monday 16 April 2018 Uptime: 1 hour, 39 minutes and 31 seconds
Know your kernel version using “-K” option. kernel information is shown for each reports.
$ tuptime -k
Below commands shows the system start time in specified format %d for day, %m for Month & %y for Year to show time we use %M,%M,%S respectively for Hours, Minutes & Seconds
$ tuptime -d %d/%m/%y %H:%M:%S
to check database file use “FILE, –filedb=FILE or -f”. Below is example showing for tuptime.db
$ tuptime -f var/lib/tuptime/tuptime.db
Looking for sending the output to someone else, tuptime has the feature that can export output directly to .csv file using “-c or –csv”. Try yourself this is exciting.
Read Also :
Cheers! that’s all for today and thank you for liking and following our post.