Skip to main content

Documenting system uptime in Linux

The uptime command is simple but provides critical information to sysadmins.
Image
Documenting system uptime in Linux

Image by Alexas_Fotos from Pixabay

The uptime command is straightforward and simple, but it can still be nice to see how some sysadmins use these common tools. Documenting the system's uptime may be important for service level agreements, performance monitoring, and general troubleshooting.

[ You might also like: Important Linux /proc filesystem files you need to know ]

The uptime command

The uptime command provides several useful results, depending on the information you need.

Image
basic uptime output
Figure 1: Basic uptime command output.

Breaking down the output here:

  • Current time
  • Up (the current status of the system)
  • Total time the system has been running
  • User count (number of current logged in users)
  • System load averages over 1, 5, and 15 minutes

Note: The load average is based on both running and uninterruptable processes.

Documenting system uptime

So how can sysadmins use this information?

First, the command itself gives a quick look at a few general performance parameters. For example, you can see whether the system has restarted recently. You can also see how many users are logged in, letting you know whether the system is busy, if it can be rebooted, or even how useful the local services might be. Obviously, the ability to see the system load averages over time provides important system performance information.

Next, you can combine the uptime results with other commands to document the system's configuration and current status. Such a report might be important for service level agreements or general server availability queries by management. I have written a few quick examples of gathering system information below.

You can use general redirectors to document uptime results:

# uptime > system-doc.txt

Take a look at my recent article Five ways to use redirect operators in Bash for a reminder on using redirectors.

If there's already content in the system-doc.txt file, be sure to use the append redirector instead:

# uptime >> system-doc.txt

It is easy to combine the uptime results with the output of other commands to quickly report on the system's current status:

# date > system-doc.txt
# hostname >> system-doc.txt
# uptime >> system-doc.txt
# ip a >> system-doc.txt
Image
basic documentation commands
Figure 2: Basic system documentation commands.

There are plenty of ways to automate and streamline such commands.

The uptime options

The uptime command doesn't have many options. In fact, there are only four, and one of those is the help option to view the other three. That option is -h.

First, use the -p option to organize the uptime output into a "pretty" format. Using this option results in just the system's running time being displayed on the screen.

Image
uptime with -p option
Figure 3: The uptime -p command.

Redirect it into your documentation file like this:

# uptime -p >> system-doc.txt

Next, display the system date and time since the system started by using the -s option.

Image
the uptime -s output
Figure 4: The uptime -s command.

SCREEN uptime -s

Redirect it into your documentation file like this:

# uptime -s >> system-doc.txt

Finally, the -V option displays the version information for the uptime command.

# uptime -V
Image
uptime -V option
Figure 5: The uptime -V command.

[ Getting started with containers? Check out this free course. Deploying containerized applications: A technical overview. ]

Wrap up

I think it's worth pointing out that the uptime results are also displayed in the first line of the top command's output. That's pretty handy information when troubleshooting performance issues using top. In that case, knowing the system load averages over the five and fifteen-minute ranges is good as related to the current information dynamically displayed in top. For a reminder on how to use and customize top, see this article here on Enable Sysadmin.

While the uptime command is simple, I think it's useful for displaying basic system information. It can answer questions regarding how long the system has been available and give a general idea of performance based on user load.

Author’s photo

Damon Garn

Damon Garn owns Cogspinner Coaction, LLC, a technical writing, editing, and IT project company based in Colorado Springs, CO. Damon authored many CompTIA Official Instructor and Student Guides (Linux+, Cloud+, Cloud Essentials+, Server+) and developed a broad library of interactive, scored labs. He regularly contributes to Enable Sysadmin, SearchNetworking, and CompTIA article repositories. Damon has 20 years of experience as a technical trainer covering Linux, Windows Server, and security content. He is a former sysadmin for US Figure Skating. He lives in Colorado Springs with his family and is a writer, musician, and amateur genealogist. More about me

Try Red Hat Enterprise Linux

Download it at no charge from the Red Hat Developer program.