Monitoring Linux VM Resources

As a Linux administrator, it is important to monitor the resources of your virtual machines (VMs) to ensure they are running efficiently and effectively. In this blog post, we will go over some commonly used Linux commands for monitoring VM resources, along with examples of their output.

First, we can use the “top” command to view real-time information about CPU and memory usage. The output will show the processes using the most CPU and memory, as well as the overall utilization of these resources.

$ top

Example output:

top – 10:25:47 up 1 day, 19:01, 1 user, load average: 0.00, 0.01, 0.05 Tasks: 139 total, 1 running, 138 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.3 us, 0.3 sy, 0.0 ni, 99.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 2031180 total, 1995028 free, 14264 used, 36888 buff/cache KiB Swap: 0 total, 0 free, 0 used. 1986816 avail Mem

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 7100 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kswapd0 1 root 20 0 193648 6580 4472 S 0.0 0.0 0:02.38 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd 3 root 20 0 0 0 0 S 0.0 0.0 0:00.06 ksoftirqd/0

We can also use the “free” command to view the amount of physical and swap memory available on the system. This is useful for identifying if a VM is running low on memory and needs to be resized or if memory is being wasted.

$ free -m

Example output:

total used free shared buff/cache available Mem: 1981 143 1737 0 100 1803 Swap: 0 0 0

PID USER %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
1 root 16.5 0.0 9056 1316 ? Ss Sep13 0:19 /sbin/init
2 root 0.0 0.0 0 0 ? S Sep13 0:00 [kthreadd]
3 root 0.0 0.0 0 0 ? S Sep13 0:00 [ksoftirqd/0]
4 root 0.0 0.0 0 0 ? S Sep13 0:00 [kworker/0:0H]
5 root 0.0 0.0 0 0 ? S Sep13 0:00 [kworker/u2:0]
6 root 0.0 0.0 0 0 ? S Sep13 0:00 [migration/0]

Another useful command is “df” which displays the amount of available disk space on the system. This is important for monitoring the storage usage of your VMs and ensuring they have enough space for their workloads.

$ df -h

Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda1      16380060 1035968  15242380   7% /
devtmpfs         804520       0    804520   0% /dev
tmpfs            812332       0    812332   0% /dev/shm
tmpfs            812332    9872    802460   2% /run
tmpfs            812332       0    812332   0% /sys/fs/cgroup
tmpfs            812332      36    812296   1% /tmp
tmpfs            162468       0    162468   0% /run/user/1000

Example output:

Filesystem Size Used Avail Use% Mounted on /dev/sda1 20G 4.4G 14G 24% / devtmpfs 7.8G 0 7.8G 0% /dev tmpfs 7.8G 0 7.8G 0% /dev/shm tmpfs 7.8G 17M 7.8G 1% /run tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup tmpfs 1.6G 0 1.6G 0% /run/user/1000

“netstat” command can be used to monitor network usage. This command displays the active network connections and their status, along with the IP address and port number of each connection. The output of this command looks like this:

netstat
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 192.168.1.100:22        192.168.1.101:47383    ESTABLISHED
tcp        0      0 192.168.1.100:22        192.168.1.102:59011    ESTABLISHED
tcp        0

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *