Activities

July 2013
M T W T F S S
« Jun   Aug »
1234567
891011121314
15161718192021
22232425262728
293031  

Useful Linux tool for monitoring process and system resource statitics

Recently I have a requirement to identify the process by resource to optimize the server performance. This is because some of the server hardware resource is heavily used sometime when the system load is high. After the Googling I found lots of really useful command line tool.

1. Top
It is the most widely used and one of the favorite sysadmin tool to check the process running in the memory. This will list all the process running along with consumed CPU and memory usage.

2. Free
This will shows the current memory statitics along with swap usage and cached memory

3. ps tool

This is the best tool to identify all the running process along with it’s process id, Virtual and physical memory usage, who is the owner of this process and how long it’s been running etc.

4. pstree

This is a tool which shows the program dependents of a running process. This would be really helpful if you find any malware program running on your system. Also helpful to view the program specific config files eg. Apache loaded conf. file etc.

[root@025 ~]# ps aux | grep "mysql" |awk '{print $2}'| head -1
3968
[root@025 ~]# pstree  -A -p 3968
mysqld_safe(3968)---mysqld(4023)-+-{mysqld}(4058)
                                 |-{mysqld}(4059)
                                 |-{mysqld}(4060)
                               
[root@mail01 ~]# pstree -a | more
init
  |-crond
  |-dbus-daemon --system
  |-dovecot
  |   |-dovecot-auth
  |   |-imap-login
  |   |-imap-login
  |   |-imap-login
  |   |-pop3-login
  |   |-pop3-login
  |   `-pop3-login
  |-(events/0)
  |-(events/1)
  |-(events/2)
  |-httpd
  |   |-httpd
  |   |-httpd
  |   |-httpd

5. pgrep
This will return the process name associate with an process id

[root@ip- ~]# pgrep httpd
6137
6138
6143
7170
7185
28124
[root@ip- ~]#

6. htop
This is a wonderful command to monitor individual CPU core usage of the server. Normally top command will shows only the process in memory and it did not show which processor is being executing that program. Also we can see the the usage of CPU individually. Also we can see the runtime process list in the same window.

Installation #yum install htop

7. atop
This is an excellent tool to monitor the process along with hardware statistics. This is showing the exact resource utilization of both hardware and software. We can identify the disk health if it is showing long time for reading and writing (avio) compare with other server.

Installation #yum install atop

8. netstat
This command useful for monitoring active network connections towards the server and identify the port used by the program/services. This will be helful wheather a service which uses port running property or not like identify the program which uses the port 80.

root@cpanel01 [~]# netstat -nlp | grep ":80"
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      20145/httpd
root@cpanel01 [~]# netstat -alp | more
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 *:imaps                     *:*                         LISTEN      31778/dovecot
tcp        0      0 *:infowave                  *:*                         LISTEN      3871/cpsrvd (SSL) -
tcp        0      0 *:nrpe                      *:*                         LISTEN      3359/xinetd
tcp        0      0 *:pop3s                     *:*                         LISTEN      31778/dovecot
tcp        0      0 *:radsec                    *:*                         LISTEN      3871/cpsrvd (SSL) -
tcp        0      0 *:gnunet                    *:*                         LISTEN      3871/cpsrvd (SSL) -
tcp        0      0 *:eli                       *:*                         LISTEN      3871/cpsrvd (SSL) -
tcp        0      0 *:mysql                     *:*                         LISTEN      3426/mysqld
tcp        0      0 *:submission                *:*                         LISTEN      3452/exim
tcp        0      0 *:11211                     *:*                         LISTEN      3479/memcached
tcp        0      0 *:pop3                      *:*                         LISTEN      31778/dovecot
tcp        0      0 *:imap                      *:*                         LISTEN      31778/dovecot
tcp        0      0 *:nbx-ser                   *:*                         LISTEN      3871/cpsrvd (SSL) -
tcp        0      0 cpanel01:783                *:*                         LISTEN      338/spamd child
tcp        0      0 *:http                      *:*                         LISTEN      20145/httpd
tcp        0      0 *:nbx-dir                   *:*                         LISTEN      3871/cpsrvd (SSL) -

9. dmidecode
This is very much useful to identify the hardware details of a server. we can get all type of hardware information including CPU/Memory/Board name and identify the hardware vendor.

[root@025 ~]# dmidecode -t 4
# dmidecode 2.7
SMBIOS 2.5 present.
Handle 0x0000, DMI type 4, 35 bytes.
Processor Information
        Socket Designation: J1PR
        Type: Central Processor
        Family: Other
        Manufacturer: Intel(R) Corporation
        ID: A5 06 01 00 FF FB EB BF
        Version: Intel(R) Xeon(R) CPU           W3520  @ 2.67GHz
        Voltage: 1.2 V
        External Clock: 133 MHz
        Max Speed: 4000 MHz
        Current Speed: 2668 MHz
 [root@025 ~]#

There are various option to identify each hardware device.
Usage : dmidecode -t < type>

Type Information
—————————————-
0 BIOS
1 System
2 Base Board
3 Chassis
4 Processor
5 Memory Controller
6 Memory Module
7 Cache
8 Port Connector
9 System Slots
10 On Board Devices
11 OEM Strings
12 System Configuration Options
13 BIOS Language
14 Group Associations
15 System Event Log
16 Physical Memory Array
17 Memory Device
18 32-bit Memory Error
19 Memory Array Mapped Address
20 Memory Device Mapped Address
21 Built-in Pointing Device
22 Portable Battery
23 System Reset
24 Hardware Security
25 System Power Controls
26 Voltage Probe
27 Cooling Device
28 Temperature Probe
29 Electrical Current Probe
30 Out-of-band Remote Access
31 Boot Integrity Services
32 System Boot
33 64-bit Memory Error
34 Management Device
35 Management Device Component
36 Management Device Threshold Data
37 Memory Channel
38 IPMI Device
39 Power Supply

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>