Skip to content

Commit

Permalink
add windows exporter logs (monitoring namespace) to troubleshooting s…
Browse files Browse the repository at this point in the history
…cript (#607)
  • Loading branch information
bragi92 authored Sep 26, 2023
1 parent 59a8bca commit 1641939
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions internal/scripts/troubleshoot/TroubleshootError.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,50 @@ try {
Write-Host ("Logs for $podName have been saved to $($podName)_promcollector.log and $($podName)__addontokenadapterwin.log")
$iterationCount++
}

# Collect windows exporter pod logs if it exits

Write-Host("Checking whether the winndows exporter pods are running correctly in the monitoring namespace...")
$ds = kubectl get ds -n monitoring -o json --field-selector metadata.name=windows-exporter | ConvertFrom-Json
if (($null -eq $ds) -or ($null -eq $ds.Items) -or ($ds.Items.Length -ne 1)) {
Write-Host( "windows exporter daemonset pod not scheduled or failed to schedule." + $contactUSMessage)
}
else {
$dsStatus = $ds.Items[0].status

if (
(($dsStatus.currentNumberScheduled -eq $dsStatus.desiredNumberScheduled) -and
($dsStatus.numberAvailable -eq $dsStatus.currentNumberScheduled) -and
($dsStatus.numberAvailable -eq $dsStatus.numberReady)) -eq $false) {

Write-Host( "windows exporter daemonset pod not scheduled or failed to schedule.") -ForegroundColor Red
Write-Host($dsStatus)
}
else {

Write-Host( "windows exporter daemonset pod(s) running OK.") -ForegroundColor Green

$iterationCount = 0
$maxIterations = 15
# Get windows exporter daemonset pod logs
$podNames = kubectl get pods -n monitoring -l app=windows-exporter -o jsonpath='{.items[*].metadata.name}' | ForEach-Object { $_.Trim() -split '\s+' }
foreach ($podName in $podNames) {
if ($iterationCount -ge $maxIterations) {
Write-Host "Maximum iteration count reached ($maxIterations) Exiting loop."
break
}

# Get logs from prometheus-collector container and store in a file
$windowsExporterLogPath = "$debuglogsDir/$($podName).log"
kubectl logs $($podName) -n monitoring > $windowsExporterLogPath

Write-Host ("Logs for $podName have been saved to $($podName).log")
$iterationCount++
}


}
}
}
}
catch {
Expand Down

0 comments on commit 1641939

Please sign in to comment.