Skip to content

Filebeat and Kafka ingest

This guide shows how to ship MongoDB and Couchbase audit logs (and MySQL and MongoDB slow-operation logs) from the database hosts to QubeSight with Elastic Filebeat, which writes to QubeSight's built-in Kafka (Redpanda).

Community Enterprise

How it works

flowchart LR
  F[Filebeat on the DB host] -- Kafka 9092 SASL/SCRAM, or 9093 TLS --> R[QubeSight Kafka, topic filebeat-db-logs]
  R --> W[Worker: MongoDB / Couchbase parsers] --> E[Event table]

Filebeat reads the audit file and writes each line, in its own envelope, to the topic filebeat-db-logs. No registration is needed in QubeSight: every host that sends logs appears automatically, listed by its IP address. Filebeat waits for Kafka's acknowledgement and resends what was not acknowledged, so delivery is at least once (a duplicate is possible, a loss is not).

Only Filebeat envelopes are accepted on this topic. Any other message on it goes to the unrecognised-logs queue, so a holder of the Filebeat credentials cannot inject events that look like another product.

Prerequisites

  • Filebeat installed on the database host (the generated configuration uses a filestream input and the Kafka output).
  • MongoDB Enterprise or Couchbase Server Enterprise with native auditing (see Native database audit logs).
  • TCP 9092 open from the database host to QubeSight (single server: the server address; cluster with a virtual IP: the virtual IP and the per-broker ports shown on the page). With ingest TLS in a cluster, TCP 9093 (virtual IP: 19190 plus the broker id) instead.

Step 1: open the Filebeat page

Open Data Sources → Stream Sources → Filebeat. The page shows:

  • The switch Filebeat ingestion on / Filebeat ingestion off.
  • Sources, Total events and Supported database types.
  • Detected sources: every sending host with its source tag, Sender IP, event count and last time (No data flowing yet. Start Filebeat on the source server … until the first line arrives).
  • The audit steps for MongoDB and Couchbase, and the /etc/filebeat/filebeat.yml for the selected type, ready to copy.
  • Address to put into Filebeat (output.kafka.hosts), the topic, and the firewall ports to open (shown when the broker ports are known).
  • Kafka credentials (SASL/SCRAM): User, Mechanism and Password.

Filebeat tab: Kafka credentials (user qs-filebeat, SCRAM-SHA-256, password hidden with Show), one detected MongoDB source with its address, event count and last time, the filebeat.yml sample and the MongoDB audit steps.

Step 2: get the Kafka credentials

Kafka authentication with SASL/SCRAM is on by default for new installations. The Filebeat user (qs-filebeat) may only write to the filebeat-db-logs topic; the mechanism is SCRAM-SHA-256.

  • Only an administrator can see the password: Show reveals it, and Copy password then appears. Every reveal is written to the audit trail.
  • In the sample filebeat.yml the password is the placeholder <FILEBEAT_PASSWORD>; while the password is revealed, the sample shows the real password instead. Replace the placeholder, or better, store it in the Filebeat keystore:

    filebeat keystore add FILEBEAT_KAFKA_PASSWORD
    

    and use password: "${FILEBEAT_KAFKA_PASSWORD}".

If the page says Kafka authentication is off, the installation predates SASL. Run ./install.sh --enable-kafka-auth on the server to turn it on; Filebeat clients then need the user name and password. See install.sh options.

Step 3: configure Filebeat

  1. Turn on auditing in the database (the page lists the steps; see also Native database audit logs).
  2. Copy the generated configuration to /etc/filebeat/filebeat.yml on the database host. Remove the input block of a database you do not monitor. A configuration for MongoDB looks like this:

    filebeat.inputs:
      - type: filestream
        id: mongodb-audit
        enabled: true
        paths:
          - /var/log/mongodb/audit.json
        tags: ["mongodb"]
    
    output.kafka:
      hosts: ["192.0.2.10:9092"]
      topic: "filebeat-db-logs"
      username: "qs-filebeat"
      password: "${FILEBEAT_KAFKA_PASSWORD}"
      sasl.mechanism: SCRAM-SHA-256
      required_acks: -1
      compression: gzip
    
    queue.mem:
      flush.min_events: 1
      flush.timeout: 1s
    
    processors:
      - add_host_metadata: ~
      - add_locale: ~
    

    For Couchbase the input reads /opt/couchbase/var/lib/couchbase/logs/audit.log with the tag couchbase.

  3. Start Filebeat: systemctl enable --now filebeat.

