VictoriaLogs: collecting and querying logs centrally

  1. Quick summary
  2. Step 1 — rsyslog collects local logs and forwards them to VictoriaLogs
  3. Step 2 — victoria-logs listens on the syslog port and splits out fields
  4. Step 3 — Logs are stored compressed by column within each _stream
  5. Step 4 — Querying through the HTTP API /select/logsql/query
  6. Step 5 — Telling word filters, field filters and stream filters apart
  7. Step 6 — Statistics with the stats / sort / limit pipes
  8. Common misconceptions
  9. Hands-on 1 — Install VictoriaLogs single-node + systemd
  10. Hands-on 2 — Have rsyslog forward logs into VictoriaLogs
  11. Hands-on 3 — Statistics & time filtering with LogsQL
  12. Hands-on 4 — Visual exploration with vmui + (optional) Grafana
  13. Review questions
  14. Flashcards
  15. Related articles

Estimated time: 45 minutes.

Quick summary

Step 1 — rsyslog collects local logs and forwards them to VictoriaLogs

rsyslog (already running on most Linux systems) reads system logs and uses the omfwd module to push them to VictoriaLogs' syslog port in RFC 5424 format.

This is an ingest path that needs no extra collector.

The RSYSLOG_SyslogProtocol23Format template produces exactly the RFC 5424 framing that VictoriaLogs can parse (syslog ingestion).

After this step, every log that passes through rsyslog has a copy flowing into VictoriaLogs.

*.* action(type="omfwd" target="127.0.0.1" port="5410" protocol="tcp" template="RSYSLOG_SyslogProtocol23Format")

Observe with:

systemctl status rsyslog; cat /etc/rsyslog.d/50-victorialogs.conf

Step 2 — victoria-logs listens on the syslog port and splits out fields

Enabling the -syslog.listenAddr.tcp=:5410 flag makes victoria-logs open the syslog receiving port;

the -httpListenAddr=:9428 flag opens the HTTP port for queries and the UI (syslog ingestion).

When parsing RFC 5424, VictoriaLogs produces the fields app_name, hostname, proc_id, severity, facility, and maps severity to level (info/notice/warning/error...).

These fields go into _stream or become ordinary fields, ready for LogsQL. The snippet below excerpts the key flags from the ExecStart line of the systemd unit; the full unit file is in Hands-on 1.

ExecStart=/usr/local/bin/victoria-logs \
  -storageDataPath=/var/lib/victoria-logs \
  -httpListenAddr=:9428 \
  -syslog.listenAddr.tcp=:5410

Observe with:

ss -ltn | grep -E ':9428|:5410'

Step 3 — Logs are stored compressed by column within each _stream

Every log entry is tied to a _stream (e.g. {app_name="sshd",hostname="web1"}) and a _time.

VictoriaLogs stores the fields by column and compresses them heavily within the scope of a stream (key concepts).

As a result, filtering by _stream and by _time touches only the relevant data instead of scanning everything. This is why queries by source plus time range are usually very fast.

# Count all logs received
curl -s -G 'http://localhost:9428/select/logsql/query' --data-urlencode 'query=* | stats count()'

Observe with:

curl -s -G 'http://localhost:9428/select/logsql/query' --data-urlencode 'query=* | stats count()'

Step 4 — Querying through the HTTP API /select/logsql/query

The /select/logsql/query endpoint takes a query parameter holding a LogsQL expression and returns results as JSON, one log per line (querying).

The same endpoint also serves the built-in UI vmui at /select/vmui for visual querying.

Use --data-urlencode with curl to pass queries containing special characters without escaping them yourself.

curl -s -G 'http://localhost:9428/select/logsql/query' \
  --data-urlencode 'query=hello'

Observe with:

Open http://<host>:9428/select/vmui in a browser

Step 5 — Telling word filters, field filters and stream filters apart

A bare word filter such as error matches a substring in _msg — so a log with app_name="demo" whose message does not contain "demo" will not match demo.

To filter by field use level:error or app_name:nginx; to filter by source use _stream:{app_name="demo"} (LogsQL filters).

Choosing the right type of filter is the difference between "0 results" and "exactly the set of logs you are looking for".

# word filter on _msg
curl -s -G '.../select/logsql/query' --data-urlencode 'query=error'
# field filter
curl -s -G '.../select/logsql/query' --data-urlencode 'query=level:error'
# stream filter by source
curl -s -G '.../select/logsql/query' --data-urlencode 'query=_stream:{app_name="demo"}'

Observe with:

Compare the results of the three queries above

Step 6 — Statistics with the stats / sort / limit pipes

The | stats count() by (field) pipe counts logs grouped by field; chain | sort by (...) and | limit N to order and trim the results (stats pipe).

On a real server, * | stats by (level) count() shows the distribution of log levels (lots of info, few errors) — a quick way to assess system health.

Pipes let you turn raw logs into aggregate numbers right inside the query.

curl -s -G '.../select/logsql/query' \
  --data-urlencode 'query=* | stats by (level) count() | sort by (count) desc'

