PowerShell ile App Service Metric bilgisini yazdirmak

Ornegin bir rapor hazirlamak istesek.. Bu raporda, butun abonelilklerdeki butun App Service Plan kaynaklarinin (ASP) son 10 gun icindeki Memory ve CPU degerlerinin ortalamasi olsa. Nasil olur? Bence guzel olur. Nasil mi? Iste boyle

$data = @()
$data+=”subname, starttime,endtime,aspname,cpupercentage,memorypercentage”

$startTime = “2021-01-21T00:00”
$endTime = “2021-02-21T00:00”

$subs = (Get-AzSubscription)

foreach($sub in $subs){

select-azsubscription -SubscriptionID $sub.ID

$subname = $sub.name

$ASPs = Get-AzAppServicePlan

foreach($asp in $ASPs){
$ID = $asp.ID
$aspName = $asp.name

$CPUPercentage = (Get-AzMetric -ResourceId “$ID” -TimeGrain 00:01:00 -StartTime $startTime -EndTime $endTime -MetricName “CPUPercentage” -DetailedOutput | select -ExpandProperty data | measure average -Average).AVERAGE

$MemoryPercentage = (Get-AzMetric -ResourceId “$ID” -TimeGrain 00:01:00 -StartTime $startTime -EndTime $endTime -MetricName “MemoryPercentage” -DetailedOutput | select -ExpandProperty data | measure average -Average).AVERAGE

$data += “$subname, $starttime, $endtime, $aspname, $cpupercentage, $memorypercentage”

}

}

$data | ft

$outputstarttime = $startTime.replace(“:”,”“) $outputendtime = $endTime.replace(“:”,”“)
$reportName = “AppService_memory_CPU_raporu”

$outputfilename = “./temp/”+$reportName+”“+$outputstarttime+”“+$outputendtime+”.csv”

$data | out-file $outputfilename

Sonuc asagidaki gibi olur. Tabi benim demo ortamimda sadece 1 tane App Service Plan oldugu icin rapor cok heybetli durmadi 🙂

Leave a Reply

Your email address will not be published.