Finding Load causing connections and users

By default dcpumon runs every 5 min to log CPU usage (“top” output) and stores the data into /var/log/dcpumon

# crontab -l | fgrep cpu
*/5 * * * * /usr/local/cpanel/bin/dcpumon >/dev/null 2>&1
#

You can view the report with “dcpumonview” command:

# /usr/local/cpanel/bin/dcpumonview

———————————————————–———————————————–
|User |Domain |CPU%|MEM%|MySQL#     |
———————————————————–———————————————–
|test |test.net |17.72|37.07|0.3  |
| Top Process | 27.8 | /usr/bin/php |
| Top Process | 14.2 | /usr/bin/php |
| Top Process | 12.3 | /usr/bin/php |
|mysql | |11.47|3.05|0.0            |
| Top Process | 11.7 | /usr/sbin/mysqld –basedir/ –datadir/var/lib/mysql –usermysql –pid-file/var/lib/mysql/alekz.pid –skip-external-locking |

To check number of IPs connected to port 80

netstat -tn 2>/dev/null | grep ‘:80 ‘ | awk ‘{print $5}’ |sed -e ‘s/::ffff://’ | cut -f1 -d: | sort | uniq -c | sort -rn | head

To list number of connections to domains in the server

/usr/bin/lynx -dump -width 500 http://127.0.0.1/whm-server-status | awk  ‘BEGIN { FS = ” ” } ; { print $12 }’ | sed ‘/^$/d’ | sort | uniq -c | sort -n

To list the Busiest Site in the server

/usr/bin/lynx -dump -width 500 http://127.0.0.1/whm-server-status | grep GET | awk ‘{print $12}’ | sort | uniq -c | sort -rn | head

To list the Busiest Script running on the server

/usr/bin/lynx -dump -width 500 http://127.0.0.1/whm-server-status | grep GET | awk ‘{print $14}’ | sort | uniq -c | sort -rn | head

To list the most running process in the server

ps aux | awk ‘{print $1}’ | sort | uniq -c | sort -nk1 | tail -n5

To list the total process running by the users

ps aux | awk ‘{print $1}’ | sort | uniq -c | sort -nk1

When we see the process in the top result with “php” or “/usr/bin/php”, we can find the directory it is working with. You can use,

for i in `ps -ef | awk ‘/php/{print $2}’`; do ls -l /proc/${i}/cwd; done

We can even check this dynamically with in a particular time limit, say 5 sec. We can use it as below.

while true; do clear; for i in `ps -ef | awk ‘/php/{print $2}’`;do ls -l /proc/${i}/cwd; done; sleep 5; done

Advertisements
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: