68 lines
2.0 KiB
Bash
Executable File
68 lines
2.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -Eeuo pipefail
|
|
|
|
section() {
|
|
printf '\n## %s\n' "$1"
|
|
}
|
|
|
|
run_optional() {
|
|
local command_name="$1"
|
|
shift
|
|
|
|
if command -v "$command_name" >/dev/null 2>&1; then
|
|
"$command_name" "$@" 2>&1 || true
|
|
else
|
|
printf '%s is not installed\n' "$command_name"
|
|
fi
|
|
}
|
|
|
|
section "Collection"
|
|
printf 'collected_at=%s\n' "$(date --iso-8601=seconds)"
|
|
printf 'collector_version=1\n'
|
|
|
|
section "Operating system"
|
|
if [[ -r /etc/os-release ]]; then
|
|
sed -n -E '/^(NAME|VERSION|VERSION_ID|VERSION_CODENAME|PRETTY_NAME)=/p' /etc/os-release
|
|
fi
|
|
run_optional uname -a
|
|
run_optional timedatectl status
|
|
|
|
section "CPU"
|
|
run_optional lscpu
|
|
|
|
section "Memory"
|
|
run_optional free -h
|
|
run_optional swapon --show --bytes
|
|
if command -v sudo >/dev/null 2>&1 && sudo -n true 2>/dev/null && command -v dmidecode >/dev/null 2>&1; then
|
|
sudo -n dmidecode --type memory 2>/dev/null \
|
|
| sed -n -E '/^[[:space:]]*(Error Correction Type|Size|Form Factor|Locator|Bank Locator|Type|Speed|Configured Memory Speed):/p'
|
|
else
|
|
printf 'dmidecode skipped: passwordless sudo or dmidecode is unavailable\n'
|
|
fi
|
|
|
|
section "Block devices"
|
|
run_optional lsblk --output NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS,MODEL
|
|
run_optional df --human-readable --print-type
|
|
|
|
section "Network link state"
|
|
for interface_path in /sys/class/net/*; do
|
|
[[ -e "$interface_path" ]] || continue
|
|
interface_name="${interface_path##*/}"
|
|
interface_state="$(cat "$interface_path/operstate" 2>/dev/null || printf 'unknown')"
|
|
printf '%s state=%s\n' "$interface_name" "$interface_state"
|
|
if command -v ethtool >/dev/null 2>&1 && [[ "$interface_name" != "lo" ]]; then
|
|
ethtool "$interface_name" 2>/dev/null \
|
|
| sed -n -E '/^[[:space:]]*(Speed|Duplex|Auto-negotiation|Link detected):/p' || true
|
|
fi
|
|
done
|
|
|
|
section "Container runtime"
|
|
run_optional docker version
|
|
if command -v docker >/dev/null 2>&1; then
|
|
docker compose version 2>&1 || true
|
|
fi
|
|
|
|
section "Security notice"
|
|
printf '%s\n' 'This collector intentionally omits IP addresses, MAC addresses, serial numbers and machine UUIDs.'
|
|
|