How to monitor my Linux system and gather statistics Print

  • statistics, monitoring, linux system, network, debugging
  • 5

You can use following Linux commands to help monitoring your Linux system performance, gather some statistics and view resource usage history.

1. Monitor connections with ss command
ss is preinstalled on all Linux server and VPS distributions we provide. Its purpose is to replace good old netstat

Show established TCP connections

ss -t 

Show established UDP connections

ss -u 

Show ports listening for TCP connections

ss -ltn

Show ports listening to UDP connection

ss -lun

Show ports listening on TCP and UDP

ss -ltun


2. Gathering Linux OS statistics

To gather Linux system statistics you can use sysstat. This tool must be installed first.

(Debian: apt-get install sysstat , CentOS/Fedora: yum install sysstat):

sudo apt-get install sysstat
yum install sysstat

This will make several tools available, for example sar and mpstat
Lets gather some basic information for interval of 20 seconds:

vmstat 1 20

You can use vmstat to gather basic disk usage information

vmstat -d 1 20

Other useful tool for gathering disk usage information is iostat

iostat 1 20

You can narrow down monitoring to specific device. For example sda

ipstat -d -p sda 1 20

3. Historical resource usage 
SAR or system activity report can look back in time and see how system was performing. In order to enable SAR, you must have running cron job service to gather stats. Also sysstat package must  be already  installed.
Edit /etc/default/sysstat

ENABLED="true"
service sysstat restart 

By default it will collect stats every 10 min and use cron job /etc/cron.d/sysstat. This time span can be changed.
How to use SAR to view CPU stats:

sar -u

How to use SAR to view memory stats:

sar -r

To check IO stats of your server use:

sar -b

 


Was this answer helpful?

« Back