Observe with:

Cross-check the count for each level/app_name

Common misconceptions

Right: VictoriaLogs is queried with its own LogsQL. Elasticsearch compatibility exists only at the log-ingestion layer (the _bulk API), not at the query layer.

VictoriaLogs accepts logs over many protocols, including the Elasticsearch bulk API, so it can replace ES at the ingest stage (data ingestion: Elasticsearch).

The storage layer is column-oriented, not a Lucene-style inverted index; the query layer uses LogsQL —

a chain of a filter followed by transformation pipes (LogsQL), not the JSON Query DSL of Elasticsearch.

The practical consequence: you do not plug Kibana into VictoriaLogs; you view logs through the built-in UI vmui at /select/vmui or through the VictoriaLogs datasource in Grafana.

Right: A _stream is the set of logs that share the same "stream fields" (similar to Loki labels).

Choosing highly variable fields as stream fields causes an explosion in the number of streams and slows down ingest.

A stream is identified by the set of stream fields chosen at ingest time; each combination of values of those fields forms a separate stream (key concepts: stream fields).

If you use a highly variable field such as request_id or user_id as a stream field, the number of streams grows to nearly the number of log lines — known as high cardinality — which increases RAM usage and reduces speed.

In practice you should pick stable fields with few distinct values, such as app_name and hostname, as stream fields, and leave everything else as ordinary fields.

This also determines how you write _stream:{...} filters.

Right: LogsQL is a chain of pipes: one filter expression, followed by pipes such as stats, sort, limit joined with the | character. PromQL/MetricsQL is for metrics, not logs.

A LogsQL query starts with a filter expression (which selects the log lines), then chains pipes that transform the result with the | character (LogsQL pipes).

A bare word filter (e.g. error) matches on the _msg field; to filter by field use field:value; to filter by source use _stream:{...}; for statistics use | stats count() by (...).

If you are used to Prometheus, keep the two clearly apart: VictoriaMetrics + MetricsQL is for metrics, while VictoriaLogs + LogsQL is for logs — the same ecosystem, but two different query languages.

Hands-on 1 — Install VictoriaLogs single-node + systemd

10 minutes

VictoriaLogs is released from its own repo, VictoriaMetrics/VictoriaLogs (separate from VictoriaMetrics core).

The single-node edition is one binary that runs ingest, storage, and queries.

This lab installs it as a binary running under systemd (no Docker); the archive contains just one file, victoria-logs-prod (quickstart).

# 1. Download, extract, check the version
cd /tmp
curl -fsSL -O https://github.com/VictoriaMetrics/VictoriaLogs/releases/download/v1.50.0/victoria-logs-linux-amd64-v1.50.0.tar.gz
tar xzf victoria-logs-linux-amd64-v1.50.0.tar.gz
./victoria-logs-prod --version

# 2. Install the binary, create a system user and the data directory
sudo install -m 0755 victoria-logs-prod /usr/local/bin/victoria-logs
sudo useradd --system --no-create-home --shell /usr/sbin/nologin victorialogs
sudo mkdir -p /var/lib/victoria-logs
sudo chown victorialogs:victorialogs /var/lib/victoria-logs

# 3. Write the systemd unit
sudo tee /etc/systemd/system/victorialogs.service >/dev/null <<'EOF'
[Unit]
Description=VictoriaLogs single-node
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
User=victorialogs
Group=victorialogs
ExecStart=/usr/local/bin/victoria-logs \
  -storageDataPath=/var/lib/victoria-logs \
  -retentionPeriod=30d \
  -httpListenAddr=:9428 \
  -syslog.listenAddr.tcp=:5410
Restart=on-failure
RestartSec=5
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target
EOF

# 4. Load the unit, enable and start it, then verify
sudo systemctl daemon-reload
sudo systemctl enable --now victorialogs
systemctl is-active victorialogs
ss -ltn | grep -E ':9428|:5410'
curl -s http://localhost:9428/health

-retentionPeriod=30d keeps logs for 30 days (the default is only 7 days); adjust it to your disk capacity (retention).

1. Download and extract the linux-amd64 binary (v1.50.0), then check the version.

The binary is victoria-logs-prod; --version prints the tag v1.50.0 (e.g. victoria-logs-...-tags-v1.50.0-...).

2. Put the binary at /usr/local/bin/victoria-logs and create the systemd unit with the flags -httpListenAddr=:9428 -syslog.listenAddr.tcp=:5410, then enable --now.

systemctl is-active victorialogs → active; ss -ltn shows 0.0.0.0:9428 and 0.0.0.0:5410 in LISTEN state.

Analysis

Observation: After startup, both port 9428 (HTTP) and port 5410 (syslog TCP) are open.

Mechanism: One binary serves ingest (syslog), storage, and the HTTP API/UI at the same time — a hallmark of the single-node edition.

Takeaway: For moderate volumes, single-node is enough; split into a cluster only when you need to scale.

Troubleshooting:

Hands-on 2 — Have rsyslog forward logs into VictoriaLogs

8 minutes

