forgejo-runner-optimiser/test/local-test.sh
Manuel Ganter 5e470c33a5
All checks were successful
ci / build (push) Successful in 30s
feat(collector): group CPU and memory metrics by cgroup
Add cgroup-based process grouping to the resource collector. Processes are
grouped by their cgroup path, with container names resolved via configurable
process-to-container mapping.

New features:
- Read cgroup info from /proc/[pid]/cgroup (supports v1 and v2)
- Parse K8s resource notation (500m, 1Gi, etc.) for CPU/memory limits
- Group metrics by container using CGROUP_PROCESS_MAP env var
- Calculate usage percentages against limits from CGROUP_LIMITS env var
- Output cgroup metrics with CPU cores used, memory RSS, and percentages

Environment variables:
- CGROUP_PROCESS_MAP: Map process names to container names for discovery
- CGROUP_LIMITS: Define CPU/memory limits per container in K8s notation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-06 14:50:36 +01:00

36 lines
1 KiB
Bash
Executable file

#!/bin/bash
# Local test script to verify cgroup grouping
# Run from project root: ./test/local-test.sh
set -e
echo "Building collector..."
go build -o bin/collector ./cmd/collector
echo ""
echo "Testing cgroup parsing on current system..."
echo "Current process cgroup:"
cat /proc/self/cgroup 2>/dev/null || echo "Cannot read /proc/self/cgroup (expected on macOS)"
echo ""
echo "Running collector for 10 seconds with cgroup grouping..."
echo "Press Ctrl+C to stop early"
echo ""
# Set up test environment variables
# Map common process names to container names
export CGROUP_PROCESS_MAP='{"bash":"shell","collector":"collector","zsh":"shell"}'
export CGROUP_LIMITS='{"shell":{"cpu":"2","memory":"4Gi"},"collector":{"cpu":"1","memory":"1Gi"}}'
# Run collector
timeout 10 ./bin/collector \
--interval=2s \
--top=5 \
--log-format=json \
2>/dev/null || true
echo ""
echo "Test complete!"
echo ""
echo "Note: On macOS, cgroup paths will be empty since cgroups are a Linux feature."
echo "To test properly, run in a Linux container or VM."