Skip to content

Commit

Permalink
include monit configration (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
hobbyquaker committed May 13, 2019
1 parent 729232c commit 5535cd6
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
19 changes: 19 additions & 0 deletions addon_files/redmatic/bin/monit-du.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

FOLDER_PATH=/usr/local/addons/redmatic

REFERENCE_SIZE=$1

#calculate size of folder
SIZE=$(/usr/bin/du -s $FOLDER_PATH | /usr/bin/awk '{print $1}')

#convert size to MB
MBSIZE=$((SIZE / 1024))

#output size so Monit can capture it
echo "$FOLDER_PATH disk $MBSIZE MB usage [$REFERENCE_SIZE MB allowed]"

#provide status code for alert
if [[ $MBSIZE -gt $(( $REFERENCE_SIZE )) ]]; then
exit 1
fi
13 changes: 13 additions & 0 deletions addon_files/redmatic/bin/redmatic
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ export GIT_EXEC_PATH=/usr/local/addons/redmatic/libexec/git-core
export NO_UPDATE_NOTIFIER=true

Stop () {
if [ -f /usr/bin/monit ]; then
/usr/bin/monit -g redmatic unmonitor
fi

PSPID=`ps -o pid,comm,args | awk '{if($3 == "node-red" || $4 ~ /node-red/){print $1}}'`
if [ "$PSPID" != "" ]
then
echo -n "Stopping Node-RED: "
logger -t redmatic -p daemon.info "Stopping Node-RED"

killall redmaticLoader 2>/dev/null
kill -SIGINT $PSPID 2>/dev/null
sleep 2
Expand Down Expand Up @@ -125,6 +130,10 @@ Start () {
start-stop-daemon -S -q -b --exec $ADDON_DIR/bin/redmaticLoader
echo "OK"
fi

if [ -f /usr/bin/monit ]; then
(sleep 60 ; /usr/bin/monit -g redmatic monitor) &
fi
}

case "$1" in
Expand Down Expand Up @@ -162,6 +171,10 @@ case "$1" in
rm $CONF_DIR/lighttpd/redmatic.conf
rm $CONF_DIR/rc.d/redmatic

if [ -f /usr/local/etc/redmatic-monit.cfg ]; then
rm /usr/local/etc/redmatic-monit.cfg
fi

mount -o remount,rw /
if [ -f $LIGHTTPD_CONF.orig ]
then
Expand Down
22 changes: 22 additions & 0 deletions addon_files/redmatic/etc/monit.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
CHECK PROCESS redmatic-nodered MATCHING '^node-red\s*$'
GROUP redmatic
MODE PASSIVE
ONREBOOT NOSTART

if memory usage > 200 MB then alert
if cpu > 90% for 2 cycles then alert
if disk write rate > 1 MB/s for 2 cycles then alert
if failed
host localhost
port 1880
protocol http
request "/addons/red/"
then alert

CHECK PROGRAM redmatic-diskusage with path "/usr/local/addons/redmatic/bin/monit-du.sh 512"
GROUP redmatic
MODE PASSIVE
ONREBOOT NOSTART
every "23 3 * * *"
if status != 0 then alert

7 changes: 7 additions & 0 deletions addon_files/update_script
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,12 @@ rm $RED_DIR/libexec/git-core.tar.gz
touch $CONF_DIR/hm_addons.cfg
./update_addon redmatic redmatic.cfg

#
# Link monit configuration
#
if [ -f /usr/bin/monit ]; then
ln -s $RED_DIR/etc/monit.cfg /usr/local/etc/monit-redmatic.cfg
fi

sync
exit 0

0 comments on commit 5535cd6

Please sign in to comment.