Tag: newrelic

  • 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

    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

    mkdir -p /usr/serverok
    vi /usr/serverok/newrelic
    

    Add following to the file

    #!/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

    chmod 755 /usr/serverok/newrelic 
    

    Create a cronjob

    crontab -e
    

    Add following cronjob

    */5 * * * * /usr/serverok/newrelic > /var/log/newrelic/monitor.log 2>&1
    

    See Server Monitoring, Application Performance Monitor (APM)

  • Moving from Apache PHP 5 to Nginx PHP 7

    Moving from Apache PHP 5 to Nginx PHP 7

    Today i moved a high traffic WordPress web using from Apache + PHP 5 to Nginx + PHP 7.2.

    Here is a graph provided by LiquidWeb (server provider).

    With Apache, load was like 8.

    root@host:/etc/php# uptime
    12:35:01 up 14:33, 1 user, load average: 8.03, 6.66, 5.84
    root@host:/etc/php#

    After switching to Nginx + PHP-FPM, load come down to 2.

    root@host:~# uptime
    17:26:20 up 19:24, 1 user, load average: 1.13, 1.07, 1.21
    root@host:~#

    Here is sar result.

    With Apache idle CPU was approx 72. With Nginx we have 90%+ idle CPU most of the time.

    Here is NewRelic Web transactions graph. The break in data is due to PHP 7.2 have no newrelic module installed. So i just switched back to Apache for a while, reinstalled NewRelic for PHP 7.2, then turned Nginx back on.

    NewRelic Apdex Score went from poor to fair.