rsyslog uses the omfwd module to push local logs to VictoriaLogs' syslog port in RFC 5424.

The RSYSLOG_SyslogProtocol23Format template is the RFC 5424 framing that VictoriaLogs can parse (syslog ingestion).

echo '*.* action(type="omfwd" target="127.0.0.1" port="5410" protocol="tcp" template="RSYSLOG_SyslogProtocol23Format")' | sudo tee /etc/rsyslog.d/50-victorialogs.conf && sudo systemctl restart rsyslog

1. Add the forwarding config, restart rsyslog, and generate test logs with logger -t demo "hello victorialogs" and logger -t demo -p user.err "simulated error connection refused to db".

rsyslog is active; the two log lines with app_name=demo are pushed over almost instantly (the err line → level=error).

2. Query by source: curl -s -G 'http://localhost:9428/select/logsql/query' --data-urlencode 'query=_stream:{app_name="demo"}'.

It returns JSON with the 2 demo log lines, each having _msg, _time, _stream, app_name, hostname, level.

Analysis

Observation: The syslog entries appear with app_name="demo", hostname, and level already split out.

Mechanism: VictoriaLogs parses RFC 5424 and maps severity → level, putting app_name/hostname into _stream.

Takeaway: A bare word filter matches _msg; to filter by source you must use _stream:{app_name="..."}.

Troubleshooting:

Hands-on 3 — Statistics & time filtering with LogsQL

6 minutes · optional

The stats ... by (...) pipe turns raw logs into aggregate numbers; _time:5m restricts to recent time (LogsQL).

curl -s -G 'http://localhost:9428/select/logsql/query' --data-urlencode 'query=* | stats by (level) count() | sort by (count) desc'

1. Run * | stats by (level) count() and * | stats by (app_name) count() to see the log distribution.

The result comes as group + count, e.g. {"level":"info","count(*)":"32"}, {"level":"error","count(*)":"1"} (the numbers depend on the actual logs on your machine).

2. Filter recent errors: _time:5m level:error.

It returns only the level=error logs from the last 5 minutes.

Hands-on 4 — Visual exploration with vmui + (optional) Grafana

5 minutes · optional

vmui is the built-in UI for typing LogsQL and viewing logs without curl.

Grafana has a VictoriaLogs datasource for building dashboards (VictoriaLogs datasource).

# Open a browser
http://<host>:9428/select/vmui

1. Open http://<host>:9428/select/vmui, then type level:error or _stream:{app_name="demo"}.

An interactive log table, filterable by time; the same results as curl, but visual.

Review questions

Question 1. Which HTTP port does the lab use by default for queries and for opening vmui on the victoria-logs single-node?

  1. :9428

  2. :8428

  3. :5410

  1. :3000

Answer: :9428.

The lab sets -httpListenAddr=:9428 for the HTTP API and /select/vmui. (:8428 is the default port of VictoriaMetrics single-node for metrics; :5410 is the syslog port set in the lab.)

Question 2. Which field does a bare word filter such as error in LogsQL match on by default?

  1. _msg

  2. _stream

  3. app_name

  1. level

Answer: _msg. By default a word filter searches for a substring in _msg (word filter).

To filter on another field you must write field:value explicitly.

Question 3. To get exactly the logs of one source (e.g. app_name="demo"), which LogsQL form is the most appropriate?

  1. _stream:{app_name="demo"}

  2. demo

  3. SELECT * WHERE app="demo"

  1. app=="demo"

Answer: _stream:{app_name="demo"}. Filter by source with the stream filter _stream:{app_name="demo"}.

The word filter demo only searches in _msg, so it misses logs; LogsQL does not use SQL syntax.

Question 4. How does VictoriaLogs differ from VictoriaMetrics?

  1. VictoriaLogs is for logs and uses LogsQL; VictoriaMetrics is for metrics and uses MetricsQL

  2. They are identical, only the names differ

  3. VictoriaLogs is merely a plugin of VictoriaMetrics and cannot run on its own

  1. VictoriaLogs is queried with PromQL

Answer: VictoriaLogs is for logs and uses LogsQL; VictoriaMetrics is for metrics and uses MetricsQL.

VictoriaLogs is an independent product (its own repo, VictoriaMetrics/VictoriaLogs) for logs, queried with LogsQL; VictoriaMetrics is for metrics, queried with MetricsQL (a superset of PromQL).

Flashcards

_msg (message), _time (time), _stream (stream, together with _stream_id).

:9428 — it serves queries at /select/logsql/query and the UI at /select/vmui.

In _msg. To filter on other fields you must write field:value or _stream:{...}.

Stable fields with few distinct values (e.g. app_name, hostname). Avoid high-cardinality fields such as request_id.

vlinsert (ingest), vlstorage (storage), vlselect (queries).

-syslog.listenAddr.tcp=:5410 (or .udp). rsyslog forwards with omfwd + the RFC 5424 template.

* | stats by (level) count() — you can chain | sort by (count) desc.

Related articles

VictoriaLogs: collecting and querying logs centrally