Disk Probe
Demonstrates the built‑in disk space probe (auto‑registered) and how to override it with custom thresholds.
Full source
File: pwsh/tutorial/examples/16.6-Health-Disk-Probe.ps1
<#
Sample: Disk Probe
Purpose: Shows the auto-registered disk probe and how to override with custom thresholds.
File: 16.6-Health-Disk-Probe.ps1
Notes: Demonstrates the use of a custom disk probe with specific health thresholds.
#>
param(
[int]$Port = 5000,
[IPAddress]$IPAddress = [IPAddress]::Loopback
)
## 1. Logging
New-KrLogger | Add-KrSinkConsole | Register-KrLogger -Name 'console' -SetAsDefault
## 2. Server
New-KrServer -Name 'Health Disk Probe'
## 3. Listener (port 5000)
Add-KrEndpoint -Port $Port -IPAddress $IPAddress
#
# Override disk probe by registering a custom one with same name
## 5. Override auto disk probe with custom logic
Add-KrHealthProbe -Name 'disk' -Tags 'self', 'infra' -ScriptBlock {
# Simulated values for clarity in documentation (replace with real drive stats if desired)
$total = 100GB
$free = 12GB
$percent = [math]::Round(($free / $total) * 100, 2)
$status = if ($percent -lt 5) { 'Unhealthy' } elseif ($percent -lt 15) { 'Degraded' } else { 'Healthy' }
$data = [Collections.Generic.Dictionary[string, object]]::new()
$data['freePercent'] = $percent
$data['totalBytes'] = $total
$data['freeBytes'] = $free
New-KrProbeResult $status "Free=$percent%" -Data $data
}
## 6. Enable configuration
Enable-KrConfiguration
## 7. Health endpoint
Add-KrHealthEndpoint -Pattern '/healthz' -DefaultTags 'self', 'infra'
## 8. Start server
Start-KrServer -CloseLogsOnExit
Step-by-step
- Use the default disk probe or override it by registering a probe with the same name.
- Set thresholds for Healthy/Degraded/Unhealthy.
- Include percentage and byte metrics in the data for dashboards.
- Start the server and query
/healthz.
Try It
Invoke-RestMethod http://127.0.0.1:5005/healthz | ConvertTo-Json -Depth 4
Override Strategy
Use scripted logic to tailor thresholds for specific disks or mount points. You can also add multiple disk probes differentiated by name (e.g., disk-root, disk-data).
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| Always Healthy | Thresholds too low | Tighten degraded/unhealthy cutoffs |
| Probe missing | Override failed | Ensure names match (disk) |
References
- New-KrLogger
- New-KrServer
- Add-KrEndpoint
- Enable-KrConfiguration
- Add-KrHealthProbe
- Add-KrHealthEndpoint
- Start-KrServer
- New-KrProbeResult
Previous / Next
Previous: C# Probe Next: Response Format