Addresses in a cluster

  • With a virtual IP: put only <virtual-ip>:9092 into Filebeat. The brokers advertise themselves on the virtual IP with one port per broker (19090 plus the broker id); these ports are not written into Filebeat, but they must be open from the Filebeat host to the virtual IP, because after the first connection Filebeat talks to each partition leader directly.
  • Without a virtual IP: list every broker address. With a single address, writing stops when that broker is down.
  • AWS cluster (internal Network Load Balancer): list the three addresses <NLB>:19190, :19191 and :19192 (Kafka TLS); the page generates them. Also lower the TCP retransmission limit on the Filebeat server (from 2.0.111 the page shows this step and a comment at the top of filebeat.yml):

    echo 'net.ipv4.tcp_retries2 = 6' | sudo tee /etc/sysctl.d/90-qubesight-filebeat.conf && sudo sysctl --system
    

    If Filebeat runs in a container, set it for that container only: docker run --sysctl net.ipv4.tcp_retries2=6 …. Why: when the cluster node that leads the Filebeat topic stops, the load balancer drops the open connection to that node without telling Filebeat. With the Linux default (15) Filebeat notices only when the kernel gives up retransmitting, about 15 to 17 minutes later, and sending waits until then (nothing is lost; the lines are sent afterwards). With 6 it moves to the new leader within about half a minute. On premises (virtual IP) this is not needed.

TLS (cluster with ingest TLS)

When ingest TLS is enabled in a cluster, the page generates the TLS form of the configuration: the address uses port 9093 and the output trusts the installation's root certificate:

  ssl.enabled: true
  ssl.certificate_authorities: ["/etc/filebeat/qubesight-ca.crt"]

Download the root certificate to that path from https://<qubesight-address>:3000/api/v1/tls/ca.crt. See Syslog and Kafka TLS.

Slow-operation logs

The same Filebeat can ship the MySQL slow query log (with multiline joining at # Time: or # User@Host:) and mongod.log for MongoDB slow operations. They are stored as measurements only when the kind is turned on; see Slow-operation logs.

Verification

  1. Once data flows, the host appears under Detected sources with its Sender IP, and Total events increases.
  2. Platform → Pipeline → Parsing → Built-in parsers shows lines for Filebeat (MongoDB / Couchbase).
  3. Search the operation in Reports; the source is filebeat:<host-name>.

Turning ingestion off

The switch stops writing Filebeat events. While it is off, live logs from Filebeat are not written and are lost for good; they are not collected retroactively when ingestion is turned back on, and Filebeat clients keep sending. Use it only on purpose; a confirmation is required.

Troubleshooting

Symptom Cause and action
Host does not appear Port 9092 (or 9093 / the virtual-IP broker ports) blocked; wrong address; Filebeat not running. Check journalctl -u filebeat.
Filebeat logs SASL authentication errors Wrong password or mechanism; the password placeholder was not replaced.
Filebeat connects, then fails to write The per-broker ports on the virtual IP are not open from the Filebeat host.
AWS cluster: Filebeat stops sending for about 15 minutes after a cluster node stops, then catches up net.ipv4.tcp_retries2 is still the default 15 on the Filebeat server; set it to 6 (see Addresses in a cluster).
A few lines at the end of the file arrive only when the next line is written Filebeat closed the file after 5 minutes without new lines while its output was waiting; the next write reopens it. Nothing is lost. A live audit log is written continuously, so this shows only in tests.
Couchbase N1QL events without statement text Query audit events (28672 and above) are disabled in Couchbase's audit settings.
Events appear in the unrecognised-logs queue The file is not a MongoDB or Couchbase audit file, or Filebeat was configured to decode the JSON itself. Ship the raw line.

Limitations

  • Built-in parsers on this path cover MongoDB and Couchbase audit logs and the MySQL and MongoDB slow-operation logs. Other files shipped through Filebeat are not parsed; use syslog with a parse rule for them.
  • All Filebeat clients share one Kafka user.
  • The Kafka topic is replicated three times only in a cluster with three brokers; a single server has one copy.