Home > Apache, bash, CentOS, Linux, RHEL, Slackware > Linux bash: get the Apache PID with high CPU consumtion and extract the URL

Linux bash: get the Apache PID with high CPU consumtion and extract the URL

make sure you have the extended status on and the http://localhost/server-status is accessible

#!/bin/sh
# by dragkh
# Wed Apr 06 12:33:56

# Config
CPU_LIMIT=10
TOP_PROCESSES=10
LOG_FILE=/var/log/high.CPU.apache.URLs.log

top -b -U apache  -n 1 | \
grep -v grep | \
grep apache  | \
sort -rn -k9 | \
head  -${TOP_PROCESSES} | \
awk -v CPU_LIMIT=${CPU_LIMIT} '($9 > CPU_LIMIT){print $0}' | \
while read PID USER      PR  NI  VIRT  RES  SHR S CPU MEM    TIME  COMMAND
do 
  echo -n "$(date) :[$HOSTNAME]: PID[${PID}]:CPU[${CPU}] : Apache => " >> ${LOG_FILE}
  links -dump http://localhost/server-status | grep -v grep | grep "${PID}" >> ${LOG_FILE}
done

Advertisements
  1. No comments yet.
  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: