I am trying to create an Azure Automation workbook that queries a resource for some metrics, and does some scaling up/down based in that metric. I have no idea how I can convert a PSMetricData to integer in order to do comparisons on it. My code at the moment is
$MonitorParameters = @{
ResourceId = "abcde....."
TimeGrain = [TimeSpan]::Parse("00:05:00")
MetricNames = "cpu_percent"
}
$MetricValues = Get-AzMetric @MonitorParameters -DetailedOutput
$Last = $MetricValues.Data[0]
Write-Output $Last
And my output is
Microsoft.Azure.Commands.Insights.OutputClasses.PSMetricValue
I am looking in general for something like: "If the last 5 mins has a cpu_percentage > 70%", then scale up..
Just use
Write-Output $Last.Average
instead ofWrite-Output $Last
, then you will get the specific value.And you should note the newest value got from the command
Get-AzMetric
is before the last one hour, e.g. if now is2:37:00 AM
, then the newest one is1:38:00 AM
, you could not get thelast 5 mins
value, theTimeGrain = [TimeSpan]::Parse("00:05:00")
just means get the value every five mins.Update:
It should work, I create a new elastic pool and test it, it is
0
.My script in the runbook: