Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Of all the tools available in your Linux command-line arsenal for monitoring resource usage on your Linux server, 'top' is probably the most well-known and most-often used. The 'top' command comes pre-installed on almost all Linux OS's, and can be run from an SSH command-line with the following simple command:

Code Block
# top

or if you're not already running as a privileged user:

Code Block
$ sudo top


the result will give you something like this:

...

Image Added

As you can see, the 'top' program gives you live access to both CPU and Memory resources on your server, as well as what programs are using what amount of resources.

Let's go over this screen and review what exactly each line means. The first line is as follows:

...

Image Added

  • top - the name of the program running
  • 18:25:54 - current system time
  • up 14 min - the amount of time since the last system boot
  • 2 users - the number of users currently logged in to the system
  • load average - CPU load averages for 1 Minute, 5 Minutes, and 15 minutes
  • 0.00 - CPU load average over the last 1 Minute
  • 0.07 - CPU load average over the last 5 minutes
  • 0.11 - CPU load average over the last 15 minutes

...

The next line covers the kernel's processing table:

...

Image Added

  • Tasks: 117 total - the number of 'active' processes that can request CPU time
  • 1 running - the number of active processes currently utilizing CPU time
  • 116 sleeping - the number of active processes not currently utilizing CPU time
  • 0 stopped - the number of stopped ('paused') processes
  • 0 zombie - the number of zombie ('defunct') processes

...

The next line covers CPU core utilization:

...

Image Added

  • 0.1 us - percentage of CPU time used by 'user' processes
  • 0.1 sy - percentage of CPU time used by 'system' processes
  • 0.0 ni - percentage of CPU time used by processes with a positive 'nice' value
  • 99.8 id - percentage of 'idle' CPU time (where the CPU cores aren't doing anything at all)
  • 0.0 wa - percentage of time the CPU is 'waiting' on I/O (usually your HDD or RAID array)
  • 0.0 hi - percentage of CPU time used by Hardware Interrupts
  • 0.0 si - percentage of CPU time used by Software Interrupts
  • 0.0 st - percentage of time the CPU is waiting for 'Steal Time'

...

The next line deals with memory utilization:

...

Image Added

  • 1884136 total - the total amount of memory available on the system
  • 922732 free - the total amount of free memory
  • 493072 used - the total amount of memory used by the system
  • 468332 buff/cache - the total amount of memory used by buffers and cache

...

The next line deals with swap:

...

Image Added

  • 839676 total - total amount of swap available on the system
  • 839676 free - total amount of free swap
  • 0 used - total amount of used swap
  • 1230288 avail Mem - total amount of memory available for starting new apps without swapping

...

After the general information is presented, the next section in 'top' displays resources and CPU utilization on a per-process level. The following line is the headings for the columns being displayed for each process, and what they mean:

...

Image Added

  • PID - the Process ID number
  • USER - the user account the process is running under
  • PR - the Priority value of the process
  • NI - the Niceness value of the process
  • VIRT - the amount of Virtual Memory used by the process
  • RES - the amount of Physical Memory used by the process
  • SHR - the amount of Shared Memory used by the process
  • S - the current status of the process ('S' for sleeping, 'R' for running, etc)
  • %CPU - the percentage of CPU the process is taking
  • %MEM - the percentage of Memory the process is taking
  • TIME+ - the total CPU time that has been given to the process while it's been active
  • COMMAND - the name of the process itself - toggle the commands full path by hitting 'c'

...

The first command is simple:

Code Block
# df -h

which will get you output similar to this:

...

Image Added

The df command is a linux command that shows your drive mount points along with their size and usage. Adding the -h option to the command told df that I wanted the file sizes to be human-readable - that is, I wanted the sizes to be in MB or GB and not KB. Note that the sizes listed in the above output have either 'M' or 'G' added to them.

...

That's neat, but I want to free up some space, how can I see where my hard drive space is going? Well, that's what the ducommand was made for!

Code Block
[root@localhost ~]# du -h --max-depth=1 /

Like the df command, the du command takes a -h parameter to make the numeric output more readable. Next, I've limited the depth of the du command to a single directory with the --max-depth=1 parameter. Last, I told du to run on the root folder /. Here's the result:

Code Block
[root@localhost ~]# du -h --max-depth=1 /

...


162M /boot

...


0 /dev

...


0 /proc

...


8.4M /run

...


0 /sys

...


23M /etc

...


172M /root

...


36K /tmp

...


115M /var

...


1.1G /usr

...


0 /home

...


0 /media

...


0 /mnt

...


250M /opt

...


0 /srv

...


1.8G /

...


[root@localhost ~]#

So, looks like most of my space is being used in the /usr directory. That makes sense, because this is a base install of CentOS 7, and the majority of the commands are kept in the /usr directory.

...