Last active
June 23, 2020 14:52
-
-
Save teopost/41d2ea849422243075dbd3f4ba791ab7 to your computer and use it in GitHub Desktop.
Installer nmon as a service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# nmon as a service | |
# installer script for red-hat 7.5 | |
yum install -y nmon | |
if [ $? -eq 1 ]; then | |
# Download NMON archive | |
cd /tmp | |
wget http://sourceforge.net/projects/nmon/files/nmon16e_mpginc.tar.gz | |
# Untar archive | |
tar -xzvf nmon16e_mpginc.tar.gz | |
# Copy nmon file | |
cp nmon_x86_64_centos7 /usr/bin/nmon | |
chmod a+x /usr/bin/nmon | |
# tidy up tmp | |
echo "Clean /tmp directory manually: rm -f nmon_* " | |
fi | |
curl https://gist.githubusercontent.com/teopost/41d2ea849422243075dbd3f4ba791ab7/raw/nmon_initd_rhel --output /etc/init.d/nmon | |
chown root:root /etc/init.d/nmon | |
chmod 755 /etc/init.d/nmon | |
curl https://gist.githubusercontent.com/teopost/41d2ea849422243075dbd3f4ba791ab7/raw/nmon_logrotated --output /etc/logrotate.d/nmon | |
chown root:root /etc/logrotate.d/nmon | |
chmod 644 /etc/logrotate.d/nmon | |
chkconfig --add nmon | |
service nmon start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# /etc/init.d/nmon | |
# | |
# chkconfig: 345 70 55 | |
# description: nmon init script | |
# Source function library. | |
. /etc/init.d/functions | |
NMON=/usr/bin/nmon | |
LOGDIR=/var/log/nmon | |
PIDFILE=/var/run/nmon.pid | |
if [ ! -d $LOGDIR/old ]; then | |
# old for logrotated | |
mkdir -p $LOGDIR/old | |
chown root:root $LOGDIR | |
chmod -R 755 $LOGDIR | |
fi | |
if [ ! -e $NMON ]; then | |
exit 5 | |
fi | |
# collect NMON data every INTERVAL seconds | |
INTERVAL=30 | |
# assume /etc/logrotate.d/nmon will restart nmon once a day | |
# run for 1 day + 1 hour since anacron randomizes when logrotate runs | |
COUNT=$(( (86400 + 3600) / $INTERVAL )) | |
FILENAME=`hostname`.nmon | |
start() { | |
if [ -f $PIDFILE ]; then | |
action "Already running!" true | |
return 0; | |
else | |
$NMON -F $FILENAME -T -s 30 -c $COUNT -m $LOGDIR -p > $PIDFILE | |
# just assume nmon started ok; exectue true so the output is correct | |
action $"Starting nmon: " true | |
touch /var/lock/subsys/nmon | |
return 0 | |
fi | |
} | |
stop() { | |
if [ -f $PIDFILE ]; then | |
action "Shutting down nmon: " kill -s USR2 `cat /var/run/nmon.pid` 2> /dev/null | |
else | |
action "Shutting down nmon: " killall -s USR2 $NMON 2> /dev/null | |
fi | |
rm -f /var/lock/subsys/nmon | |
rm -f $PIDFILE | |
return 0 | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
stop | |
start | |
;; | |
status) | |
status nmon | |
;; | |
*) | |
echo "Usage: nmon {start|stop|restart|status}" | |
exit 1 | |
;; | |
esac | |
exit $? | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/var/log/nmon/*.nmon { | |
olddir old | |
daily | |
rotate 15 | |
size 0 | |
nocreate | |
nocopy | |
nomail | |
missingok | |
extension .nmon | |
sharedscripts | |
prerotate | |
service nmon stop | |
endscript | |
postrotate | |
service nmon start | |
endscript | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment