Export to ClickHouse#
Store the keepalives and map snapshots of your targets in ClickHouse, through the OpenTelemetry Collector’s ClickHouse exporter. The exporter writes OTLP logs to one table and each kind of metric to a table of its own.
This is a do-it-yourself example to get started from, not an integration that shirudo ships or maintains. Adapt retention, access control and sizing to your deployment. To check the keepalives’ quotes and compare each target with its upatch tree as well, start from the Backend instead.
Before you begin#
Targets that export to a collector, as Monitor and export telemetry describes, with the collector’s
otlpreceiver set up there.The OpenTelemetry Collector Contrib distribution,
otelcol-contrib, built with Go 1.24 or later. The contrib distribution includes the ClickHouse exporter; Go 1.24 offers the hybrid key exchange the targets require.A ClickHouse server the collector can reach, and a user for the collector that may create its database and tables and insert into them.
The exporter’s log support is beta and its metric support alpha.
Set up the exporter#
Create the database and the collector’s user:
CREATE DATABASE shirudo; CREATE USER otel IDENTIFIED BY '<password>'; GRANT CREATE DATABASE, CREATE TABLE, INSERT, SELECT ON shirudo.* TO otel;
Add the exporter and the pipelines to the collector’s configuration, next to the
otlpreceiver:exporters: clickhouse: endpoint: tcp://<clickhouse-host>:9440?secure=true database: shirudo username: otel password: ${env:CLICKHOUSE_PASSWORD} create_schema: true ttl: 720h sending_queue: batch: flush_timeout: 5s min_size: 5000 service: pipelines: logs: receivers: [otlp] exporters: [clickhouse] metrics: receivers: [otlp] exporters: [clickhouse]
create_schemalets the exporter create its tables,otel_logsfor logs andotel_metrics_gauge,otel_metrics_sumand their siblings for metrics. It also runsCREATE DATABASE IF NOT EXISTSat every start, which needs theCREATE DATABASEgrant even though the database exists. Set it tofalseto create the tables yourself.ttldrops rows older than 30 days.CLICKHOUSE_PASSWORDcomes from the collector’s environment.Restart the collector.
Check the data#
List the latest keepalives:
SELECT Timestamp, ResourceAttributes['host.name'] AS host, JSONExtractString(Body, 'verdict') AS verdict FROM shirudo.otel_logs WHERE ServiceName = 'shirudo' AND EventName = 'shirudo.keepalive' ORDER BY Timestamp DESC LIMIT 10;
Bodyholds the keepalive body, the JSON string the target’s TPM quoted, and the queries read its keys withJSONExtractand its kin. shirudo status lists the keys. A target sends a keepalive every minute, so each target shows up within a minute or two of the restart.Show the last verdict of every target and when it last reported:
SELECT ResourceAttributes['host.name'] AS host, argMax(JSONExtractString(Body, 'verdict'), Timestamp) AS verdict, max(Timestamp) AS last_seen FROM shirudo.otel_logs WHERE ServiceName = 'shirudo' AND EventName = 'shirudo.keepalive' GROUP BY host ORDER BY last_seen;
A target at the top whose
last_seenfalls behind has stopped sending, and averdictother thanokneeds a look, as Monitor and export telemetry describes under what to alert on.Read the map snapshots of one upatch:
SELECT Timestamp, LogAttributes['shirudo.map.name'] AS map, Body FROM shirudo.otel_logs WHERE EventName = 'shirudo.bpf.map.snapshot' AND LogAttributes['shirudo.upatch.name'] = '<upatch>' ORDER BY Timestamp DESC LIMIT 10;
Bodyholds what the map’s decoder returned, or the map’s entries when the upatch ships no decoder. A decoder that emits metrics writes to the metric tables instead.
Alert on the data#
Each query below returns one row for every target that needs a look, so an alert fires when a query returns rows. Run them on a schedule, from Grafana with its ClickHouse data source or from any tool that can run SQL. Monitor and export telemetry explains each signal under what to alert on.
Find targets that stopped sending keepalives. Ten minutes covers several keepalive intervals and a tree sync of a few minutes, which holds the config operation lock that a keepalive waits for; a target whose tree syncs run for longer needs a longer threshold:
SELECT ResourceAttributes['host.name'] AS host, max(Timestamp) AS last_seen FROM shirudo.otel_logs WHERE ServiceName = 'shirudo' AND EventName = 'shirudo.keepalive' GROUP BY host HAVING last_seen < now() - INTERVAL 10 MINUTE;
Find targets that reported a verdict other than
okin the last five minutes:SELECT ResourceAttributes['host.name'] AS host, JSONExtractString(Body, 'verdict') AS verdict, max(Timestamp) AS last_seen FROM shirudo.otel_logs WHERE ServiceName = 'shirudo' AND EventName = 'shirudo.keepalive' AND Timestamp > now() - INTERVAL 5 MINUTE AND verdict != 'ok' GROUP BY host, verdict;
Find targets whose guards refused operations in the last ten minutes:
SELECT ResourceAttributes['host.name'] AS host, JSONExtractString(Body, 'boot_id') AS boot, max(arraySum(JSONExtract(Body, 'tamper', 'Array(UInt64)'))) - min(arraySum(JSONExtract(Body, 'tamper', 'Array(UInt64)'))) AS new_attempts FROM shirudo.otel_logs WHERE ServiceName = 'shirudo' AND EventName = 'shirudo.keepalive' AND Timestamp > now() - INTERVAL 10 MINUTE GROUP BY host, boot HAVING new_attempts > 0;
tamperlists every counter, so their sum is the number of refusals since boot. The counters only grow within a boot and start at zero at the next, so the query compares the keepalives of one boot,boot_id, and a reboot in the window reports nothing.integritylists the integrity counters the same way; the query withintegrityin place oftamperfinds targets that refused a change to their running kernel.
Next steps#
OTLP documents for every field a target sends
Write a Lua decoder to turn a map into log records or metrics
Export to Grafana to chart the same data
Backend to check the quotes and the tree state the keepalives report
SIEM export for how the records reach a backend and what to build on them