fix(aw): harden collectors and grafana exports

This commit is contained in:
igor04091968
2026-05-28 10:54:46 +03:00
parent 524ab33f63
commit cc9e4a0669
29 changed files with 1181 additions and 131 deletions
+14 -5
View File
@@ -170,10 +170,19 @@ function Get-1CFileInfobases {
}
function Get-HostSample {
$os = Get-CimInstance Win32_OperatingSystem
$cpuSample = Get-CimInstance Win32_Processor -ErrorAction SilentlyContinue |
Measure-Object -Property LoadPercentage -Average
$cpu = if ($cpuSample.Count -gt 0 -and $null -ne $cpuSample.Average) { [double]$cpuSample.Average } else { 0 }
$cpu = 0.0
$ramPct = 0.0
try {
Add-Type -AssemblyName Microsoft.VisualBasic -ErrorAction Stop
$computerInfo = New-Object Microsoft.VisualBasic.Devices.ComputerInfo
$totalMemory = [double]$computerInfo.TotalPhysicalMemory
$availableMemory = [double]$computerInfo.AvailablePhysicalMemory
if ($totalMemory -gt 0) {
$ramPct = (($totalMemory - $availableMemory) / $totalMemory) * 100
}
} catch {
Write-RunLog ("warning: host memory sample fallback reason={0}" -f $_.Exception.Message)
}
$disk = Get-PSDrive -Name E -ErrorAction SilentlyContinue
$rdp = (quser 2>$null | Select-Object -Skip 1 | Measure-Object).Count
@@ -181,7 +190,7 @@ function Get-HostSample {
ts = (Get-Date).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
host = $env:COMPUTERNAME
cpu_pct = [math]::Round($cpu, 2)
ram_pct = [math]::Round((($os.TotalVisibleMemorySize - $os.FreePhysicalMemory) / $os.TotalVisibleMemorySize) * 100, 2)
ram_pct = [math]::Round($ramPct, 2)
disk_free_gb = if ($disk) { [math]::Round($disk.Free / 1GB, 2) } else { 0 }
disk_latency_ms = 0
smb_errors = 0