Forwarding your logs to New Relic makes all of your logging data available in one location, providing deeper visibility into both your application and your platform performance data. With your logs in one spot, you can collect, process, explore, query, and alert on errors or anomalies found in your log data.
From your host's UI, your logs are placed in context of events for the selected time period. You can drill down into detailed data for any of the highlighted attributes.
How you forward your logs depends on how you installed the infrastructure agent, since the infrastructure agent enables the log forwarding feature. You can install the infrastructure agent via:
Guided install (recommended for most users)
Manual installation
Linux tarball
Important
The Linux version of infrastructure agent, specifically version 1.42.0, has transitioned from using the td-agent-bit package to the fluent-bit package. This change was necessitated by the fact that fluent-bit is no longer distributed in the td-agent-bit flavour after the major version 2.x update.
To ensure smooth operations and provide the option to revert to td-agent-bit in the event of any issues with the fluent-bit package, the infrastructure agent now installs both packages (td-agent-bit and fluent-bit). By default, the agent is configured to use fluent-bit.
Fluent Bit. The infrastructure agent already installs the latest version for you. To update or downgrade it to a specfic version, refer to the Fluent Bit installation procedures.
OpenSSL library 1.1.0 or higher
Built-in support for ARM64 architecture on Linux systems (for example, AWS Graviton architecture) added in infrastructure agent 1.20.6.
Amazon Linux 2 and 2023
CentOS version 8 and 9 Stream (Rocky Linux and AlmaLinux are also supported)
RedHat version 8 and 9
Debian version 11 (Bullseye) and 12 (Bookworm).
SUSE Linux Enterprise Server (SLES) version 12 and 15 (ARM64 not supported).
Windows Server 2016, 2019, and 2022, and their service packs.
Windows 10, Windows 11.
Automatically forward logs with guided install
When you use our guided install to install the infrastructure agent, the log forwarding feature is automatically configured during the install process.
To initiate your install, choose your deployment method:
To forward logs from a Docker container, use this Docker image as the base image to be used with kubernetes logs integration, or you can build your own container with custom configurations for different environments.
Configuration files direct your system to forward the log sources you want to appear in New Relic. You can add as many config files as you want. Our infrastructure agent uses .yml files to configure logging. If you install the infrastructure agent via Integrations & Agents in the UI, the file logging.yml is created automatically.
To add a new configuration file for the log forwarding feature:
Navigate to the log forwarder configuration folder:
Create a logging.yml configuration file, and add the parameters you need. The logging.d directory has various .yml.example files you can use as a reference or starting point. For Windows examples, see our Github repo.
# Log forwarder configuration file example
# Source: file
# Available customization parameters: attributes, max_line_kb, pattern
logs:
# Basic tailing of a single file
-name: basic-file
file: /var/log/logFile.log
# File with spaces in its path. No need to use quotes.
-name: file-with-spaces-in-path
file: /var/log/folder with spaces/logFile.log
# Specify a list of custom attributes, as key-value pairs, to be included
# in each log record
-name: file-with-attributes
file: /var/log/logFile.log
attributes:
application: tomcat
department: sales
maintainer: example@mailprovider.com
# Use wildcards to refer to multiple files having a common extension or
# prefix. Newly generated files will be automatically detected every 60
# seconds.
#
# WARNING: avoid using wildcards that include the file extension, since
# it'll cause logs to be forwarded repeatedly if log rotation is enabled.
-name: log-files-in-folder
file: /var/log/logF*.log
# Lines longer than 128 KB will be automatically skipped. Use 'max_line_kb'
# to increase this limit.
-name: log-file-with-long-lines
file: /var/log/logFile.log
max_line_kb:256
# Use 'pattern' to filter records using a regular expression
-name: only-records-with-warn-and-error
file: /var/log/logFile.log
pattern: WARN|ERROR
The agent automatically processes new configuration files without having to restart the infrastructure monitoring service. The only exception to this is when configuring a custom Fluent Bit configuration.
Step 2. Set log forwarding parameters
You're required to set up a name and log source parameter in the log forwarding .yml config file. To start, define a name of the log or logs you want to forward to New Relic.
What you use for the log source depends on the location your logs are sourced from. Available options for the log source include:
Path to the log file or files. The agent tracks changes on the log files in a way similar to tail -f shell.
Example:
logs:
-name: example-log
file: /var/log/example.log # Path to a single log file
-name: example-log-two
file: /var/log/example-two.log # Path to another single log file
The file parameter can point to a specific log file or multiple files by using wildcards applied to names and extensions; for example, /logs/*.log. You can use wildcards in place of directories in a file path, which can be used to tail files located in different directories.
Example:
logs:
-name: docker-logs
file: /var/lib/docker/containers/*/*.log# Path to multiple folders and files
Important
Use of wildcards may significantly increase the number of file descriptors and inotify watches the Fluent Bit process keeps open, which can interfere with log collection if the host's file descriptor limit is reached. Tailing a large number of files may require you to increase the maximum number of file descriptors and inotify watchers allowed by the operating system. Please refer to Errors when tailing a large amount of log files for more details on how to increase them.
Use the systemd parameter to forward log messages that are collected by the journald daemon in Linux environments. This input type requires the agent to run in root mode.
Example:
logs:
-name: systemd-example
systemd: cupsd
Syslog data source.
Parameters:
uri: Syslog socket. Format varies depending on the protocol:
parser: Syslog parser. Default is rfc3164. Use rfc5424 if your messages include fractional seconds. Note: rfc3164 currently does not work on SuSE.
unix_permissions: Default is 0644 for domain sockets. This limits entries to processes running as root. You can use 0666 to listen for non-root processes (at your own risk).
When running the agent in privileged mode, ports and sockets must be available or owned by nri-agent and with 0666 file permissions so that other processes can write logs to the sockets.
logs:
# TCP network socket
-name: syslog-tcp-test
syslog:
uri: tcp://0.0.0.0:5140# Use the tcp://LISTEN_ADDRESS:PORT format
parser: rfc5424 # Default syslog parser is rfc3164
# UDP network socket
-name: syslog-udp-test
syslog:
uri: udp://0.0.0.0:6140# Use the udp://LISTEN_ADDRESS:PORT format
max_line_kb:35
# Unix TCP domain socket
-name: syslog-unix-tcp-test
syslog:
uri: unix_tcp:///var/unix-tcp-socket-test
unix_permissions:0666# Default is 0644. Change at your own risk
# Unix UDP domain socket
-name: syslog-unix-udp-test
syslog:
uri: unix_udp:///var/unix-udp-socket-test
parser: rfc5424
Logs retrieved over TCP connections.
Parameters:
uri: TCP/IP socket to listen for incoming data. The URI format is tcp://LISTEN_ADDRESS:PORT.
format: Format of the data. It can be json or none.
separator: If format: none is used, you can define a separator string for splitting records (default: \n).
logs:
-name: tcp-simple-test
tcp:
uri: tcp://0.0.0.0:1234# Use the tcp://LISTEN_ADDRESS:PORT format
format: none # Raw text - this is default for 'tcp'
separator: \t # String for separating raw text entries
max_line_kb:32
-name: tcp-json-test
tcp:
uri: tcp://0.0.0.0:2345# Use the tcp://LISTEN_ADDRESS:PORT format
format: json
Important
Available since infrastructure agent v.1.24.3
Only compatible with Windows Server 2019 and later. Use winlog instead for prior versions.
Collect event from Windows log channels using new Windows Event Log API using the winevtlog Fluent Bit plugin.
Parameters:
channel: Name of the channel logs will be collected from.
collect-eventids: List of Windows Event IDs to be collected and forwarded to New Relic. Event ID ranges are supported.
exclude-eventids: List of Windows Event IDs to be excluded from collection. Event ID ranges are supported.
use-ansi: Use ANSI encoding on winlog messages. We use ANSI encoding by default on Windows Server 2016 and older versions, and UTF-8 on newer ones. You can override this behavior with this configuration parameter if these defaults do not suit your use case. This solves the problem of ANSI character code logs being empty strings. It's not a function to convert multi-byte character code logs in ANSI character code to UTF-8.
All events are collected from the specified channel by default. Configure the collect-eventids and exclude-eventids sections to avoid sending unwanted logs to your New Relic account.
Add event IDs or ranges to collect-eventids or exclude-eventids to forward or drop specific events. exclude-eventids takes precedence over collect-eventids if the same event ID is present in both sections.
Example:
logs:
# Example winevtlog security log ingestion with eventId filters.
-name: windows-security
winevtlog:
channel: Security
collect-eventids:
-4624
-4265
- 4700-4800
exclude-eventids:
-4735
attributes:
logtype: windows_security
# Example entries for the application and system channels
-name: windows-application
winevtlog:
channel: Application
attributes:
logtype: windows_application
# Example entries for the application use-ansi
-name: windows-application
winevtlog:
channel: Application
attributes:
logtype: windows_application
use-ansi:true
-name: windows-system
winevtlog:
channel: System
attributes:
logtype: windows_system
# Example/Optional entry for Windows Defender Logs
Winlog can only collect classic Event logs. Attempting to capture others will silently collect the Applications log.
Collect events from Windows log channels.
Parameters:
channel: Name of the channel logs will be collected from. It doesn't work for custom channels.
collect-eventids: List of Windows Event IDs to be collected and forwarded to New Relic. Event ID ranges are supported.
exclude-eventids: List of Windows Event IDs to be excluded from collection. Event ID ranges are supported.
use-ansi: Use ANSI encoding on winlog messages. We use ANSI encoding by default on Windows Server 2016 and older versions, and UTF-8 on newer ones. You can override this behavior with this configuration parameter if these defaults do not suit your use case. This solves the problem of ANSI character code logs being empty strings. It's not a function to convert multi-byte character code logs in ANSI character code to UTF-8.
All events are collected from the specified channel by default. Configure the collect-eventids and exclude-eventids sections to avoid sending unwanted logs to your New Relic account.
Add event IDs or ranges to collect-eventids or exclude-eventids to forward or drop specific events. exclude-eventids takes precedence over collect-eventids if the same event ID is present in both sections.
Example:
logs:
# Example winlog security log ingestion with eventId filters.
-name: windows-security
winlog:
channel: Security
collect-eventids:
-4624
-4265
- 4700-4800
exclude-eventids:
-4735
attributes:
logtype: windows_security
# Example entries for the application and system channels
-name: windows-application
winlog:
channel: Application
attributes:
logtype: windows_application
-name: windows-system
winlog:
channel: System
attributes:
logtype: windows_system
# Example entries for the application use-ansi
-name: windows-application
winlog:
channel: Application
attributes:
logtype: windows_application
use-ansi:true
# Example/Optional entry for Windows Defender Logs
Although these configuration parameters aren't required, we still recommend you apply these configurations to your logging.yml file so you get the most out of log forwarding.
List of custom attributes specified as key-value pairs that can be used to send additional data with the logs which you can then query. The attributes configuration parameter can be used with any log source.
Important
The attributes configuration parameter does not add custom attributes to logs forwarded via external Fluent Bit configuration (for example, using the fluentbit configuration parameter). In this scenario, you should refer to the record_modifier option in the Fluent Bit documentation.
One common use of the attributes configuration parameter is to specify the logtype attribute. This attribute allows leveraging one of the built-in parsing rules supported by New Relic's capabilities.
Example:
logs:
-name: example-file-attributes
file: /var/log/example.log
attributes:
logtype: nginx
region: example-us-02
team: A-team
-name: example-tcp-attributes
tcp:
uri: tcp://0.0.0.0:2345
format: json
attributes:
logtype: nginx
region: example-us-02
team: B-team
The infrastructure agent automatically inserts log attributes for your convenience. Some of them are inserted for any log record, while others depend on the configuration parameters you used while setting up the log forwarder.
Attribute name
Description
entity.guids
Always inserted.
The infrastructure agent inserts the Entity GUID assigned by New Relic to identify the host where it's running. It is available in the entity.guids field.
Note: If the captured logs belong to an application instrumented using APM, the entity.guids field contains both the entity GUID of infrastructure, as well as the GUID of APM, separated by a pipe ( | ) delimiter.
fb.input
Always inserted.
The underlying Fluent Bit input plugin type used to capture the logs. Currently its values are tail, systemd, winlog, syslog, and tcp.
filePath
Inserted when using the file input type.
Absolute file path of the file being monitored.
hostname
Always inserted.
The hostname of the machine/VM/container executing the infrastructure agent.
plugin.type
Always inserted.
Indicates the utility used to capture the logs. In this case, it is the infrastructure agent itself, so this attribute always has the value nri-agent.
Regular expression for filtering records. Only supported for the tail, systemd, syslog, and tcp (only with format none) sources.
This field works in a way similar to grep -E in Unix systems. For example, for a given file being captured, you can filter for records containing either WARN or ERROR using:
-name: only-records-with-warn-and-error
file: /var/log/logFile.log
pattern: WARN|ERROR
No filtering is applied by default.
Maximum size of log entries/lines in KB. If log entries exceed the limit, they are skipped. Default is 128,the minimum allowed value is 33.
External Fluent Bit configuration and parser files. If defined, they are merged with the existing configuration and parser files generated by the infrastructure agent.
The infrastructure agent processes the configuration files located in the logging.d directory and will generate a run-time Fluent Bit configuration file that contains the appropriate [INPUT], [FILTER] and [OUTPUT] sections. Optionally, it will also declare an @INCLUDE in case you provided an external Fluent Bit configuration file via the fluentbit option.
The runtime file does not define a [SERVICE] section, leaving all default Fluent Bit configuration values. You can still override Fluent Bit's default settings by defining your own [SERVICE] section in your external Fluent Bit configuration file and include it via the fluentbit option.
Parameters:
config_file: path to an existing Fluent Bit configuration file. Note that any overlapping source results in duplicate messages in our logs UI.
parsers_file: path to an existing Fluent Bit parsers file. The following parser names are reserved: rfc3164, rfc3164-local and rfc5424.
Important
The infrastructure agent allows forwarding logs for the most common use cases by defining simple log forwarding configurations in the YAML files in the logging.d/ directory, as described in this document. These files are internally translated into Fluent Bit configuration files with the correct format and sane configuration defaults. New Relic provides official support for these configuration options since we ensure that the generated configuration files are correct and operative.
Nevertheless, for those use cases not covered by our supported configuration options, we provide the possibility to use an externally-generated Fluent Bit configuration and parsers file using the fluentbit, config_file, and parsers_file options.
Note: We cannot guarantee the correct operation of the log forwarded in this case, given that the provided configurations are completely arbitrary and are not being generated/validated by the agent. Therefore, New Relic does not provide official support for the external configurations specified via these options.
In the infrastructure UI, from the host table, click the icon for a specific host, and then click View logs.
Our tools for running NRQL queries. For example, you can execute a query like this:
SELECT*FROM Log
Enable logging for your on-host integrations
With the infrastructure agent installed, you can enable automatic log parsing and forwarding for our most popular on-host integrations with one step. To enable this feature, rename the on-host-log.yml.example file to on-host-log.yml. Once done, your integration's logs are automatically parsed and sent to New Relic.
To enable the on-host integration log forwarding feature:
Copy or rename the elasticsearch-log.yml.example file to elasticsearch-log.yml to enable automatic Elasticsearch JSON formatted log parsing and forwarding to New Relic. No need to restart the agent.
Copy or rename the mysql-log.yml.example file to mysql-log.yml to enable automatic MySQL error log parsing and forwarding to New Relic. No need to restart the agent.
Copy or rename the nginx-log.yml.example file to nginx-log.yml to enable automatic NGINX access and error log parsing and forwarding to New Relic. No need to restart the agent.
Copy or rename the rabbitmq-log.yml.example file to rabbitmq-log.yml to enable automatic Rabbitmq error log parsing and forwarding to New Relic. No need to restart the agent.
Copy or rename the redis-log.yml.example file to redis-log.yml to enable automatic Redis error log parsing and forwarding to New Relic. No need to restart the agent.
Enable log forwarding on agent installed using Linux tarball
Our custom Linux installation process for infrastructure monitoring allows you to tailor all aspects of the installation process, and to place files and folders on your machine. If you choose the assisted or manual tarball installation process, follow these steps to implement the log forwarder feature:
The log forwarding feature requires the agent to have permission to read the data sources. When running the infrastructure agent in privileged or non-privileged modes, make sure that the log files you want to forward (and any intermediary directory in its path) are readable by the user running nri-agent.
Example: Check file access under Linux
Let's check whether the file /var/log/restrictedLogs/logFile.log can be monitored by the nri-agent user. In Linux, you can do a quick check with the namei command:
This command failed because the file is not visible to the nri-agent user. By inspecting the previous output, we can detect that the restrictedLogs directory is missing the execution flag for others.
The file is now visible to the nri-agent user. You must ensure that the file is also readable by the nri-agent user. To check this, use:
bash
$
sudo-u nri-agent head /var/log/restrictedLogs/logFile.log
head: cannot open '/var/log/restrictedLogs/logFile.log' for reading: Permission denied
In this example, the file is missing the read rights for the others group (users other than vagrant and the vagrant user group). You could fix this by granting read permissions to others, but the application could change these permissions upon restart.
To avoid this, a better approach is to add the nri-agent user to the vagrant user group.
The log forwarding feature requires that the agent has permission to read the data sources. When running the infrastructure agent in privileged or non-privileged modes:
If you're using Unix domain socket files, make sure that the nri-agent user can access these files (please refer to the previous section) and that they have read and write permissions (666) so that other users than nri-agent can write to them.
If you're using IP sockets, ensure that the port that you are using is not a system reserved one (like port 80, for example).
As explained in the infrastructure agent configuration guidelines, the proxy parameter must use either HTTP or HTTPS and be in the form https://user:password@hostname:port. The agent can parse the parameter without the HTTP or HTTPS, but the log forwarder cannot. You will see an error like the following in the agent verbose logs:
[ERROR] building HTTP transport: parse \"hostname:port\":
first path segment in URL cannot contain colon
To solve this problem, check your newrelic-infra.yml file, and ensure the proxy parameter adheres to this form.
If you're using caBundleFile or caBundleDir in order to specify any certificate, we recommend to follow the below rules for each OS:
Linux
For HTTP proxies you don't need to setup any certificates. The plugin loads the system certificates and New Relic sends logs into the logging endpoint. However, you can specify the proxy self-signed certificate (PEM file) using either the caBundleFile or caBundleDir parameters.
Windows
For HTTP proxies you don't need to setup any certificates. The plugin loads the system certificates.
For HTTPS, you can configure it in one of the following ways:
(Recommended) Import the proxy certificate to the system pool. Import the proxy self-signed certificate (PEM file) by using the MMC tool. Refer to this link, and in Step 2 ensure to import it in your Trusted Root Certification Authorities instead of in the Intermediate Certification Authorities.
Use the caBundleFile and caBundleDir parameters
On Windows, we cannot load both the certificates from the system certificate pool and the ones specified with the caBundleFilecaBundleDir parameters. So, if you are using caBundleFile or caBundleDir, ensure that the following certificates are placed in the same PEM file (when using caBundleFile) or in the same directory (when using caBundleDir):
The proxy certificate (because it's an HTTPS proxy).
The logging endpoint certificate (eg. https://log-api.newrelic.com/log/v1).
The infrastructure agent certificate (eg. https://infra-api.newrelic.com).
You can configure the infrastructure agent to send its own logs to New Relic. This is useful for troubleshooting issues with log forwarding, the agent, or when contacting support.
Important
Trace logging generates a lot of data very quickly. To reduce disk space consumption and data ingest, when finished generating logs, be sure to set level: info (or lower).
To forward the infrastructure agent logs to New Relic:
Edit your newrelic-infra.yml file.
Enable logs forwarding to New Relic by adding the following config snippet:
log:
level: trace # Recommended: Helps with troubleshooting
forward:true# Enables sending logs to New Relic
format: json # Recommended: Enable agent logging in JSON format
stdout:false# On Windows and systems that don't use `systemd` or where `journald` is inaccessible
This configuration sets up the agent in troubleshooting mode, but the log forwarder (based on Fluent Bit) will continue in a non-verbose mode.
Sometimes you can have issues with the log forwarder itself. For example, there may be problems accessing a specific channel when shipping Windows log events or when accessing a particular log file. In these situations, you can also enable the verbose mode for the log forwarder.
Important
Trace logging generates a lot of data very quickly. To reduce disk space consumption and data ingest, when finished generating logs, be sure to set level: info (or lower).
Edit your newrelic-infra.yml file.
Enable Fluent Bit verbose logs by adding the following config snippet:
log:
level: trace
forward:true# Enables sending logs to New Relic
format: json # Recommended: Enable agent logging in JSON format
stdout:false# On Windows and systems that don't use `systemd` or where `journald` is inaccessible
include_filters:
traces:
- supervisor # Required to see verbose logs from Fluent Bit
It's common to face either one of the following error messages when attempting to tail a large amount of files:
Too many open files
The user limit on the total number of inotify watches was reached or the kernel failed to allocate a needed resource
The operating system defines a maximum amount of allocatable file descriptors (typically 1024 by default), and a maximum amount of allocatable inotify watches (typically 8192 by default). Any process attempting to go above these limits will fail, returning one of the errors above.
The underlying technology we use to forward logs, Fluent Bit, opens one file descriptor and sets an inotify watch for each file you configure to be forwarded. Moreover, at the time of writing this section, Fluent Bit uses an extra set of 32 file descriptors for its normal operation, with another extra file descriptor when it shuts down. Therefore, to capture a large amount of files you need to ensure that both the file descriptor and inotify watch limits are slightly greater than the amount of log files you wish to tail.
The following instructions summarize how to increase these limits if you want to tail 10,000 log files. Also, it assumes the infrastructure agent is installed in rootrunning mode, and therefore must be run using the root user.
Check which is the current hard limit for the amount of file descriptors per process. Typically, this limit should be quite high and should not need to be modified.
bash
$
ulimit-Hn
Add the following line to /etc/security/limits.conf. We specified a limit of 10100 here instead of just 10000 to allow Fluent Bit to allocate the extra file descriptors it may need to work.
bash
$
root soft nofile 10100# replace root by nri-agent for non-root (privileged and unprivileged) installations
Add the following line to /etc/pam.d/common-session so that the previous limit is applied upon restart:
bash
$
session required pam_limits.so
Add the following line to /etc/sysctl.conf to increase the amount of allowed inotify watchers per user. We specified a limit of 18192 here instead of just 10000 so that the root user will still have 8192 available inotify watches (the default value).
bash
$
fs.inotify.max_user_watches=18192
Restart your system.
Ensure that the new limits have been enforced by running:
bash
$
ulimit-Sn# Should return 10100
$
cat /proc/sys/fs/inotify/max_user_watches # Should return 18192
Prior to version 1.19.0 (or version 1.20.3 for SLES 12.5), the Linux infrastructure agent came bundled with a Fluent Bit binary. Starting in this version, Fluent Bit is now included as as a separate recommended package dependency.
This means that you can install, update, or downgrade Fluent Bit separately from the agent. For your convenience, we have included several Fluent Bit packages in the same repository where the infrastructure lives, so you don't need to install any additional repositories to upgrade Fluent Bit.
Note that the agent automatically installs Fluent Bit when you first install it, using the latest available version. After the first installation, you can upgrade Fluent Bit as you would normally do with any Linux package.
You can list the available Fluent Bit versions by running:
RPM:
bash
$
sudo yum check-update
$
yum list fluent-bit --showduplicates
DEB:
bash
$
sudoapt update
$
apt-cache showpkg fluent-bit
To upgrade to the latest Fluent Bit version, run these commands:
RPM:
bash
$
# Remove command only required when downgrading to a previous version
$
# sudo yum remove fluent-bit
$
sudo yum install fluent-bit
DEB:
bash
$
sudoaptinstall fluent-bit
Please note that td-agent-bit is not available for the following distributions so rollbacks on them are not possible:
CentOS 9 Stream (including Rocky Linux and AlmaLinux)
RedHat 9
Ubuntu 22.04.x
Open Suse (SLES) 15.4
Amazon Linux 2023
If you wish to revert to td-agent-bit, you can follow the steps outlined below:
Open the file /etc/newrelic-infra.yml using your preferred text editor.
Add the following line at the end of the file: fluent_bit_exe_path: /opt/td-agent-bit/bin/td-agent-bit.
Save the changes.
Restart the infrastructure agent by executing the following command: sudo systemctl restart newrelic-infra.
By completing these steps, the infrastructure agent will be configured to use td-agent-bit instead of fluent-bit.
What's next?
Explore logging data across your platform with our logs UI.
Get deeper visibility into both your application and your platform performance data by forwarding your logs with our logs in context capabilities.
To disable log forwarding capabilities, go to your logging.d directory, and remove files with the .yml extension that were originally added during the configuration process.