Skip to content

Commit

Permalink
Update AzcopyThroughput.ps1
Browse files Browse the repository at this point in the history
improvement: can analyze the log even if the log is not completed, created a validation if the variable $tf is empty or not to avoid dividing a int per zero.

Also create a validation if the auxiliar file exists, to avoid send a instruction to delete something that not exists.
  • Loading branch information
tilimpo committed Oct 4, 2023
1 parent a12e4b1 commit 4f2d670
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions utils/AzcopyThroughput.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<#
<#
.SCRIPT SYNOPSIS
Analyzes the azcopy log, and collects transfer metrics to generate a repot
.Description
This script will collect transfer metrics from azcopy log and generate a csv
.Parameter AzCopy log
.Parameter JsonFile
Mandatory: This item is the Resource Group Name that will be used
Alias: F
Expand Down Expand Up @@ -65,14 +65,12 @@ Write-Host "`n Loading Azcopy log ($path)......" -ForegroundColor Yellow
$timer=[system.diagnostics.stopwatch]::StartNew()
$logname = (Get-ChildItem $path).BaseName

# Read log, and save into auxiliary file, with all the information about azcopy metrics


# Read log, and save into auxiliar file, with all the information about azcoy metrics
$reader = [IO.File]::OpenText($path)
while ($reader.Peek() -ge 0) {
$line = $reader.ReadLine()
if ($line -match 'Mb/s'){
$line | Out-File -FilePath C:\temp\auxiliaryfile_$logname.log -Append
$line | Out-File -FilePath C:\temp\auxiliarfile_$logname.log -Append
}elseif($line -match 'Total Number of Transfers'){
$totalfiles = $line
break
Expand All @@ -82,21 +80,24 @@ $reader.Dispose()
# Get the total files to transfer
$tf=$totalfiles -split ':', 2

# Convert the auxiliary file in a CSV to be imported in HTML report
# Convert the auxiliar file in a CSV to be imported in HTML report
$azcopyvalues = @()
$azvalues = Get-Content -Path "C:\temp\auxiliaryfile_$logname.log"
$azvalues = Get-Content -Path "C:\temp\auxiliarfile_$logname.log"
foreach ($azvalue in $azvalues){
$item = New-Object -TypeName PSObject
$params=$azvalue -split ',', 7
foreach ($param in $params[0]){
$value=$param -split ' ', 3
$item | Add-Member -MemberType NoteProperty -Name "timestamp" -Value $value[1]
if ($tf){}else{ $item | Add-Member -MemberType NoteProperty -Name "Percentage" -Value $value[2] }
}
# calculate the Percentage base on done files
foreach ($param in $params[1]){
$value = $param -split ' ', 3
$value = [math]::Round(([int]$value[1]*100)/[int]$tf[1], 2)
$item | Add-Member -MemberType NoteProperty -Name "Percentage" -Value $value
if ($tf){
$value = [math]::Round(([int]$value[1]*100)/[int]$tf[1], 2)
$item | Add-Member -MemberType NoteProperty -Name "Percentage" -Value $value
}
}
foreach ($param in $params[6]){
$value = $param -split ' ', 6
Expand All @@ -107,7 +108,10 @@ foreach ($azvalue in $azvalues){
}

$azcopyvalues | ConvertTo-Csv -NoTypeInformation -Delimiter ";" | % {$_ -replace '"',''} | Out-File C:\temp\ReporAzCopy_$logname.csv
Remove-Item C:\temp\auxiliaryfile_$logname.log

if(Test-Path -Path "C:\temp\auxiliarfile_$logname.log"){
Remove-Item C:\temp\auxiliarfile_$logname.log
}

$timer.Stop()
Write-Host 'Duration:' $timer.Elapsed -ForegroundColor Green

0 comments on commit 4f2d670

Please sign in to comment.