Sunday, 7 January 2018

How to monitor resource utilization of your Linux server

It is very important to understand the resources available in our linux systems to keep it running smoothly an effortlessly. Hence it is important for Linux administrators to keep an eye on all the resources and for doing the same many useful commands come into play. Some of the most important commands are listed below.

Top command

The linux top command is a very useful performance monitoring program which can display all the running and active real time processes. It displays various variables such as CPU usage, memory usage, Cache size and much more. Just run top in the terminal to get the results.
# top
Output:
top - 15:13:49 up  5:25,  1 user,  load average: 0.42, 0.31, 0.32
 Tasks: 208 total,   3 running, 205 sleeping,   0 stopped,   0 zombie
 %Cpu(s):  7.7 us,  1.3 sy,  0.0 ni, 90.0 id,  1.0 wa,  0.0 hi,  0.0 si,  0.0 st
 KiB Mem :  3936084 total,   390088 free,  1954416 used,  1591580 buff/cache
 KiB Swap:  4083708 total,  4083708 free,        0 used.  1659976 avail Mem

PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
 3320 test      20   0 1987084 939560 133752 S   6.2 23.9  59:48.14 Web Content
 12940 test      20   0   41812   3840   3164 R   6.2  0.1   0:00.01 top
 1 root      20   0  185392   6048   4004 S   0.0  0.2   0:07.65 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.09 ksoftirqd/0
 5 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 kworker/0:0H
 7 root      20   0       0      0      0 S   0.0  0.0   0:16.42 rcu_sched
 8 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcu_bh
 9 root      rt   0       0      0      0 S   0.0  0.0   0:00.01 migration/0
 10 root      rt   0       0      0      0 S   0.0  0.0   0:00.09 watchdog/0
 11 root      rt   0       0      0      0 S   0.0  0.0   0:00.09 watchdog/1
 12 root      rt   0       0      0      0 S   0.0  0.0   0:00.01 migration/1
 13 root      20   0       0      0      0 S   0.0  0.0   0:00.07 ksoftirqd/1
 15 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 kworker/1:0H
 ..........................
The top command will keep refreshing until you press q.There are various arguments of top commands which you can view using man page of top command
# man top

Virtual Memory Statistics

The vmstat command is useful to produce compact results on various variables such as swap memory, buffer, cache and much more.
# vmstat
Output:
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0      0 4748336 104628 797532    0    0    17    43  135   84  0  0 99  0  0

Netstat

The netstat command is used to find out the incoming and outgoing network packets as well as interface stats. It is also used in troubleshooting network related problems.
# netstat
Output:
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State      
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags       Type       State         I-Node Path
unix  7      [ ]         DGRAM                    8030   /dev/log
unix  2      [ ]         DGRAM                    6645   @/org/kernel/udev/udevd
unix  2      [ ]         DGRAM                    32754  
unix  2      [ ]         DGRAM                    9564   
unix  2      [ ]         DGRAM                    8265   
unix  2      [ ]         DGRAM                    8205   
unix  2      [ ]         DGRAM                    8151   
unix  3      [ ]         DGRAM                    6659   
unix  3      [ ]         DGRAM                    6658

Memory details

Memory details like free memory, used memory, etc can be viewed using the following commands
# cat /proc/meminfo
Output:
MemTotal: 5823268 kB
MemFree: 4771880 kB
Buffers: 101872 kB
Cached: 776064 kB
SwapCached: 0 kB
Active: 415560 kB
Inactive: 483296 kB
Active(anon): 20932 kB
Inactive(anon): 368 kB
Active(file): 394628 kB
Inactive(file): 482928 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 8 kB
Writeback: 0 kB
AnonPages: 20940 kB
Mapped: 10680 kB
Shmem: 380 kB
Slab: 82140 kB
SReclaimable: 60472 kB
SUnreclaim: 21668 kB
KernelStack: 1424 kB
PageTables: 6292 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 2911632 kB
Committed_AS: 144496 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 26040 kB
VmallocChunk: 34359710252 kB
HardwareCorrupted: 0 kB
AnonHugePages: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
DirectMap4k: 6144000 kB
DirectMap2M: 0 kB
or you can use any of the following commands as well for more concise results
# free
# free -m
# free -mt
# free -gt
Output:
             total       used       free     shared    buffers     cached
Mem:       5823268    1051388    4771880        380     101872     776064
-/+ buffers/cache:     173452    5649816
Swap:            0          0          0

No comments:

Step-by-step OpenLDAP Installation and Configuration on server

This tutorial describes how to install and configure an OpenLDAP server and also an OpenLDAP client. Step by Step Installation and Conf...