#
# monitoring mediaprocessing
#

# Check services
check process mediaprocessing with pidfile /opt/bertin/mediacentric/var/run/mediacentric-mediaprocessing.pid
	start program = "/usr/sbin/service mediacentric-mediaprocessing start" with timeout 20 seconds
	stop program = "/usr/sbin/service mediacentric-mediaprocessing stop"
	if NOT EXIST for 2 times within 5 cycles
		then exec "/opt/bertin/mediacentric/bin/monit_alert.sh mediacentric-mediaprocessing KO"
	else if SUCCEEDED
		then exec "/opt/bertin/mediacentric/bin/monit_alert.sh mediacentric-mediaprocessing OK"

check program mediaprocessing_check_queue_size with path "/opt/bertin/mediacentric/bin/check_queue_size.sh text_processing 10000"
	if status = 1 for 1 cycles then exec "/opt/bertin/mediacentric/bin/restart_service.sh mediacentric-mediaprocessing 'slow text_processing'"

check program mediaprocessing_check_module_rabbitQ with path "/opt/bertin/mediacentric/bin/check_module_rabbitQ.sh mediacentric-mediaprocessing"
	if status = 1 for 3 cycles then exec "/opt/bertin/mediacentric/bin/restart_service.sh mediacentric-mediaprocessing 'no rabbit consumer'"

# Check pattern in logs
check file mediaprocessing_log with path /opt/bertin/mediacentric/logs/mediaprocessing.log
	if match "java.lang.OutOfMemoryError" then exec "/opt/bertin/mediacentric/bin/monit_alert_logs.sh mediacentric-mediaprocessing OutOfMemory" repeat every 1 cycle
	if match "Too many open files" then exec "/opt/bertin/mediacentric/bin/monit_alert_logs.sh mediacentric-mediaprocessing TooManyOpenFiles" repeat every 1 cycle
