Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

fix: Fix some path handling in collect-windows-logs script #2488

Merged
merged 1 commit into from
Dec 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions scripts/collect-windows-logs.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
$lockedFiles = "kubelet.err.log", "kubelet.log", "kubeproxy.log", "kubeproxy.err.log", "containerd.err.log", "containerd.log", "azure-vnet-telemetry.log"
$lockedFiles = "kubelet.err.log", "kubelet.log", "kubeproxy.log", "kubeproxy.err.log", "containerd.err.log", "containerd.log", "azure-vnet-telemetry.log", "azure-vnet.log"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to add azure-vnet-ipam.log here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure why not. I haven't seen it fail on that file but if azure-vnet.log can be locked this one probably can too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting - I don't have a c:\k\azure-vnet-ipam.log

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just azure-vnet-ipam.json - is that what you meant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took azure-vnet-ipam.log back out and rebased to keep the history clean

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strange


$timeStamp = get-date -format 'yyyyMMdd-hhmmss'
$zipName = "$env:computername-$($timeStamp)_logs.zip"

# The leading , forces array output. However, if there are no logs in c:\k\*.log, there's a null entry. That needs to be filtered later
$paths = , (get-childitem c:\k\*.log -Exclude $lockedFiles)
$paths += $lockedFiles | Foreach-Object { $src = "c:\k\$_" ; if (Test-Path $src) {Copy-Item $src . -Passthru -ErrorAction Ignore } }
$paths = @()
get-childitem c:\k\*.log* -Exclude $lockedFiles | Foreach-Object {
$paths += $_
}
$lockedTemp = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName())
New-Item -Type Directory $lockedTemp
$lockedFiles | Foreach-Object {
Write-Host "Copying $_ to temp"
$src = "c:\k\$_"
if (Test-Path $src) {
$tempfile= Copy-Item $src $lockedTemp -Passthru -ErrorAction Ignore
if ($tempFile) {
$paths += $tempFile
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a good idea to add a log statement here like "Fetching ETW events, this may take a while..." because this takes a while and the first time I rant he script I thought it hung copying files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok new output:

.\collect-windows-logs.ps1


    Directory: C:\Users\azureuser\AppData\Local\Temp


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       12/21/2019  12:16 AM                nz3m4hge.ctn
Copying kubelet.err.log to temp
Copying kubelet.log to temp
Copying kubeproxy.log to temp
Copying kubeproxy.err.log to temp
Copying containerd.err.log to temp
Copying containerd.log to temp
Copying azure-vnet-telemetry.log to temp
Copying azure-vnet.log to temp
Exporting ETW events to CSV files
WARNING: The names of some imported commands from the module 'helper' include unapproved verbs that might make them less
discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list  of approved verbs, type Get-Verb.
File c:\k\debug\dumpVfpPolicies.ps1 already exists.
File c:\k\debug\hns.psm1 already exists.
File c:\k\debug\starthnstrace.cmd already exists.
File c:\k\debug\startpacketcapture.cmd already exists.
File c:\k\debug\stoppacketcapture.cmd already exists.
File c:\k\debug\portReservationTest.ps1 already exists.
WARNING: The names of some imported commands from the module 'hns' include unapproved verbs that might make them less discoverable.   To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved    verbs, type Get-Verb.
C:\k\debug\tj5otk5h.5uh
WARNING: The names of some imported commands from the module 'helper' include unapproved verbs that might make them less
discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list  of approved verbs, type Get-Verb.
File c:\k\debug\VFP.psm1 already exists.
Logs are available at C:\k\debug\tj5otk5h.5uh
Compressing all logs to 2758k8s010-20191221-121625_logs.zip



FullName                                                                     Length
--------                                                                     ------
C:\k\azure-vnet-telemetry.log.1                                             5252718
C:\k\azure-vnet-telemetry.log.2                                             5247427
C:\k\azure-vnet-telemetry.log.3                                             5245465
C:\k\azure-vnet-telemetry.log.4                                             5248190
C:\k\azure-vnet-telemetry.log.5                                             5243766
C:\k\azure-vnet-telemetry.log.6                                             5245985
C:\k\azure-vnet-telemetry.log.7                                             5245989
C:\k\azure-vnet.log.1                                                       5243524
C:\k\azure-vnet.log.2                                                       5243613
C:\k\azure-vnet.log.3                                                       5243571
C:\k\azure-vnet.log.4                                                       5242931
C:\k\azure-vnet.log.5                                                       5243187
C:\k\azure-vnet.log.6                                                       5245861
C:\k\azure-vnet.log.7                                                       5243308
C:\k\kubelet.err-20191211T032141.867.log                                    1048609
C:\k\kubelet.err-20191211T081458.750.log                                    1048447
C:\k\kubelet.err-20191211T130814.621.log                                    1048342
C:\k\kubelet.err-20191211T180129.501.log                                    1048300
C:\k\kubelet.err-20191212T011812.436.log                                    1048585
C:\k\kubelet.err-20191212T075412.704.log                                    1048357
C:\k\kubelet.err-20191212T144517.626.log                                    1048505
C:\k\kubelet.err-20191212T195233.336.log                                    1048715
C:\k\kubelet.err-20191212T223313.374.log                                    1048088
C:\k\kubelet.err-20191212T223313.375.log                                        107
C:\k\kubelet.err-20191212T223313.391.log                                        451
C:\k\kubelet.err-20191219T205751.077.log                                    1048601
C:\k\kubelet.err-20191219T225931.084.log                                    1047781
C:\k\kubelet.err-20191219T225931.086.log                                        107
C:\k\kubelet.err-20191219T225931.101.log                                        279
C:\k\kubelet.err-20191220T010050.419.log                                    1048191
C:\k\kubelet.err-20191220T010050.420.log                                        102
C:\k\kubelet.err-20191220T010050.435.log                                        322
C:\k\kubeproxy-20191215T101807.586.log                                      1048612
C:\k\kubeproxy-20191217T230149.480.log                                      1048608
C:\k\kubeproxy.err-20191212T060357.408.log                                  1048632
C:\k\kubeproxy.err-20191218T160308.890.log                                  1048654
C:\k\kubeproxy.err-20191220T181856.436.log                                  1048612
C:\k\windowsnodereset.log                                                      1800
C:\Users\azureuser\AppData\Local\Temp\nz3m4hge.ctn\kubelet.err.log           584131
C:\Users\azureuser\AppData\Local\Temp\nz3m4hge.ctn\kubelet.log                 4729
C:\Users\azureuser\AppData\Local\Temp\nz3m4hge.ctn\kubeproxy.log             355635
C:\Users\azureuser\AppData\Local\Temp\nz3m4hge.ctn\kubeproxy.err.log         192080
C:\Users\azureuser\AppData\Local\Temp\nz3m4hge.ctn\azure-vnet-telemetry.log 1093156
C:\Users\azureuser\AppData\Local\Temp\nz3m4hge.ctn\azure-vnet.log            211162
C:\Users\azureuser\AppData\Local\Temp\\20191221-121625_services.csv
C:\Users\azureuser\AppData\Local\Temp\\20191221-121625_hyper-v-compute-operational.csv
C:\Users\azureuser\AppData\Local\Temp\\20191221-121625_docker.csv
C:\Users\azureuser\AppData\Local\Temp\\20191221-121625_pagefile.txt
C:\k\debug\tj5otk5h.5uh\arp.txt
C:\k\debug\tj5otk5h.5uh\docker.txt
C:\k\debug\tj5otk5h.5uh\dynamicportrange.txt
C:\k\debug\tj5otk5h.5uh\endpoint.txt
C:\k\debug\tj5otk5h.5uh\Ethernet 2_int.txt
C:\k\debug\tj5otk5h.5uh\excludedportrange.txt
C:\k\debug\tj5otk5h.5uh\hcsdiag.txt
C:\k\debug\tj5otk5h.5uh\hnsdiag.txt
C:\k\debug\tj5otk5h.5uh\ip.txt
C:\k\debug\tj5otk5h.5uh\mtu.txt
C:\k\debug\tj5otk5h.5uh\network.txt
C:\k\debug\tj5otk5h.5uh\networkdetailed.txt
C:\k\debug\tj5otk5h.5uh\nmscrub.txt
C:\k\debug\tj5otk5h.5uh\nvspinfo.txt
C:\k\debug\tj5otk5h.5uh\policy.txt
C:\k\debug\tj5otk5h.5uh\ports.txt
C:\k\debug\tj5otk5h.5uh\reservedports.txt
C:\k\debug\tj5otk5h.5uh\routes.txt
C:\k\debug\tj5otk5h.5uh\tcpconnections.txt
C:\k\debug\tj5otk5h.5uh\vEthernet (Ethernet 2)_int.txt
C:\k\debug\tj5otk5h.5uh\vEthernet (nat)_int.txt
C:\k\debug\tj5otk5h.5uh\vfpOutput.txt
C:\k\debug\tj5otk5h.5uh\vswitchForwarding.txt
C:\k\debug\tj5otk5h.5uh\winver.txt




    Directory: C:\Users\azureuser


Mode          LastWriteTime  Length Name
----          -------------  ------ ----
-a---- 12/21/2019  12:16 AM 3258444 2758k8s010-20191221-121625_logs.zip

Write-Host Exporting ETW events to CSV files
$scm = Get-WinEvent -FilterHashtable @{logname='System';ProviderName='Service Control Manager'} | Where-Object { $_.Message -Like "*docker*" -or $_.Message -Like "*kub*" } | Select-Object -Property TimeCreated, Id, LevelDisplayName, Message
# 2004 = resource exhaustion, other 5 events related to reboots
$reboots = Get-WinEvent -ErrorAction Ignore -FilterHashtable @{logname='System'; id=1074,1076,2004,6005,6006,6008} | Select-Object -Property TimeCreated, Id, LevelDisplayName, Message
Expand All @@ -24,7 +38,7 @@ Invoke-WebRequest -UseBasicParsing https://raw.githubusercontent.com/Microsoft/S
& 'c:\k\debug\collectlogs.ps1' | write-Host
$netLogs = Get-ChildItem (Get-ChildItem -Path c:\k\debug -Directory | Sort-Object LastWriteTime -Descending | Select-Object -First 1).FullName | Select-Object -ExpandProperty FullName
$paths += $netLogs
$pathsFiltered = $paths | Where-Object { $_ -ne $null }
Write-Host Compressing all logs to $zipName
Compress-Archive -LiteralPath $pathsFiltered -DestinationPath $zipName
$paths | Format-Table FullName, Length -AutoSize
Compress-Archive -LiteralPath $paths -DestinationPath $zipName
Get-ChildItem $zipName # this puts a FileInfo on the pipeline so that another script can get it on the pipeline