tuwunel 1.9.4 exports no metrics. The host collector gets an httpcheck receiver on the gateway's /_matrix/client/versions (new services.hyperhive.otel.httpChecks, declared by hive-matrix), and a timer in the hive-matrix container pushes the database directory's size through the forwarder's OTLP port, as the attic cache-size unit does. The size step dereferences the state directory's symlink and pushes nothing for a result under 4096 bytes.
37 lines
1.6 KiB
Nix
37 lines
1.6 KiB
Nix
# The hive-matrix container's database-size step: measures a directory and
|
|
# pushes the byte count as the gauge `hyperhive.matrix.database_bytes` to the
|
|
# forwarder's OTLP/HTTP metrics receiver on loopback.
|
|
#
|
|
# `dir` is a `DynamicUser` unit's `/var/lib/<name>`, which systemd makes a
|
|
# symlink to `/var/lib/private/<name>`. `--dereference-args` measures the
|
|
# directory behind the link and works unchanged when `dir` is a real
|
|
# directory; without it `du` reports the link itself (a few bytes).
|
|
#
|
|
# A result under 4096 bytes is not a database, since a directory entry alone
|
|
# is that big: the step warns on stderr and pushes nothing, so the gauge
|
|
# stays absent rather than wrong.
|
|
#
|
|
# Pure function — NOT a NixOS module. Needs `du`, `cut`, `date` and `curl`.
|
|
{ lib }:
|
|
{ dir, otlpPort }:
|
|
''
|
|
set -euo pipefail
|
|
|
|
bytes="$(du --summarize --bytes --dereference-args ${lib.escapeShellArg dir} | cut -f1)"
|
|
case "$bytes" in
|
|
"" | *[!0-9]*)
|
|
echo "du answered a non-number: bytes='$bytes'" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
if [ "$bytes" -lt 4096 ]; then
|
|
echo "warning: ${dir} measures $bytes bytes, too small for a database; pushing nothing" >&2
|
|
exit 0
|
|
fi
|
|
|
|
printf '{"resourceMetrics":[{"resource":{"attributes":[{"key":"service.name","value":{"stringValue":"hive-matrix"}}]},"scopeMetrics":[{"metrics":[{"name":"hyperhive.matrix.database_bytes","gauge":{"dataPoints":[{"asInt":"%s","timeUnixNano":"%s"}]}}]}]}]}' \
|
|
"$bytes" "$(date +%s%N)" |
|
|
curl --fail --silent --show-error --max-time 20 \
|
|
-H 'Content-Type: application/json' --data-binary @- \
|
|
http://127.0.0.1:${toString otlpPort}/v1/metrics
|
|
''
|