From 2520b2b359a57cca2e60bcd2ef27a628c3805f62 Mon Sep 17 00:00:00 2001 From: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Date: Tue, 7 Dec 2021 12:52:30 -0800 Subject: [PATCH] Sync eng/common directory with azure-sdk-tools for PR 2381 (#3162) * Add disk metrics script and template * Support linux disk matrics * Add continueOnError to write-filesystemmetrics.yml Co-authored-by: Patrick Hallisey --- .../steps/write-filesystemmetrics.yml | 7 +++++ .../scripts/Write-FileSystemMetrics.ps1 | 31 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 eng/common/pipelines/templates/steps/write-filesystemmetrics.yml create mode 100644 eng/common/scripts/Write-FileSystemMetrics.ps1 diff --git a/eng/common/pipelines/templates/steps/write-filesystemmetrics.yml b/eng/common/pipelines/templates/steps/write-filesystemmetrics.yml new file mode 100644 index 000000000..5eef3147b --- /dev/null +++ b/eng/common/pipelines/templates/steps/write-filesystemmetrics.yml @@ -0,0 +1,7 @@ +steps: + - task: Powershell@2 + inputs: + filePath: $(Build.SourcesDirectory)/eng/common/scripts/Write-FileSystemMetrics.ps1 + pwsh: true + displayName: Write filesystem metrics + continueOnError: true diff --git a/eng/common/scripts/Write-FileSystemMetrics.ps1 b/eng/common/scripts/Write-FileSystemMetrics.ps1 new file mode 100644 index 000000000..1fc1e6f99 --- /dev/null +++ b/eng/common/scripts/Write-FileSystemMetrics.ps1 @@ -0,0 +1,31 @@ +$drives = [IO.DriveInfo]::GetDrives() | Where-Object { $_.TotalSize -gt 0 -and $_.DriveType -eq 'Fixed' -and $null -ne $_.Name } + +foreach($drive in $drives) { + $entry = [ordered]@{ + "name"= "agent_driveinfo_size_bytes"; + "value"= $drive.TotalSize; + "timestamp"= [DateTimeOffset]::UtcNow; + "labels"= [ordered]@{ + "name"= $drive.Name; + "volumeLabel"= $drive.VolumeLabel; + "driveType"= $drive.DriveType.ToString(); + "driveFormat"= $drive.DriveFormat; + } + } + + Write-Output "logmetric: $($entry | ConvertTo-Json -Compress)" + + $entry = [ordered]@{ + "name"= "agent_driveinfo_available_bytes"; + "value"= $drive.AvailableFreeSpace; + "timestamp"= [DateTimeOffset]::UtcNow; + "labels"= [ordered]@{ + "name"= $drive.Name; + "volumeLabel"= $drive.VolumeLabel; + "driveType"= $drive.DriveType.ToString(); + "driveFormat"= $drive.DriveFormat; + } + } + + Write-Output "logmetric: $($entry | ConvertTo-Json -Compress)" +} \ No newline at end of file