Last active
August 22, 2024 05:12
-
-
Save rleap-m/b7a4495cd8481bad1ab82cf1eb96148f to your computer and use it in GitHub Desktop.
Collects 'docker container ls' output and outputs it to a CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$sleepTimeSec = 10 # Sleep between data collection iteration | |
$durationinMin = 2 # Collect data for this many minutes | |
# Delete the previous file | |
$csvPath = '.\watch-container-status.csv' | |
if (Test-Path -Path $csvPath -PathType Leaf) { | |
Remove-Item -Path $csvPath | |
} | |
$startDate = Get-Date | |
do { | |
$iterationDate = Get-Date -Format s | |
$containersAsJson = docker container ls --format="{{json .}}" | ConvertFrom-Json | |
foreach ($container in $containersAsJson) { | |
$result = [PSCustomObject]@{ | |
'Node' = $ENV:ComputerName | |
'ID' = $container.ID | |
'Name' = $container.Names | |
'Image' = $container.Image | |
'Networks' = $container.Networks | |
'Ports' = $container.Ports | |
'RunningFor' = $container.RunningFor | |
'Status' = $container.Status | |
'Timestamp' = $iterationDate | |
} | |
$result | Select-Object ID,Name,Status | |
$result | Export-Csv -NoTypeInformation -Path $csvPath -Append | |
} | |
Start-Sleep -Seconds $sleepTimeSec | |
} while ((Get-Date) -le ($startDate.AddMinutes($durationinMin))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment