Where events go missing: analyzing losses in analysisd
When Wazuh loses events: how to read events_dropped and the queues in wazuh-analysisd.state, compute deltas between readings and relate them to CPU load.
You can lose events even with empty queues and no losses reported by remoted. This is not a contradiction. The counters can describe different processing stages, and a single reading shows the state only at one moment. Diagnosis requires comparing readings over time and correlating them with load.
Example of reading the counters
The values below are synthetic and serve only as an illustration, not a measurement. A reading of analysisd statistics can show events_received=100000, events_processed=98500 and events_dropped=500, with *_queue_usage equal to 0 at the time of the reading and remoted discarded_count=0. At the same time, the analysisd process can occupy most of the available CPU cores.
In this example, events_dropped is 0.5% of events_received. Do not subtract processed from received and treat the whole difference as loss. The counters can describe other stages, update at different moments and cover different time windows. The arithmetic alone does not prove that the missing 1500 events disappeared.
The limits of what the counters document
The Wazuh documentation describes the file /var/ossec/var/run/wazuh-analysisd.state, updated every analysisd.state_interval seconds. The default interval is 5 seconds, and the allowed range is 0 to 86400. The interval is set in the internal options. The default value describes how often the file is updated, not a guaranteed gap between readings taken by external monitoring. The documentation does not define the meaning of the value 0.
The comments in the sample state file assign selected descriptions to the counters.
| Fields | Description given in the sample comment |
|---|---|
events_received | Events received |
events_processed, events_edps | Events processed, Rule matching |
events_dropped | Events dropped |
total_events_decoded, source decoding counters and *_edps | Decoding reading, sources: syscheck, syscollector, rootcheck, sca, hostinfo, other |
alerts_written, firewall_written, fts_written | Write counters for alerts, firewall and FTS |
The documentation does not define the unit of the edps fields. It also does not define the unit of queue_usage, whose sample values are decimal, or whether the counters are cumulative or reset. When you compare source decoding counters, keep the source name with every reading and do not aggregate different *_edps fields without confirming their units. For this reason, a value without a time context is not enough to state the rate or size of losses. You need to measure deltas between readings and confirm the semantics in the documentation for the version running on the analyzed system.
Do not guess what exactly increments events_dropped. The mere existence of the field is not a definition of the mechanism. If its meaning affects an operational decision, establish it from the documentation of the specific version or from a controlled measurement. Until confirmed, talk about the counter increase, not the cause.
A procedure without guessing
Start by collecting the timestamp, the counter and the context. Record the values of events_received, events_processed, events_dropped, the available queue counters and the discard information from remoted, if it is already collected. Add the CPU and the nature of the load in the same interval. Do not compare readings from different loads as if they were equivalent.
Repeat the reading after a known interval, for example after 60 seconds. Wazuh does not require this interval. For each value, compute the difference between the end and the start. If a counter decreased, the assumption of a continuous counter may not fit this version or period. Keep both readings, because the delta alone will not show whether its value comes from a change in traffic rate or from a different load pattern. Do not interpret a negative delta as a negative number of events. Verify a reset, a process restart or other counter behavior before drawing further conclusions.
The comparison should answer operational questions: does events_dropped increase, does events_received grow, how do the queues change and does the CPU stay high. Putting these signals together can narrow the area of further diagnosis, but it does not point to the guilty component on its own. For example, high CPU is consistent with computational pressure, but it does not settle whether the limit is the decoders, rule matching or thread synchronization.
Example comparison of two samples
The table illustrates computing differences over the observation period.
| Counter | Start sample | End sample | Delta |
|---|---|---|---|
events_received | 10000 | 10600 | +600 |
events_processed | 9850 | 10440 | +590 |
events_dropped | 50 | 54 | +4 |
In the example, events_received grows by 600 and events_processed grows by 590. The difference between these two deltas is not equivalent to the events_dropped delta, which is 4. The window length matters when assessing the rate, so record the timestamps of both samples. If the interval lasted 60 seconds, your own per-second delta calculation would not define the unit of the *_edps fields; they would be separate measures.
Computing deltas from the state file
The script below reads two samples. The format of the input file is not verified here: verify it in the version you use before applying the script. The script strips quotes, apostrophes and whitespace from the field name and value, and then checks the three required counters.
#!/bin/sh
state=/var/ossec/var/run/wazuh-analysisd.state
first=$(mktemp)
second=$(mktemp)
trap 'rm -f "$first" "$second"' EXIT HUP INT TERM
read_counters() {
awk -F= '
{
gsub(/["\047[:space:]]/, "", $1)
gsub(/["\047[:space:]]/, "", $2)
if ($1 ~ /^(events_received|events_processed|events_dropped)$/) {
print $1 "=" $2
}
}
' "$state"
}
# Capture two samples from the state file.
read_counters > "$first"
sleep 60
read_counters > "$second"
# Require every counter in both samples and flag possible resets.
awk -F= '
FNR == NR { before[$1] = $2; next }
{ after[$1] = $2 }
END {
keys[1] = "events_received"
keys[2] = "events_processed"
keys[3] = "events_dropped"
for (i = 1; i <= 3; i++) {
key = keys[i]
if (!(key in before) || !(key in after)) {
print key, "MISSING"
} else if (after[key] + 0 < before[key] + 0) {
print key, "possible reset"
} else {
printf "%s delta=%.0f\n", key, after[key] - before[key]
}
}
}
' "$first" "$second"
The script does not establish the units of the counters or their semantics. The result rests only on three fields and their two readings. MISSING means the required name was not found in at least one sample. possible reset signals a drop in value between samples; the script then does not compute a delta as an increase.
Queues and threads as hypotheses
The path /var/ossec/etc/local_internal_options.conf is unverified, so check the documentation for your version. For queues, the state file gives the fields <name>_queue_usage and <name>_queue_size. The queue names listed in the documentation are syscheck, syscollector, rootcheck, sca, hostinfo, upgrade, event, rule_matching, alerts, firewall, statistical and archives. The sample field event_queue_usage belongs to this scheme.
The values of these fields describe successive samples, not the history between them. A reading of event_queue_usage=0.53 would be only an example of a numeric format, not a percentage. Put such a field next to its successive readings and other counters from the same period.
The internal options document thread settings such as analysisd.event_threads, syscheck_threads, syscollector_threads, rootcheck_threads, sca_threads, hostinfo_threads, rule_matching_threads, dbsync_threads and winevt_threads. Their default value is 0, which means a choice that depends on the number of CPU cores; the documented range is 0 to 32. This describes the available configuration, not a recommendation to raise all values. Do not interpret the value 0 as disabling threads, since the documentation describes it as a choice that depends on cores.
For these queues, the internal options documentation gives a default value of 16384 and a range of 128 to 2000000. In the option listing, some names appear without the analysisd. prefix; confirm the full names in the internal-options documentation for your version. The listed options are analysisd.decode_event_queue_size, analysisd.decode_syscheck_queue_size, analysisd.decode_syscollector_queue_size, analysisd.decode_rootcheck_queue_size, analysisd.decode_sca_queue_size, analysisd.decode_hostinfo_queue_size, analysisd.decode_output_queue_size, analysisd.decode_winevt_queue_size, archives_queue_size, statistical_queue_size, alerts_queue_size, firewall_queue_size, fts_queue_size, dbsync_queue_size and upgrade_queue_size.
The allowed range is not a tuning target, and an option name does not indicate which queue from the state file it is tied to. The list describes the documented options and their values, not a one-to-one mapping to the <name> fields in the previous list. Raising a limit can change buffering behavior, but without measurement it does not prove the cause was removed or the losses reduced.
Before a change, record the initial values and define which observable result will confirm an improvement, for example a smaller increase of events_dropped at similar traffic.
Deciding on the next change
When measurements point to a problem, state the hypothesis in a way that can be disproved. For example: at comparable traffic, the queue of a specific stage regularly grows, and the events_dropped increase occurs in the same period. Such a statement does not yet prove a causal link, but it gives a concrete direction for a controlled test. A change should cover one parameter or one area, and its effect must be compared with the baseline measurement.
Enlarging the decoding queue is a hypothesis to test, not an approved change. After the test, check the counter deltas, queue behavior, CPU and whether the traffic profile stayed comparable. If no sign of improvement appeared, go back to the baseline and narrow the hypothesis, rather than keeping the change just because the parameter is available. Events can also be lost earlier, in the agent buffer before sending to the manager, as described in the post on the agent buffer.
Conclusion
Record two samples with a timestamp, compute separate deltas of events_received, events_processed and events_dropped, and then compare them with the queue readings and the load from the same period. Measure the rate of counter growth and watch the queues over time, not only their momentary state.