Update Ping_Monitor.ps1
Improved output formatting
This commit is contained in:
@@ -1,16 +1,22 @@
|
|||||||
# Define the IP addresses to monitor
|
# Define the IP addresses to monitor
|
||||||
$addresses = @(
|
$addresses = @()
|
||||||
|
$addressDefinitions = @(
|
||||||
"1.1.1.1",
|
"1.1.1.1",
|
||||||
"1.0.0.1",
|
"1.0.0.1",
|
||||||
"8.8.8.8-9" # Using range notation for cleaner definition
|
"8.8.8.8-9" # Using range notation for cleaner definition
|
||||||
) | ForEach-Object {
|
|
||||||
if ($_ -match "(\d+\.\d+\.\d+\.)(\d+)-(\d+)") {
|
)
|
||||||
|
|
||||||
|
foreach ($addr in $addressDefinitions) {
|
||||||
|
if ($addr -match "(\d+\.\d+\.\d+\.)(\d+)-(\d+)") {
|
||||||
$prefix = $matches[1]
|
$prefix = $matches[1]
|
||||||
$start = [int]$matches[2]
|
$start = [int]$matches[2]
|
||||||
$end = [int]$matches[3]
|
$end = [int]$matches[3]
|
||||||
$start..$end | ForEach-Object { "$prefix$_" }
|
for ($i = $start; $i -le $end; $i++) {
|
||||||
|
$addresses += "$prefix$i"
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$_
|
$addresses += $addr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,11 +99,11 @@ try {
|
|||||||
$stats[$addr].TotalTime += $responseTime
|
$stats[$addr].TotalTime += $responseTime
|
||||||
$stats[$addr].SuccessCount++
|
$stats[$addr].SuccessCount++
|
||||||
|
|
||||||
# Update rolling queue of samples
|
# Update rolling queue of samples - suppress output
|
||||||
if ($stats[$addr].Samples.Count -eq 60) {
|
if ($stats[$addr].Samples.Count -eq 60) {
|
||||||
$stats[$addr].Samples.Dequeue()
|
[void]$stats[$addr].Samples.Dequeue()
|
||||||
}
|
}
|
||||||
$stats[$addr].Samples.Enqueue($responseTime)
|
[void]$stats[$addr].Samples.Enqueue($responseTime)
|
||||||
|
|
||||||
# Update min/max
|
# Update min/max
|
||||||
$stats[$addr].MinTime = [Math]::Min($stats[$addr].MinTime, $responseTime)
|
$stats[$addr].MinTime = [Math]::Min($stats[$addr].MinTime, $responseTime)
|
||||||
@@ -126,7 +132,7 @@ try {
|
|||||||
[math]::Round((Get-Mean $stats[$addr].Samples), 1)
|
[math]::Round((Get-Mean $stats[$addr].Samples), 1)
|
||||||
} else { 0 }
|
} else { 0 }
|
||||||
|
|
||||||
# Calculate trend based on last 5 samples
|
# Calculate trend based on last 5 samples - suppress output
|
||||||
$trend = if ($stats[$addr].Samples.Count -ge 5) {
|
$trend = if ($stats[$addr].Samples.Count -ge 5) {
|
||||||
$recent = @([array]($stats[$addr].Samples))
|
$recent = @([array]($stats[$addr].Samples))
|
||||||
$lastFive = $recent[-[Math]::Min(5, $recent.Count)..-1]
|
$lastFive = $recent[-[Math]::Min(5, $recent.Count)..-1]
|
||||||
|
|||||||
Reference in New Issue
Block a user