NXLog Documentation

You are viewing the documentation of our legacy products. Go to the NXLog Platform Documentation.

Test Generator (im_testgen)

This module generates simple events for testing, with an incremented integer up to the number of events specified by the MaxCount directive.

To examine the supported platforms, see the list of installer packages in the Available Modules chapter.

Configuration

The im_testgen module accepts the following directives in addition to the common module directives.

Optional directives

MaxCount

The module will generate the defined number of events and then stop generating events. If you don’t specify this directive, or set it with a non-integer value, im_testgen will continue generating events until you stop NXLog. MaxCount is a 64-bit unsigned integer and negative values are interpreted as such, therefore setting MaxCount to 18446744073709551615 or -1 is equivalent.

MoreFields

When set to TRUE, this boolean directive enables the generation of 16 additional fields in each event record, simulating a larger payload for testing purposes. The extra fields include integers such as EventID, TraceFlags, CountField, and ErrorCode and strings like Severity, MessageSourceAddress, AccountName, TraceID, SpanID, and OtherMessage. Several fields use static values, including OtherMessage, TraceID, and SpanID. Enabling this option may reduce the module’s throughput due to the increased event size.

Examples

Example 1. Generating unstructured events

This configuration generates ten unstructured events defined in the MaxCount directive and then stops generating events.

nxlog.conf
<Input testgen>
   Module      im_testgen
   MaxCount    10
</Input>
Output sample
0@Mon Nov 13 16:14:53 2023
1@Mon Nov 13 16:14:53 2023
2@Mon Nov 13 16:14:53 2023
3@Mon Nov 13 16:14:53 2023
4@Mon Nov 13 16:14:53 2023
5@Mon Nov 13 16:14:53 2023
6@Mon Nov 13 16:14:53 2023
7@Mon Nov 13 16:14:53 2023
8@Mon Nov 13 16:14:53 2023
9@Mon Nov 13 16:14:53 2023
Example 2. Generating structured events

This configuration generates ten events defined in the MaxCount directive and parses them into a JSON format as a structured output.

nxlog.conf
<Extension json>
   Module      xm_json
</Extension>

<Input testgen>
   Module      im_testgen
   MaxCount    10
   Exec        $Message=$raw_event; json->to_json();
</Input>
Output sample
{
  "SeverityValue":2,
  "EventTime":"2023-11-13T16:18:44.854580+00:00",
  "SourceName":"nxlog",
  "ProcessID":1,
  "EventReceivedTime":"2023-11-13T16:18:44.854580+00:00",
  "SourceModuleName":"testgen",
  "SourceModuleType":"im_testgen",
  "Hostname":"f691d53f3ad0",
  "Message":"1@Mon Nov 13 16:18:44 2023"
}
Example 3. Using a schedule and module restart for crude rate-limiting

This configuration generates ten events defined in the MaxCount directive. Then, the Schedule block restarts the module to start generating events again, going into a cycle of generating ten events every 5 seconds.

nxlog.conf
<Extension json>
    Module      xm_json
</Extension>

<Input testgen>
    Module      im_testgen
    MaxCount    10
    Exec        $Message=$raw_event; json->to_json();
    <Schedule>
        Every    5 sec
        Exec     module_restart();
    </Schedule>
</Input>
MaxCount is only reset on module restart starting from NXLog version 6.2.
Output sample from the NXLog log file reporting of completed cycles.
2023-11-13 16:26:08 INFO [im_testgen|testgen] maxcount 10 reached
2023-11-13 16:26:13 INFO [im_testgen|testgen] maxcount 10 reached
2023-11-13 16:26:18 INFO [im_testgen|testgen] maxcount 10 reached
2023-11-13 16:26:23 INFO [im_testgen|testgen] maxcount 10 reached
Example 4. Rate-limiting and randomized rate-limiting

This configuration generates a continuous event stream where the module waits for 100000 microseconds between generating events. It roughly equals to around ten events generated per second.

nxlog.conf
<Input testgen>
    Module    im_testgen
    Exec      sleep (100000);
</Input>

This configuration generates a continuous event stream where the module waits randomly between 0 to 2000 microseconds within generating events.

nxlog.conf
<Input testgen>
    Module    im_testgen
    Exec      sleep (get_rand(2000));
</Input>
Example 5. Generating events using MoreFields directive

This configuration enables the MoreFields directive and adds 16 more fields to the payload, which are parsed into JSON.

nxlog.conf
<Extension json>
    Module        xm_json
</Extension>

<Input testgen>
    Module        im_testgen
    MoreFields    TRUE
    MaxCount      1
    Exec          to_json();
</Input>
Output sample
{
  "SeverityValue": 2,
  "EventTime": "2025-03-07 12:55:53",
  "EventReceivedTime": "2025-03-07 12:55:53",
  "EventID": 214074,
  "SourceModuleName": "i1",
  "Severity": "INFO",
  "MessageSourceAddress": "127.0.0.1",
  "AccountName": "NXLog",
  "TargetUserName": "NXLog",
  "TraceID": "AaaA-Bbbb-CccC",
  "SpanID": "DddD-EeeE-FffF",
  "TraceFlags": 214074,
  "Hostname": "maindeb12",
  "Message": "0@Fri Mar 07 14:55:53 2025",
  "CountField": 0,
  "ErrorCode": 0,
  "OtherMessage": "some other message",
  "SourceName": "nxlog",
  "ProcessID": 214074,
  "SourceModuleType": "im_testgen"
}