added a sample httpd monitoring script

This commit is contained in:
hyung-hwan 2016-01-20 04:06:51 +00:00
parent c51f44ec8c
commit b4e5f574e5
4 changed files with 59 additions and 2 deletions

View File

@ -68,6 +68,7 @@ rm -rf $RPM_BUILD_ROOT
/var/www/html/codepot /var/www/html/codepot
/usr/sbin/codepot-user /usr/sbin/codepot-user
/usr/sbin/codepot-mon-httpd
%config(noreplace) /etc/codepot/codepot.ini %config(noreplace) /etc/codepot/codepot.ini
/etc/codepot/codepot.mysql /etc/codepot/codepot.mysql

View File

@ -1,4 +1,4 @@
sbin_SCRIPTS = codepot-user sbin_SCRIPTS = codepot-user codepot-mon-httpd
EXTRA_DIST = $(sbin_SCRIPTS) EXTRA_DIST = $(sbin_SCRIPTS)

View File

@ -139,7 +139,7 @@ sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@ sysconfdir = @sysconfdir@
target_alias = @target_alias@ target_alias = @target_alias@
wwwdir = @wwwdir@ wwwdir = @wwwdir@
sbin_SCRIPTS = codepot-user sbin_SCRIPTS = codepot-user codepot-mon-httpd
EXTRA_DIST = $(sbin_SCRIPTS) EXTRA_DIST = $(sbin_SCRIPTS)
all: all-am all: all-am

View File

@ -0,0 +1,56 @@
#!/bin/sh
#
# This is just a sample script for httpd resource monitoring
# While this is inside the codepot distro, it's not supposed
# to be used without consideration of the actual environment.
#
DAEMON=0
THRESHOLD=1024
if [ "$1" = "-daemon" ]
then
($0 --daemon </dev/null >/dev/null 2>&1 &) &
#($0 --daemon &) &
exit 0
elif [ "$1" = "--daemon" ]
then
DAEMON=1
fi
while true
do
sleep 5
ps -ylC httpd | awk -vdaemon=$DAEMON -v"self=$0" -vthreshold=$THRESHOLD '
{
x += $8;
y += 1;
}
END {
MB = x / 1024;
AVGMB = x / ((y - 1) * 1024);
if (daemon <= 0)
{
print "Apache Memory Usage (MB): " MB;
print "Average Proccess Size (MB): " AVGMB;
if (MB > int(threshold))
{
system ("/etc/init.d/httpd restart");
}
}
else
{
if (MB > int(threshold))
{
system (sprintf ("logger -t \"%s\" \"Restarting httpd for excess memory usage [%s/%d]\"", self, MB, threshold));
system ("/etc/init.d/httpd restart >/dev/null 2>&1 </dev/null");
}
}
}
'
done