Report uptime from the agents, and stop the Integrations page overflowing a phone
Linux agent 8 and Windows agent 7 say how long the machine has been up; the server stores it (migration 0086) and shows it as Up for in the status strip (left out while offline) and Uptime on the server page. The Integrations header wraps and its button no longer squeezes, and .table-responsive is positioned so hidden text in scrolled-off columns cannot widen the page. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d88a24b33a
commit
41fbbf3467
18 files changed
+9161
-10
No files matched your search
@@ -17,7 +17,7 @@ set -euo pipefail
|
||||
# 4 = also reports failed services, disk health (SMART) and ZFS pools, reads pacman, and can update itself when told to
|
||||
# 5 = also says what the machine is (maker, model, serial number), from the firmware, for the inventory
|
||||
# 6 = also says what it could not collect and why (no smartctl, no systemd, a package manager that failed ...), so the server can say what to fix
|
||||
AGENT_VERSION=7
|
||||
AGENT_VERSION=8
|
||||
|
||||
ENV_FILE="${ENV_FILE:-/etc/homelab-manager-agent.env}"
|
||||
if [[ -f "$ENV_FILE" ]]; then
|
||||
@@ -579,6 +579,13 @@ collect_system_info() {
|
||||
cpu_load_percent=$(awk -v l="$load1" -v c="$cpu_cores" 'BEGIN { printf "%.1f", (l/c)*100 }')
|
||||
fi
|
||||
|
||||
# How long the host has been up: the first figure in /proc/uptime, in seconds. null if it cannot be read.
|
||||
local uptime_seconds="null"
|
||||
if [[ -r /proc/uptime ]]; then
|
||||
uptime_seconds=$(awk '{ printf "%d", $1 }' /proc/uptime 2>/dev/null || true)
|
||||
[[ "$uptime_seconds" =~ ^[0-9]+$ ]] || uptime_seconds="null"
|
||||
fi
|
||||
|
||||
local mem_total=0 mem_used=0
|
||||
if command -v free >/dev/null 2>&1; then
|
||||
read -r mem_total mem_used < <(free -b | awk '/^Mem:/ {print $2, $3}')
|
||||
@@ -648,11 +655,13 @@ collect_system_info() {
|
||||
--argjson cpu_load_percent "$cpu_load_percent" \
|
||||
--argjson mem_total_bytes "${mem_total:-0}" \
|
||||
--argjson mem_used_bytes "${mem_used:-0}" \
|
||||
--argjson uptime_seconds "$uptime_seconds" \
|
||||
--argjson disks "$disks_json" \
|
||||
'{
|
||||
ip_addresses: $ip_addresses,
|
||||
cpu: { model: $cpu_model, cores: $cpu_cores, load_percent: $cpu_load_percent },
|
||||
memory: { total_bytes: $mem_total_bytes, used_bytes: $mem_used_bytes },
|
||||
uptime_seconds: $uptime_seconds,
|
||||
disks: $disks,
|
||||
listening_ports: $listening_ports,
|
||||
updates: $updates,
|
||||
|
||||
@@ -36,7 +36,7 @@ $ErrorActionPreference = 'Stop'
|
||||
# 3 = can replace itself with the newer script when an administrator has switched that on in Homelab Manager
|
||||
# 4 = also reports services that have failed, disk health, Storage Spaces pools and what the machine is (maker, model, serial)
|
||||
# 5 = also says what it could not collect and why, so Homelab Manager can say what to fix
|
||||
$script:AgentVersion = 6
|
||||
$script:AgentVersion = 7
|
||||
|
||||
$script:DefaultConfigPath = Join-Path $env:ProgramData 'HomelabManager\agent.json'
|
||||
|
||||
@@ -432,6 +432,10 @@ function Get-SystemInfo($Config = $null) {
|
||||
$load = ($cpus | Where-Object { $null -ne $_.LoadPercentage } | Measure-Object -Property LoadPercentage -Average).Average
|
||||
$cores = ($cpus | Measure-Object -Property NumberOfLogicalProcessors -Sum).Sum
|
||||
|
||||
# How long it has been up, in seconds (null if Windows does not say when it started).
|
||||
$uptime = $null
|
||||
try { if ($os.LastBootUpTime) { $uptime = [int64][math]::Floor(((Get-Date) - $os.LastBootUpTime).TotalSeconds); if ($uptime -lt 1) { $uptime = $null } } } catch { }
|
||||
|
||||
$disks = @()
|
||||
foreach ($d in @(Get-CimInstance -ClassName Win32_LogicalDisk -Filter 'DriveType=3')) {
|
||||
if (-not $d.Size) { continue } # an unformatted or unavailable volume
|
||||
@@ -468,6 +472,7 @@ function Get-SystemInfo($Config = $null) {
|
||||
ip_addresses = @($ips)
|
||||
cpu = [ordered]@{ model = [string]($cpus[0].Name).Trim(); cores = [int]$cores; load_percent = $(if ($null -ne $load) { [math]::Round([double]$load, 1) } else { $null }) }
|
||||
memory = [ordered]@{ total_bytes = $totalBytes; used_bytes = ($totalBytes - $freeBytes) }
|
||||
uptime_seconds = $uptime
|
||||
disks = @($disks)
|
||||
listening_ports = @(Get-ListeningPorts)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user