Azure

Plot Azure WebApp Metrics in PowerShell Console Graph

I am sharing a simple PS script which can plot Azure WebApp Requests, Data In and Out stats in PowerShell console

Make sure that you have ‘Graphical’ Module imported with the following PS script:

Install-Module Graphical

Note: Set your preferred values for the parameters as per your setup. ResourceName “manutest” ResourceGroupName “manurg1”

Give Start and End Time accordingly

PS Code is prepared as below:

$RgName = Read-Host “Please enter the Resource Group Name that the Websites belongs to”
$Days= Read-Host “Please enter Last #Days needed to be checked in the report”
$ResourceNames = Get-AzResource -ResourceGroupName $RgName -ResourceType “Microsoft.Web/sites”
foreach ($ResourceName in $ResourceNames)
{
$WebappName = $ResourceName.Name
$URLName=(Get-AzWebApp -Name $WebappName).DefaultHostName
# inputs
 $WarningPreference = ‘SilentlyContinue’
 $TimeGrain = [timespan]::FromHours(1)
 $Start = [datetime]::Now.AddDays(-$Days)
 $End = [datetime]::Now
 
 # capture resource metrics
 $Resource = Get-AzResource -ResourceName $WebappName -ResourceGroupName $RgName -ResourceType “Microsoft.Web/sites”
 $ResourceID = $Resource.ResourceId
 
 $MetricName = ‘BytesSent’
 $Splat = @{
     ResourceId = $ResourceID
     MetricName = $MetricName
     TimeGrain = $TimeGrain
     StartTime = $Start
     EndTime = $End
 }
 $Data = Get-AzMetric @Splat
 $Datpoints = $data.data.average.foreach({[int]$_})
 
 # plot the graph
 Show-Graph -Datapoints $Datpoints -GraphTitle “$MetricName : $URLName” -YAxisStep 5
 Show-Graph -Datapoints $Datpoints -GraphTitle “$MetricName : $URLName” -YAxisStep 5 -Type Line
 Show-Graph -Datapoints $Datpoints -GraphTitle “$MetricName : $URLName” -YAxisStep 5 -Type Scatter
 
 $MetricName = ‘BytesReceived’
 $Splat = @{
     ResourceId = $ResourceID
     MetricName = $MetricName
     TimeGrain = $TimeGrain
     StartTime = $Start
     EndTime = $End
 }
 $Data = Get-AzMetric @Splat
 $Datpoints = $data.data.average.foreach({[int]$_})
 
 # plot the graph
 Show-Graph -Datapoints $Datpoints -GraphTitle “$MetricName : $URLName” -YAxisStep 5
 Show-Graph -Datapoints $Datpoints -GraphTitle “$MetricName : $URLName” -YAxisStep 5 -Type Line
 Show-Graph -Datapoints $Datpoints -GraphTitle “$MetricName : $URLName” -YAxisStep 5 -Type Scatter
 
 $MetricName = ‘Requests’
 $Splat = @{
     ResourceId = $ResourceID
     MetricName = $MetricName
     TimeGrain = $TimeGrain
     StartTime = $Start
     EndTime = $End
 }
 $Data = Get-AzMetric @Splat
 $Datpoints = $data.data.average.foreach({[int]$_})
 
 # plot the graph
 Show-Graph -Datapoints $Datpoints -GraphTitle “$MetricName : $URLName” -YAxisStep 5
 Show-Graph -Datapoints $Datpoints -GraphTitle “$MetricName : $URLName” -YAxisStep 5 -Type Line
 Show-Graph -Datapoints $Datpoints -GraphTitle “$MetricName : $URLName” -YAxisStep 5 -Type Scatter
 }