Auto restart newrelic-daemon if crashed
On a web server with Newrelic APM installed, graph stopped showing new data. On checking the newrelic log file, i get following error
1 2 |
root@new-website-2:~# tail -f /var/log/newrelic/php_agent.log 2021-02-08 17:21:27.453 +0000 (680439 680439) warning: daemon connect(fd=13 uds=@newrelic) returned -1 errno=ECONNREFUSED. Failed to connect to the newrelic-daemon. Please make sure that there is a properly configured newrelic-daemon running. For additional assistance, please see: https://newrelic.com/docs/php/newrelic-daemon-startup-modes |
This is because newrelic-daemon stopped working. To auto restart newrelic-daemon if it crash, do the following
1 2 |
mkdir -p /usr/serverok vi /usr/serverok/newrelic |
Add following to the file
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#!/bin/bash # Author: ServerOK # Web: https://serverok.in/auto-restart-newrelic-daemon CURRENT_STATUS="$(/etc/init.d/newrelic-daemon status)" TIME_STAMP="$(date "+%Y-%m-%d %H:%M:%S")" if [[ ! "${CURRENT_STATUS}" =~ "newrelic-daemon is running" ]] then /etc/init.d/newrelic-daemon start echo -e "${TIME_STAMP} newrelic-daemon down\n" fi |
Make the script executable
1 |
chmod 755 /usr/serverok/newrelic |
Create a cronjob
1 |
crontab -e |
Add following cronjob
1 |
*/5 * * * * /usr/serverok/newrelic > /var/log/newrelic/monitor.log 2>&1 |
See Server Monitoring, Application Performance Monitor (APM)