Redis (im_redis)

This module can retrieve data stored in a Redis server. The module issues LPOP commands using the Redis Protocol to pull data.

The output counterpart, om_redis, can be used to populate the Redis server with data.

Configuration

The im_redis module accepts the following directives in addition to the common module directives. The Host directive is required.

Required directives

The following directives are required for the module to start.

Host

This mandatory directive specifies the IP address or DNS hostname of the Redis server to connect to. The module works in a failover configuration if additional hosts are specified on new lines. If a host is unreachable, the module automatically fails over to the next one. If the last host is unreachable, the module will fail over to the first host.

Optional directives

Channel

Optional directive to define the Redis channel(s) to subscribe to. The default is nxlog. This directive can be specified multiple times within the module definition. The Command directive must be set to SUBSCRIBE or PSUBSCRIBE when using this directive. When the command is set to PSUBSCRIBE, each Channel directive specifies a glob pattern that will be used by the Redis server to match available channels. For the SUBSCRIBE command, Channel specifies the channel name without a pattern.

Command

This optional directive can be used to choose between the LPOP (the default), RPOP, SUBSCRIBE, and PSUBSCRIBE commands.

InputType

See the InputType directive in the list of common module directives. The default is the Dgram reader function, which expects a plain string. You can use Binary to read structured data if the logs are written to Redis by another NXLog Agent instance in Binary format.

Key

This specifies the Key used by the LPOP command. The default is nxlog. The usage of this directive is mutually exclusive with the usage of the SUBSCRIBE and PSUBSCRIBE commands in the Command directive.

LocalPort

This optional directive specifies the local port number of the connection. If not specified, a random high port number will be used, which may be unsuitable for firewalled network environments.

PollInterval

This directive specifies how frequently the module will check for new data, in seconds. If this directive is not specified, the default is 1 second. Fractional seconds may be specified (PollInterval 0.5 will check twice every second). The usage of this directive is mutually exclusive with the usage of the SUBSCRIBE and PSUBSCRIBE commands in the Command directive.

Port

This specifies the port number of the Redis server. The default is port 6379.

Fields

The following fields are used by im_redis.

$raw_event (type: string)

The received string.

$Channel (type: string)

For the SUBSCRIBE and PSUBSCRIBE commands, this is the Redis Pub/Sub channel from which the message was received. Otherwise, it is undefined.

Examples

Example 1. Collecting logs from Redis with default configuration

This configuration only sets the mandatory Host directive to the Redis server IP address. The module default will use the LPOP command to retrieve logs from a key named nxlog.

nxlog.conf
<Input redis>
    Module    im_redis
    Host      192.168.1.213
</Input>
Example 2. Collecting logs from Redis with a custom command key

The configuration below sets the mandatory Host directive to the Redis server IP address. It also specifies the Command and Key directives to use the RPOP command for retrieving logs from a key named event_logs.

nxlog.conf
<Input redis>
    Module     im_redis
    Host       192.168.1.213
    Command    RPOP
    Key        event_logs
</Input>
Example 3. Subscribing to a custom channel

The configuration below sets the mandatory Host directive to the Redis server IP address. It also specifies the Command and Channel directives for subscribing to the event_logs Redis channel.

nxlog.conf
<Input redis>
    Module     im_redis
    Host       192.168.1.213
    Command    SUBSCRIBE
    Channel    event_logs
</Input>
Example 4. Subscribing to multiple channels with a pattern

The configuration below sets the mandatory Host directive to the Redis server IP address. It also specifies the Command and multiple Channel directives for subscribing to any Redis channel names ending with _metrics or _logs.

nxlog.conf
<Input redis>
    Module     im_redis
    Host       192.168.1.213
    Command    PSUBSCRIBE
    Channel    *_metrics
    Channel    *_logs
</Input>