22.4. Working with Queues in Rsyslog

Figure 22.1. Message Flow in Rsyslog
/etc/rsyslog.conf are applied. Based on these rules, the rule processor evaluates which actions are to be performed. Each action has its own action queue. Messages are passed through this queue to the respective action processor which creates the final output. Note that at this point, several actions can run simultaneously on one message. For this purpose, a message is duplicated and passed to multiple action processors.
- they serve as buffers that decouple producers and consumers in the structure of rsyslog
- they allow for parallelization of actions performed on messages
Warning
SSH logging, which in turn can prevent SSH access. Therefore it is advised to use dedicated action queues for outputs which are forwarded over a network or to a database.
22.4.1. Defining Queues
/etc/rsyslog.conf:
object(queue.type=”queue_type”)
- main message queue: replace object with
main_queue - an action queue: replace object with
action - ruleset: replace object with
ruleset
direct, linkedlist or fixedarray (which are in-memory queues), or disk.
Direct Queues
object(queue.type=”Direct”)
main_queue, action or ruleset to use this option to the main message queue, an action queue or for the ruleset respectively. With direct queue, messages are passed directly and immediately from the producer to the consumer.
Disk Queues
/etc/rsyslog.conf:
object(queue.type=”Disk”)
main_queue, action or ruleset to use this option to the main message queue, an action queue or for the ruleset respectively. The default size of a queue can be modified with the following configuration directive:
object(queue.size=”size”)
object(queue.filename=”name”)
object(queue.maxfilesize=”size”)
In-memory Queues
action (queue.saveonshutdown=”on”) setting to save the data before shutdown. There are two types of in-memory queues:
- FixedArray queue — the default mode for the main message queue, with a limit of 10,000 elements. This type of queue uses a fixed, pre-allocated array that holds pointers to queue elements. Due to these pointers, even if the queue is empty a certain amount of memory is consumed. However, FixedArray offers the best run time performance and is optimal when you expect a relatively low number of queued messages and high performance.
- LinkedList queue — here, all structures are dynamically allocated in a linked list, thus the memory is allocated only when needed. LinkedList queues handle occasional message bursts very well.
object(queue.type=”LinkedList”)
object(queue.type=”FixedArray”)
main_queue, action or ruleset to use this option to the main message queue, an action queue or for the ruleset respectively.
Disk-Assisted In-memory Queues
queue.filename=”file_name” directive to its block to define a file name for disk assistance. This queue then becomes disk-assisted, which means it couples an in-memory queue with a disk queue to work in tandem.
object(queue.highwatermark=”number”)
object(queue.lowwatermark=”number”)
main_queue, action or ruleset to use this option to the main message queue, an action queue or for the ruleset respectively. Replace number with a number of enqueued messages. When an in-memory queue reaches the number defined by the high watermark, it starts writing messages to disk and continues until the in-memory queue size drops to the number defined with the low watermark. Correctly set watermarks minimize unnecessary disk writes, but also leave memory space for message bursts since writing to disk files is rather lengthy. Therefore, the high watermark must be lower than the whole queue capacity set with queue.size. The difference between the high watermark and the overall queue size is a spare memory buffer reserved for message bursts. On the other hand, setting the high watermark too low will turn on disk assistance unnecessarily often.
Example 22.12. Reliable Forwarding of Log Messages to a Server
UDP protocol.
Procedure 22.1. Forwarding To a Single Server
- Use the following configuration in
/etc/rsyslog.confor create a file with the following content in the/etc/rsyslog.d/directory:*.* action(type=”omfwd” queue.type=”LinkedList” queue.filename=”example_fwd” action.resumeRetryCount="-1" queue.saveonshutdown="on" arget="example.com" Port="6514" Protocol="tcp")
Where:queue.typeenables a LinkedList in-memory queue,queue.filenamedefines a disk storage, in this case the backup files are created in the/var/lib/rsyslog/directory with the example_fwd prefix,- the
action.resumeRetryCount= “-1”setting prevents rsyslog from dropping messages when retrying to connect if server is not responding, - enabled
queue.saveonshutdownsaves in-memory data if rsyslog shuts down, - the last line forwards all received messages to the logging server using reliable TCP delivery, port specification is optional.
With the above configuration, rsyslog keeps messages in memory if the remote server is not reachable. A file on disk is created only if rsyslog runs out of the configured memory queue space or needs to shut down, which benefits the system performance.
Procedure 22.2. Forwarding To Multiple Servers
- Each destination server requires a separate forwarding rule, action queue specification, and backup file on disk. For example, use the following configuration in
/etc/rsyslog.confor create a file with the following content in the/etc/rsyslog.d/directory:*.* action(type=”omfwd” queue.type=”LinkedList” queue.filename=”example_fwd1” action.resumeRetryCount="-1" queue.saveonshutdown="on" Target="example1.com" Protocol="tcp") *.* action(type=”omfwd” queue.type=”LinkedList” queue.filename=”example_fwd2” action.resumeRetryCount="-1" queue.saveonshutdown="on" Target="example2.com" Protocol="tcp")
22.4.2. Creating a New Directory for rsyslog Log Files
syslogd daemon and is managed by SELinux. Therefore all files to which rsyslog is required to write to, must have the appropriate SELinux file context.
Procedure 22.3. Creating a New Working Directory
- If required to use a different directory to store working files, create a directory as follows:
~]#
mkdir/rsyslog - Install utilities to manage SELinux policy:
~]#
yum install policycoreutils-python - Set the SELinux directory context type to be the same as the
/var/lib/rsyslog/directory:~]#
semanage fcontext -a -t syslogd_var_lib_t /rsyslog - Apply the SELinux context:
~]#
restorecon -R -v /rsyslogrestorecon reset /rsyslog context unconfined_u:object_r:default_t:s0->unconfined_u:object_r:syslogd_var_lib_t:s0 - If required, check the SELinux context as follows:
~]#
ls -Zd /rsyslogdrwxr-xr-x. root root system_u:object_r:syslogd_var_lib_t:s0 /rsyslog - Create subdirectories as required. For example:
~]#
The subdirectories will be created with the same SELinux context as the parent directory.mkdir/rsyslog/work/ - Add the following line in
/etc/rsyslog.confimmediately before it is required to take effect:global(workDirectory=”/rsyslog/work”)
This setting will remain in effect until the nextWorkDirectorydirective is encountered while parsing the configuration files.
22.4.3. Managing Queues
Limiting Queue Size
object(queue.highwatermark=”number”)
main_queue, action or ruleset to use this option to the main message queue, an action queue or for the ruleset respectively. Replace number with a number of enqueued messages. You can set the queue size only as the number of messages, not as their actual memory size. The default queue size is 10,000 messages for the main message queue and ruleset queues, and 1000 for action queues.
object(queue.maxdiskspace=”number”)
main_queue, action or ruleset. When the size limit specified by number is hit, messages are discarded until sufficient amount of space is freed by dequeued messages.
Discarding Messages
object(queue.discardmark=”number”)
MainMsg or with Action to use this option to the main message queue or for an action queue respectively. Here, number stands for a number of messages that have to be in the queue to start the discarding process. To define which messages to discard, use:
object(queue.discardseverity=”number”)
7 (debug), 6 (info), 5 (notice), 4 (warning), 3 (err), 2 (crit), 1 (alert), or 0 (emerg). With this setting, both newly incoming and already queued messages with lower than defined priority are erased from the queue immediately after the discard mark is reached.
Using Timeframes
object(queue.dequeuetimebegin=”hour”)
object(queue.dequeuetimeend=”hour”)
Configuring Worker Threads
object(queue.workerthreadminimummessages=”number”)
object(queue.workerthreads=”number”)
object(queue.timeoutworkerthreadshutdown=”time”)
Batch Dequeuing
$object(queue.DequeueBatchSize= ”number”)
Terminating Queues
object(queue.timeoutshutdown=”time”)
object(queue.timeoutactioncompletion=”time”)
object(queue.saveonshutdown=”on”)
22.4.4. Using the New Syntax for rsyslog queues
action() object that can be used both separately or inside a ruleset in /etc/rsyslog.conf. The format of an action queue is as follows:
action(type="action_type "queue.size="queue_size" queue.type="queue_type" queue.filename="file_name"
disk or select from one of the in-memory queues: direct, linkedlist or fixedarray. For file_name specify only a file name, not a path. Note that if creating a new directory to hold log files, the SELinux context must be set. See Section 22.4.2, “Creating a New Directory for rsyslog Log Files” for an example.
Example 22.13. Defining an Action Queue
action(type="omfile" queue.size="10000" queue.type="linkedlist" queue.filename="logfile")
*.* action(type="omfile" file="/var/lib/rsyslog/log_file
)
*.* action(type="omfile"
queue.filename="log_file"
queue.type="linkedlist"
queue.size="10000"
)
The default work directory, or the last work directory to be set, will be used. If required to use a different work directory, add a line as follows before the action queue: global(workDirectory="/directory")
Example 22.14. Forwarding To a Single Server Using the New Syntax
omfwd plug-in is used to provide forwarding over UDP or TCP. The default is UDP. As the plug-in is built in it does not have to be loaded.
/etc/rsyslog.conf or create a file with the following content in the /etc/rsyslog.d/ directory:
*.* action(type="omfwd"
queue.type="linkedlist"
queue.filename="example_fwd"
action.resumeRetryCount="-1"
queue.saveOnShutdown="on"
target="example.com" port="6514" protocol="tcp"
)
queue.type="linkedlist"enables a LinkedList in-memory queue,queue.filenamedefines a disk storage. The backup files are created with the example_fwd prefix, in the working directory specified by the preceding globalworkDirectorydirective,- the
action.resumeRetryCount -1setting prevents rsyslog from dropping messages when retrying to connect if server is not responding, - enabled
queue.saveOnShutdown="on"saves in-memory data if rsyslog shuts down, - the last line forwards all received messages to the logging server, port specification is optional.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.