all repos — zion-terminal @ 66508a0a605214d34c7a2231848d44ee63b394b2

dotfiles

opt/zion-terminal/bin/zion-collect (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
#!/usr/bin/env bash
# ZION TERMINAL - Coletor de metricas (cache + ring-buffer)
# Cyberdeck criado por Pablo Murad em 2026
# Executado por timer systemd (a cada 60s) e no boot.
export LC_ALL=C
. /opt/zion-terminal/bin/zion-lib.sh 2>/dev/null
mkdir -p /run/zion
CSV=/opt/zion-terminal/logs/metricas.csv
MAX=120   # ~2h a 60s

# --- Metricas lentas -> cache (para MOTD/status rapidos) ---
if tailscale status >/dev/null 2>&1; then ts=conectado; else ts=parado; fi
if timeout 3 curl -fsS -o /dev/null --max-time 3 http://connectivitycheck.gstatic.com/generate_204 2>/dev/null; then net=disponivel; else net=indisponivel; fi
upd=$(apt list --upgradable 2>/dev/null | grep -vc Listing)
{
  echo "TS_ESTADO=$ts"
  echo "INTERNET=$net"
  echo "UPDATES=$upd"
  echo "ATUALIZADO_EM=$(date '+%H:%M:%S')"
} > /run/zion/status 2>/dev/null

# --- Ring-buffer para sparklines (timestamp,temp,cpu,rampct) ---
temp=$(zion_temp_c); cpu=$(zion_cpu_pct); ram=$(zion_ram_pct)
printf '%s,%s,%s,%s\n' "$(date +%s)" "$temp" "$cpu" "$ram" >> "$CSV" 2>/dev/null
# manter apenas as ultimas MAX linhas
if [ -f "$CSV" ]; then tail -n "$MAX" "$CSV" > "$CSV.tmp" 2>/dev/null && mv "$CSV.tmp" "$CSV"; fi