# riemann() destination options

The `riemann()` driver sends metrics or events to a [Riemann](<http://riemann.io/>) monitoring system.

The `riemann()` destination has the following options:

## attributes()

|   
---|---  
Type: | parameter list of the `value-pairs()` option  
Default: |   
  
_Description:_ The `attributes()` option adds extra metadata to the Riemann event, that can be displayed on the Riemann dashboard. To specify the metadata to add, use the syntax of the `value-pairs()` option. For details on using `value-pairs()`, see [Structuring macros, metadata, and other value-pairs](../../../docs/axosyslog-core/chapter-concepts/concepts-value-pairs/index.md).

## description()

|   
---|---  
Type: | template, macro, or string  
Default: |   
  
_Description:_ The value to add as the description field of the Riemann event.

## disk-buffer()

_Description:_ This option enables putting outgoing messages into the disk buffer of the destination to avoid message loss in case of a system failure on the destination side. It has the following options:

### capacity-bytes()

Type: | number (bytes)  
---|---  
Default: | 1MiB  
  
_Description:_ This is a required option. The maximum size of the disk-buffer in bytes. The minimum value is `1048576` bytes. If you set a smaller value, the minimum value will be used automatically. It replaces the old `log-disk-fifo-size()` option.

In AxoSyslog version 4.2 and earlier, this option was called `disk-buf-size()`.

### compaction()

Type: | yes/no  
---|---  
Default: | no  
  
_Description:_ If set to `yes`, AxoSyslog prunes the unused space in the LogMessage representation, making the disk queue size smaller at the cost of some CPU time. Setting the `compaction()` argument to `yes` is recommended when numerous name-value pairs are unset during processing, or when the same names are set multiple times.

Note Simply unsetting these name-value pairs by using the `unset()` rewrite operation is not enough, as due to performance reasons that help when AxoSyslog is CPU bound, the internal representation of a `LogMessage` will not release the memory associated with these name-value pairs. In some cases, however, the size of this overhead becomes significant (the raw message size can grow up to four times its original size), which unnecessarily increases the disk queue file size. For these cases, the compaction will drop `unset` values, making the `LogMessage` representation smaller at the cost of some CPU time required to perform compaction. 

### dir()

Type: | string  
---|---  
Default: | N/A  
  
_Description:_ Defines the folder where the disk-buffer files are stored.

Warning

When creating a new `dir()` option for a disk buffer, or modifying an existing one, make sure you delete the persist file.

AxoSyslog creates disk-buffer files based on the path recorded in the persist file. Therefore, if the persist file is not deleted after modifying the `dir()` option, then following a restart, AxoSyslog will look for or create disk-buffer files in their old location. To ensure that AxoSyslog uses the new `dir()` setting, the persist file must not contain any information about the destinations which the disk-buffer file in question belongs to.

Note If the `dir()` path provided by the user does not exist, AxoSyslog creates the path with the same permission as the running instance. 

### flow-control-window-bytes()

Type: | number (bytes)  
---|---  
Default: | 163840000  
  
_Description:_ Use this option if the option `reliable()` is set to `yes`. This option contains the size of the messages in bytes that is used in the memory part of the disk buffer. It replaces the old `log-fifo-size()` option. It does not inherit the value of the global `log-fifo-size()` option, even if it is provided. Note that this option will be ignored if the option `reliable()` is set to `no`.

In AxoSyslog version 4.2 and earlier, this option was called `mem-buf-size()`.

### flow-control-window-size()

Type: | number(messages)  
---|---  
Default: | 10000  
  
_Description:_ Use this option if the option `reliable()` is set to `no`. This option contains the number of messages stored in overflow queue. It replaces the old `log-fifo-size()` option. It inherits the value of the global `log-fifo-size()` option if provided. If it is not provided, the default value is `10000` messages. Note that this option will be ignored if the option `reliable()` is set to `yes`.

In AxoSyslog version 4.2 and earlier, this option was called `mem-buf-length()`.

### front-cache-size()

Type: | number(messages)  
---|---  
Default: | 1000  
  
_Description:_ The number of messages stored in the output buffer of the destination. Note that if you change the value of this option and the disk-buffer already exists, the change will take effect when the disk-buffer becomes empty.

Options `reliable()` and `capacity-bytes()` are required options.

In AxoSyslog version 4.2 and earlier, this option was called `qout-size()`.

### prealloc()

Type: | yes/no  
---|---  
Default: | no  
  
_Description:_

By default, AxoSyslog doesn’t reserve the disk space for the disk-buffer file, since in a properly configured and sized environment the disk-buffer is practically empty, so a large preallocated disk-buffer file is just a waste of disk space. But a preallocated buffer can prevent other data from using the intended buffer space (and elicit a warning from the OS if disk space is low), preventing message loss if the buffer is actually needed. To avoid this problem, when using AxoSyslog 4.0 or later, you can preallocate the space for your disk-buffer files by setting `prealloc(yes)`.

In addition to making sure that the required disk space is available when needed, preallocated disk-buffer files provide radically better (3-4x) performance as well: in case of an outage the amount of messages stored in the disk-buffer is continuously growing, and using large continuous files is faster, than constantly waiting on a file to change its size.

If you are running AxoSyslog on a dedicated host (always recommended for any high-volume settings), use `prealloc(yes)`.

Available in AxoSyslog 4.0 and later.

### reliable()

Type: | yes/no  
---|---  
Default: | no  
  
_Description:_ If set to `yes`, AxoSyslog cannot lose logs in case of reload/restart, unreachable destination or AxoSyslog crash. This solution provides a slower, but reliable disk-buffer option. It is created and initialized at startup and gradually grows as new messages arrive. If set to `no`, the normal disk-buffer will be used. This provides a faster, but less reliable disk-buffer option.

Warning Hazard of data loss! If you change the value of `reliable()` option when there are messages in the disk-buffer, the messages stored in the disk-buffer will be lost. 

### truncate-size-ratio()

Type: | number((between 0 and 1))  
---|---  
Default: | 1 (do not truncate)  
  
_Description:_ Limits the truncation of the disk-buffer file. Truncating the disk-buffer file can slow down the disk IO operations, but it saves disk space. By default, AxoSyslog version 4.0 and later doesn’t truncate disk-buffer files by default (`truncate-size-ratio(1)`). Earlier versions freed the disk-space when at least 10% of the disk-buffer file could be freed (`truncate-size-ratio(0.1)`).

AxoSyslog only truncates the file if the possible disk gain is more than `truncate-size-ratio()` times `capacity-bytes()`.

  * Smaller values free disk space quicker.
  * Larger ratios result in better performance.



If you want to avoid performance fluctuations:

  * use `truncate-size-ratio(1)` (never truncate), or
  * use `prealloc(yes)` to reserve the entire size of the disk-buffer on disk.



Warning Axoflow does not recommend you to change `truncate-size-ratio()`. Only change its value if you understand the performance implications of doing so. 

### Example: Examples for using disk-buffer()

In the following case reliable disk-buffer() is used.
```
 
    destination d_demo {
        network(
            "127.0.0.1"
            port(3333)
            disk-buffer(
                flow-control-window-bytes(10000)
                capacity-bytes(2000000)
                reliable(yes)
                dir("/tmp/disk-buffer")
            )
        );
    };
    
```

In the following case normal disk-buffer() is used.
```
 
    destination d_demo {
        network(
            "127.0.0.1"
            port(3333)
                disk-buffer(
                flow-control-window-size(10000)
                capacity-bytes(2000000)
                reliable(no)
                dir("/tmp/disk-buffer")
            )
        );
    };
    
```

## event-time()

|   
---|---  
Type: | template, macro, or string  
Default: | ${UNIXTIME}  
  
_Description:_ Instead of the arrival time into Riemann, AxoSyslog can also send its own timestamp value.

This can be useful if Riemann is inaccessible for a while, and the messages are collected in the disk buffer until Riemann is accessible again. In this case, it would be difficult to differentiate between messages based on the arrival time only, because this would mean that there would be hundreds of messages with the same arrival time. This issue can be solved by using this option.

The `event-time()` option takes an optional parameter specifying whether the time format is in seconds or microseconds. For example:
```
 
       event-time("$(* $UNIXTIME 1000000)" microseconds)
        event-time("12345678" microseconds)
        event-time("12345678" seconds)
        event-time("12345678")
    
```

In case the parameter is omitted, AxoSyslog defaults to the seconds version. In case the `event-time()` option is omitted altogether, AxoSyslog defaults to the seconds version with `$UNIXTIME`.

Note that the time format parameter requires:

  * riemann-c-client 1.10.0 or newer

In older versions of riemann-c-client, the microseconds option is not available.

If you installed the new version in a custom location (instead of the default one), make sure that you append the directory of the pkg-config file (`.pc` file) to the environment variable `export PKG_CONFIG_PATH=...`.

After calling `configure`, you should see the following message in the case of successful installation:
```
 [...]
             Riemann destination (module): yes, microseconds: yes
            [...]
        
```

  * Riemann 2.13 or newer

Older versions of Riemann cannot handle microseconds. No error will be indicated, however, the time of the event will be set to the timestamp when the message arrived to Riemann.




## Example: Example event-time() option
```
       destination d_riemann {
           riemann(
           server("127.0.0.1")
           port(5555)
           event-time("${UNIXTIME}")
           [...]
           );
        };
    
```

## batch-bytes()

|   
---|---  
Accepted values: | number [bytes]  
Default: | none  
  
_Description:_ Sets the maximum size of payload in a batch. If the size of the messages reaches this value, AxoSyslog sends the batch to the destination even if the number of messages is less than the value of the `batch-lines()` option.

Note that if the `batch-timeout()` option is enabled and the queue becomes empty, AxoSyslog flushes the messages only if `batch-timeout()` expires, or the batch reaches the limit set in `batch-bytes()`.

Available in AxoSyslog version 3.19 and later.

## batch-idle-timeout()

|   
---|---  
Type: | time in milliseconds  
Default: | `0` (disabled)  
  
Available in AxoSyslog 4.24 and later.

_Description:_ `batch-idle-timeout()` measures the elapsed time since the last message was added to the batch (`batch-timeout()` defines the maximum time used to collect a batch, starting from the first message). If either `batch-idle-timeout()` or `batch-timeout()` expires, AxoSyslog closes and sends the batch.

## batch-lines()

|   
---|---  
Type: | number  
Default: | 1  
  
_Description:_ Specifies how many lines are flushed to a destination in one batch. The AxoSyslog application waits for this number of lines to accumulate and sends them off in a single batch. Increasing this number increases throughput as more messages are sent in a single batch, but also increases message latency. To disable `batch-lines()`, set it to `0`.

For example, if you set `batch-lines()` to 100, AxoSyslog waits for 100 messages.

If the `batch-timeout()` option is disabled, the AxoSyslog application flushes the messages if it has sent `batch-lines()` number of messages, or the queue became empty. If you stop or reload AxoSyslog or in case of network sources, the connection with the client is closed, AxoSyslog automatically sends the unsent messages to the destination.

Note that if the `batch-timeout()` option is enabled and the queue becomes empty, AxoSyslog flushes the messages only if `batch-timeout()` expires, or the batch reaches the limit set in `batch-lines()`.

For optimal performance, make sure that the AxoSyslog source that feeds messages to this destination is configured properly: the value of the `log-iw-size() / max-connections()` of the source must be higher than the `batch-lines() * workers()` of the destination. Otherwise, the size of the batches cannot reach the `batch-lines()` limit.

## batch-timeout()

|   
---|---  
Type: | time in milliseconds  
Default: | `-1` (disabled)  
  
_Description:_ Specifies the time AxoSyslog waits for lines to accumulate in the output buffer. The AxoSyslog application sends batches to the destinations evenly. The timer starts when the first message arrives to the buffer, so if only few messages arrive, AxoSyslog sends messages to the destination at most once every `batch-timeout()` milliseconds.

If an error occurs while sending the messages to the server, AxoSyslog will try to resend every message from the batch. If it does not succeed (you can set the number of retry attempts in the `retries()` option), AxoSyslog drops every message in the batch.

## hook-commands()

_Description:_ This option makes it possible to execute external programs when the relevant driver is initialized or torn down. The `hook-commands()` can be used with all source and destination drivers with the exception of the `usertty()` and `internal()` drivers.

Note The AxoSyslog application must be able to start and restart the external program, and have the necessary permissions to do so. For example, if your host is running AppArmor or SELinux, you might have to modify your AppArmor or SELinux configuration to enable AxoSyslog to execute external applications. 

### Using `hook-commands()` when AxoSyslog starts or stops

To execute an external program when AxoSyslog starts or stops, use the following options:

#### `startup()`

Type: | string  
---|---  
Default: | N/A  
  
_Description:_ Defines the external program that is executed as AxoSyslog starts.

#### `shutdown()`

Type: | string  
---|---  
Default: | N/A  
  
_Description:_ Defines the external program that is executed as AxoSyslog stops.

### Using the hook-commands() when AxoSyslog reloads

To execute an external program when the AxoSyslog configuration is initiated or torn down, for example, on startup/shutdown or during a AxoSyslog reload, use the following options:

#### `setup()`

Type: | string  
---|---  
Default: | N/A  
  
_Description:_ Defines an external program that is executed when the AxoSyslog configuration is initiated, for example, on startup or during a AxoSyslog reload.

#### `teardown()`

Type: | string  
---|---  
Default: | N/A  
  
_Description:_ Defines an external program that is executed when the AxoSyslog configuration is stopped or torn down, for example, on shutdown or during a AxoSyslog reload.

### Example: Using hook-commands() with a network source

In the following example, the `hook-commands()` is used with the `network()` driver and it opens an [iptables](<https://en.wikipedia.org/wiki/Iptables> "https://en.wikipedia.org/wiki/Iptables") port automatically as AxoSyslog is started/stopped.

The assumption in this example is that the `LOGCHAIN` chain is part of a larger ruleset that routes traffic to it. Whenever the AxoSyslog created rule is there, packets can flow, otherwise the port is closed.
```
 
    source {
        network(transport(udp)
        hook-commands(
              startup("iptables -I LOGCHAIN 1 -p udp --dport 514 -j ACCEPT")
              shutdown("iptables -D LOGCHAIN 1")
            )
         );
    };
    
```

## host()

|   
---|---  
Type: | template, macro, or string  
Default: | ${HOST}  
  
_Description:_ The value to add as the host field of the Riemann event.

## log-fifo-size()

|   
---|---  
Type: | number  
Default: | Use global setting.  
  
_Description:_ The number of messages that the output queue can store.

## metric()

|   
---|---  
Type: | template, macro, or string  
Default: |   
  
_Description:_ The numeric value to add as the metric field of the Riemann event. If possible, include type-hinting as well, otherwise the Riemann server will interpret the value as a floating-point number. The following example specifies the SEQNUM macro as an integer.
```
 
       metric(int("$SEQNUM"))
    
```

## port()

|   
---|---  
Type: | number  
Default: | 5555  
  
_Description:_ The port number of the Riemann server.

## retries()

|   
---|---  
Type: | number (of attempts)  
Default: | 3  
  
_Description:_ If AxoSyslog cannot send a message, it will try again until the number of attempts reaches `retries()`.

If the number of attempts reaches `retries()`, AxoSyslog will wait for `time-reopen()` time, then tries sending the message again.

## server()

|   
---|---  
Type: | hostname or IP address  
Default: | 127.0.0.1  
  
_Description:_ The hostname or IP address of the Riemann server.

## service()

|   
---|---  
Type: | template, macro, or string  
Default: | ${PROGRAM}  
  
_Description:_ The value to add as the service field of the Riemann event.

## state()

|   
---|---  
Type: | template, macro, or string  
Default: |   
  
_Description:_ The value to add as the state field of the Riemann event.

## tags()

|   
---|---  
Type: | string list  
Default: | the tags already assigned to the message  
  
_Description:_ The list of tags to add as the tags field of the Riemann event. If not specified AxoSyslog automatically adds the tags already assigned to the message. If you set the `tags()` option, only the tags you specify will be added to the event.

## throttle()

|   
---|---  
Type: | number  
Default: | 0  
  
_Description:_ Sets the maximum number of messages sent to the destination per second. Use this output-rate-limiting functionality only when using disk-buffer as well to avoid the risk of losing messages. Specifying `0` or a lower value sets the output limit to unlimited.

## time-reopen()

|   
---|---  
Accepted values: | number [seconds]  
Default: | 60  
  
_Description:_ The time to wait in seconds before a dead connection is reestablished.

## timeout()

|   
---|---  
Type: | number [seconds]  
Default: |   
  
_Description:_ The value (in seconds) to wait for an operation to complete, and attempt to reconnect the Riemann server if exceeded. By default, the timeout is disabled.

## ttl()

|   
---|---  
Type: | template, macro, or number  
Default: |   
  
_Description:_ The value (in seconds) to add as the ttl (time-to-live) field of the Riemann event.

## type()

|   
---|---  
Type: | tcp  
Default: | tcp  
  
_Description:_ The type of the network connection to the Riemann server: TCP, TLS, or UDP. For TLS connections, set the `ca-file()` option to authenticate the Riemann server, and the `cert-file()` and `key-file()` options if the Riemann server requires authentication from its clients.

### Declaration 1:
```
       destination d_riemann {
            riemann(
                server("127.0.0.1")
                port(5672)
                type(
                   "tls"
                   ca-file("ca")
                   cert-file("cert") 
                   key-file("key")
                )
            );
        };
    
```

An alternative way to specify TLS options is to group them into a `tls()` block. This allows you to separate them and ensure better readability.

### Declaration 2:
```
       destination d_riemann {
            riemann(
                server("127.0.0.1")
                port(5672)
                type("tls")
                tls(
                    ca-file("ca")
                    cert-file("cert") 
                    key-file("key")
                )
            );
        };
    
```

Make sure that you specify TLS options either using `type()` or using the `tls()` block. Avoid mixing the two methods. In case you do specify TLS options in both ways, the one that comes later in the configuration file will take effect.

### `ca-file()`

|   
---|---  
Type: | path to a CA certificate in PEM format  
Default: |   
  
_Description:_ Path to the CA certificate in PEM format that signed the certificate of the Riemann server. When establishing TLS connection, AxoSyslog verifies the certificate of the Riemann server using this CA.

_Alternative 1_
```
 
       type(
            "tls"
            ca-file("/opt/syslog-ng/etc/syslog-ng/riemann-cacert.pem")
            )
    
```

_Alternative 2_
```
 
       riemann(
            .
            .
            type("tls")
         tls(
                    ca-file("/opt/syslog-ng/etc/syslog-ng/riemann-cacert.pem")
            )
    
```

This option was called `cacert()` up until (and including) AxoSyslog version 3.12.

### cert-file()

|   
---|---  
Type: | path to a CA certificate in PEM format  
Default: |   
  
_Description:_ Path to the a certificate file in PEM format. When establishing TLS connection, AxoSyslog authenticates on the Riemann server using this certificate and the matching private key set in the `key-file()` option.

Note that you have to set the `cert-file()` and `key-file()` options only if the Riemann server requires authentication from the clients.

_Alternative 1:_
```
 
       type(
            "tls"
         cert-file("/opt/syslog-ng/etc/syslog-ng/riemann-client-cert.pem")
            key-file("/opt/syslog-ng/etc/syslog-ng/riemann-client-cert.key")
            )
    
```

_Alternative 2:_
```
 
       riemann(
            .
            .
            type("tls")
                tls(
                      cert-file("/opt/syslog-ng/etc/syslog-ng/riemann-client-cert.pem")
                      key-file("/opt/syslog-ng/etc/syslog-ng/riemann-client-cert.key")
               )
    
```

This option was called `cert()` in AxoSyslog version 3.7.

### key-file()

|   
---|---  
Type: | path to a private key file  
Default: |   
  
_Description:_ Path to the private key of the certificate file set in the `cert-file()` option. When establishing TLS connection, AxoSyslog authenticates on the Riemann server using this private key and the matching certificate set in the `cert-file()` option.

Note that you have to set the `cert-file()` and `key-file()` options only if the Riemann server requires authentication from the clients.

_Alternative 1:_
```
 
       type(
            "tls"
         cert-file("/opt/syslog-ng/etc/syslog-ng/riemann-client-cert.pem")
            key-file("/opt/syslog-ng/etc/syslog-ng/riemann-client-cert.key")
            )
    
```

_Alternative 2:_
```
 
       riemann(
            .
            .
            type("tls")
                tls(
                      cert-file("/opt/syslog-ng/etc/syslog-ng/riemann-client-cert.pem")
                      key-file("/opt/syslog-ng/etc/syslog-ng/riemann-client-cert.key")
               )
    
```

This option was called `key()` in AxoSyslog version 3.7.

Last modified November 20, 2024: [Broken link updates (5644de9)](<https://github.com/axoflow/axosyslog-core-docs/commit/5644de9a8069da37e3bebf0ed5a4e73cf958a66b>)