• Log inStart now

Use TCP endpoint to forward logs to New Relic

We offer a wide range of solutions to get your log data into New Relic. But in other situations where you don't have log forwarders (such as CDNs, hardware devices, or managed services), you can use syslog protocols via a TCP endpoint. You can forward your logs to New Relic using syslog clients such as rsyslog and syslog-ng.

Compatibility and requirements

To forward logs to New Relic using a syslog client, you need:

  • A valid New Relic license key for the account you want to send logs to
  • Some minor changes to the syslog client's configuration, as explained in this document

Configure rsyslog versions 8 and higher (Amazon Linux, Redhat, Centos)

Important

If you're using an EU region account you should use newrelic.syslog.eu.nr-data.net as the endpoint, instead of newrelic.syslog.nr-data.net. Don't forget to replace it on the configuration files, using the US endpoint for EU account will not work.

To forward logs to New Relic with rsyslog for Amazon Linux, Redhat, and Centos distributions:

  1. Install packages required to allow rsyslog to send logs using TLS encryption:

    bash
    $
    sudo yum install rsyslog-gnutls ca-certificates
  2. Optional: Configure rsyslog to tail log files and forward their contents to New Relic. Add the following to the /etc/rsyslog.conf file in order to enable its text file input module:

    module(load="imfile"
    PollingInterval="10"
    )
  3. In the /etc/rsyslog.d/ directory, create a text file named newrelic.conf.

  4. Check whether the $IncludeConfig options under /etc/rsyslog.conf already have a matching wildcard that will include the newly created newrelic.conf file under the /etc/rsyslog.d directory. Otherwise you'll need to explicitly include /etc/rsyslog.d/newrelic.conf in /etc/rsyslog.conf using $IncludeConfig /etc/rsyslog.d/newrelic.conf

  5. Add the following to newrelic.conf. Replace the highlighted values. For YOUR_LICENSE_KEY, use your New Relic license key:

    ## Specify each of the files to be tailed in case step 1 is done
    
    input(type="imfile" Tag="YOUR_FILE_TAG" File="PATH_TO_FILE" 
    
    ## Template expected by the New Relic Syslog endpoint
    
    template(name="newrelic-rfc5424"
             type="string"
             string="YOUR_LICENSE_KEY <%pri%>%protocol-version% %timestamp:::date-rfc3339% %hostname% %app-name% %procid% %msgid% %structured-data% %msg%\n"
    )
    
    ## Configure TLS and log forwarding
    
    global(DefaultNetstreamDriver="gtls"
           DefaultNetstreamDriverCAFile="/etc/ssl/certs/ca-certificates.crt"
    )
    
    action(type="omfwd"
           Target="newrelic.syslog.nr-data.net"
           Port="6514"
           Protocol="tcp"
           Template="newrelic-rfc5424"
           ResendLastMSGOnReconnect="on"
           StreamDriver="gtls"
           StreamDriverAuthMode="x509/name"
           StreamDriverPermittedPeers="*.syslog.nr-data.net"
           StreamDriverMode="1"
    )
  6. Restart the rsyslog service by running:

    bash
    $
    sudo systemctl restart rsyslog
  7. Check your New Relic account for logs.

Configure rsyslog versions 8 and above with compression (Amazon Linux, Redhat, Centos)

To configure rsyslog versions 8 and above for Amazon Linux, Redhat, and Centos distributions:

  1. Follow steps 1 to 4 described in configure rsyslog.

Important

Note the configured port number is 6516 instead of 6514.

  1. Add the following to newrelic.conf. Replace all highlighted values. For YOUR_LICENSE_KEY, use your New Relic license key:

    ## Specify each of the files to be tailed in case step 1 is done
    
    input(type="imfile" Tag="YOUR_FILE_TAG" File="PATH_TO_FILE"
    
    ## Template expected by the New Relic Syslog endpoint
    
    template(name="newrelic-rfc5424"
             type="string"
             string="YOUR_LICENSE_KEY <%pri%>%protocol-version% %timestamp:::date-rfc3339% %hostname% %app-name% %procid% %msgid% %structured-data% %msg%\n"
    )
    
    ## Configure TLS and log forwarding
    
    global(DefaultNetstreamDriver="gtls"
           DefaultNetstreamDriverCAFile="/etc/ssl/certs/ca-certificates.crt"
    )
    
    action(type="omfwd"
           Target="newrelic.syslog.nr-data.net"
           Port="6516"
           Protocol="tcp"
           Template="newrelic-rfc5424"
           ResendLastMSGOnReconnect="on"
           StreamDriver="gtls"
           StreamDriverAuthMode="x509/name"
           StreamDriverPermittedPeers="*.syslog.nr-data.net"
           StreamDriverMode="1"
           compression.Mode="stream:always"
    )
  2. Restart the rsyslog service by running:

    bash
    sudo systemctl restart rsyslog
  3. Check your New Relic account for logs.

Legacy config file for rsyslog versions 7 or lower (Amazon Linux, Redhat, Centos)

If you're using rsyslog version 7 or below, the configuration files need to be adapted to the obsolete legacy format. This format is only kept for retro compatibility purposes. We strongly recommend to avoid using it, as stated in the rsyslog documentation. To configure logs for Amazon Linux, Redhat, and Centos distributions:

  1. Install packages required to allow rsyslog to send logs using TLS encryption:

    bash
    sudo yum install rsyslog-gnutls ca-certificates
  2. Optional: Configure rsyslog to tail log files and forward their contents to New Relic. Add the following to the /etc/rsyslog.conf file in order to enable its text file input module:

    $ModLoad imfile
    $InputFilePollInterval 10
    $PrivDropToGroup adm
    $WorkDirectory /var/spool/rsyslog
  3. In the /etc/rsyslog.d/ directory, create a text file named newrelic.conf.

  4. Check whether the $IncludeConfig options under /etc/rsyslog.conf already have a matching wildcard that will include the newly created newrelic.conf file under the /etc/rsyslog.d directory. Otherwise you'll need to explicitly include /etc/rsyslog.d/newrelic.conf in /etc/rsyslog.conf using $IncludeConfig /etc/rsyslog.d/newrelic.conf.

  5. Add the following to newrelic.conf. Replace the highlighted values. For YOUR_LICENSE_KEY, use your New Relic license key:

    ## Template expected by the New Relic Syslog endpoint
    
    $template NRLogFormat,"YOUR_LICENSE_KEY <%pri%>%protocol-version% %timestamp:::date-rfc3339% %hostname% %app-name% %procid% %msgid% %structured-data% %msg%\n"
    
    ## Specify each of the files to be tailed in case step 1 is done
    
    $InputFileName /path/to/file
    $InputFileTag YOUR_FILE_TAG
    $InputFileSeverity info
    $InputRunFileMonitor
    
    ## Configure TLS and log forwarding
    
    $DefaultNetstreamDriverCAFile /etc/ssl/certs/ca-certificates.crt
    $ActionSendStreamDriver gtls
    $ActionSendStreamDriverMode 1
    $ActionSendStreamDriverAuthMode x509/name
    $ActionSendStreamDriverPermittedPeer *.syslog.nr-data.net
    
    *.* @@newrelic.syslog.nr-data.net:6514;NRLogFormat
  6. Restart the rsyslog service by running:

    bash
    $
    sudo systemctl restart rsyslog
  7. Check your New Relic account for logs.

Configure syslog-ng

To forward logs to New Relic with syslog-ng:

  1. Install ca-certificates required to allow syslog-ng to send logs using TLS encryption:

    bash
    sudo yum install ca-certificates
  2. Open the syslog-ng configuration file (/etc/syslog-ng/syslog-ng.conf) in a text editor.

  3. Define the sources to be monitored by adding:

    source s_src {
    internal();
    };
  4. Optional: Configure syslog-ng to tail files by adding the following to the Sources configuration block:

    source s_files {
            file("PATH_TO_FILE");
    };
  5. Define the New Relic syslog format. For YOUR_LICENSE_KEY, use your New Relic license key.

    template NRFormat { template("YOUR_LICENSE_KEY <${PRI}>1 ${ISODATE} ${HOST:--} ${PROGRAM:--} ${PID:--} ${MSGID:--} ${SDATA:--} $MSG\n");
            template_escape(no);
    };
  6. Add the New Relic Syslog endpoint:

    destination d_newrelic {
    network("newrelic.syslog.nr-data.net" port(6514)
    transport("tls")
    tls(peer-verify(no))
    template(NRFormat)
    );
    };
  7. Add the following output to the log path configuration block:

    log {
    source(s_src);
    source(s_files); ## in case step 4 is implemented.
    destination(d_newrelic);
    };
  8. Restart syslog-ng by running:

    bash
    $
    sudo service syslog-ng restart
  9. Check your New Relic account for logs.

Tip

If you're running syslog-ng from a Docker container and experience issues, check balait/syslog image documentation.

Copyright © 2022 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.