AkurAI Build
Menu

Public repository / 6e34fed0c66d04e240e149b8861eab61b0c02ee1

AkurAI-Monitor / scripts/check-metric-contract.sh

Latest change 8bade644cef8ddaa358cc88eb6017c8e64d5a6e4 - AKURAI-MONITOR-7 monitor processes, docker, systemd; fix #errors alert delivery by Ólafur Búi Ólafsson

#!/usr/bin/env bash
set -euo pipefail

ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
# Source the same names used by the Titan push wrapper; fail if the wrapper
# drifts from the contract or if the Rust collector drops a required metric.
# shellcheck source=scripts/metric-contract.sh
source "$ROOT/scripts/metric-contract.sh"
agent=$ROOT/scripts/titan-monitor-agent
collector=$ROOT/src/collectors.rs

for name in "$METRIC_CPU_USAGE" "$METRIC_MEM_TOTAL" "$METRIC_MEM_USED" \
  "$METRIC_MEM_AVAILABLE" "$METRIC_MEM_USED_PCT" "$METRIC_DISK_ROOT_TOTAL" \
  "$METRIC_DISK_ROOT_USED" "$METRIC_DISK_ROOT_USED_PCT" "$METRIC_LOAD_1M" \
  "$METRIC_LOAD_5M" "$METRIC_LOAD_15M" "$METRIC_UPTIME" \
  "$METRIC_SYSTEMD_FAILED" "$METRIC_DOCKER_RUNNING"; do
  grep -Fq "$name" "$collector"
done
for variable in METRIC_CPU_USAGE METRIC_MEM_TOTAL METRIC_MEM_USED \
  METRIC_MEM_AVAILABLE METRIC_MEM_USED_PCT METRIC_DISK_ROOT_TOTAL \
  METRIC_DISK_ROOT_USED METRIC_DISK_ROOT_USED_PCT METRIC_LOAD_1M \
  METRIC_LOAD_5M METRIC_LOAD_15M METRIC_UPTIME \
  METRIC_SYSTEMD_FAILED METRIC_DOCKER_RUNNING; do
  grep -Fq "$variable" "$agent"
done

# proc./systemd./docker. entity namespaces must exist in both the in-process
# collector and the Titan push agent, even though the entity segment itself
# (process/unit/container name) is dynamic and can't be a fixed constant.
for prefix in 'proc.' 'systemd.' 'docker.'; do
  grep -Fq "\"$prefix" "$collector" || {
    echo "Rust collector must emit the ${prefix} entity namespace" >&2
    exit 1
  }
  grep -Fq "${prefix}" "$agent" || {
    echo "Titan agent must emit the ${prefix} entity namespace" >&2
    exit 1
  }
done

grep -Fq 'sleep 1' "$agent"
grep -Fq 'METRIC_NET_SAMPLING' "$ROOT/scripts/metric-contract.sh"
grep -Fq 'mount != "/"' "$collector" || {
  echo 'Rust collector must emit the canonical root disk namespace' >&2
  exit 1
}