Fluentd plugin for log forwarding

New Relic offers a Fluentd output plugin to connect your Fluentd monitored log data to New Relic. Read on to learn how to enable this feature.

Compatibility and requirements

To forward logs to New Relic using Fluentd, ensure your configuration meets the following requirements:

Enable Fluentd for New Relic log management

To enable log management with Fluentd:

  1. Install the Fluentd plugin.
  2. Configure the Fluentd plugin.
  3. Test the Fluentd plugin.
  4. Optional: Configure additional plugin attributes.
  5. Generate some traffic and wait a few minutes, then check your account for data.

Install the Fluentd plugin

To install the Fluentd plugin:

Install using fluent-gem install

To install using fluent-gem install, enter the following command into your terminal or command line interface:

fluent-gem install fluent-plugin-newrelic
Install using td-agent-gem

To install using the td-agent plugin, enter the following command into your terminal or command line interface:

td-agent-gem install fluent-plugin-newrelic

Configure the Fluentd plugin

NOTE: If you're configuring Fluentd for the first time, you may find it helpful to review our collection of pre-built configuration files addressing common use cases.

To configure your Fluentd plugin:

  1. In your fluent.conf file, or td-agent.conf if using the td-agent, add the following block of data, replacing the placeholder text with your Insert API key(recommended) or New Relic license key.

    Configure with the New Relic Insert API key (recommended)

    Configure with the New Relic Insert API key:

    #Tail one or more log files 
    <source>
      @type tail
      <parse>
        @type none
      </parse>
      path /path/to/file
      tag example.service
    </source>
    
    #Add hostname and service_name to all events with "example.service" tag
    <filter example.service>
      @type record_transformer
      <record>
        service_name ${tag}
        hostname "#{Socket.gethostname}"
      </record>
    </filter>
    
    #Forward all events to New Relic
    <match **>
      @type newrelic
      api_key YOUR_API_INSERT_KEY
    </match>
    
    Configure with the New Relic license key

    Configure with the New Relic license key:

    #Tail one or more log files 
    <source>
      @type tail
      <parse>
        @type none
      </parse>
      path /path/to/file
      tag example.service
    </source>
    
    #Add hostname and service_name to all events with "example.service" tag
    <filter example.service>
      @type record_transformer
      <record>
        service_name ${tag}
        hostname "#{Socket.gethostname}"
      </record>
    </filter>
    
    #Forward all events to New Relic
    <match **>
      @type newrelic
      license_key YOUR_LICENSE_KEY
    </match>
    
  2. Restart the Fluentd service to ensure your changes are applied.

Test the Fluentd plugin

To test if your Fluentd plugin is receiving input from a log file:

  1. Run the following command to append a test log message to your log file:

    echo "test message" >> /PATH/TO/YOUR/LOG/FILE
  2. Search New Relic Logs UI for test message.

Optional configuration

Once you have installed and configured the Fluentd plugin, you can use the following attributes to configure how the plugin sends data to New Relic:

Property Description Default value
base_uri The New Relic ingestion endpoint. US endpoint: https://log-api.newrelic.com/log/v1
EU endpoint: https://log-api.eu.newrelic.com/log/v1

For more information and examples, see Example Configurations for Fluentd.

View log data

If everything is configured correctly and your data is being collected, you should see data logs in both of these places:

What's next?

Now that you've enabled Logs, here are some potential next steps:

If no data appears after you enable New Relic Logs, follow the troubleshooting procedures.

For more help