PlotWebAppMetricsasGraphGallery.ps1
<#PSScriptInfo
.VERSION 1.0 .GUID c3a0985b-2117-41c9-9016-12a528746fe3 .AUTHOR Manu Philip .COMPANYNAME cloudcompute.info .COPYRIGHT .TAGS .LICENSEURI .PROJECTURI .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES .PRIVATEDATA #> <# .DESCRIPTION Plot Azure WebApp Metrics in Shell as Graph #The following PowerShell code can print Azure WebApp metrics as Graphical form 'DataIn, DataOut, Requests' for each days for selected number of days $Important Note: Install Graphical module before you run the code in shell. #Install-Module Graphical #The script is ready to use. Copy the code and save as PS1 file #When executing, the script will ask for the resource group name and number of days needed in report #After the completing the script, you will get graphical metrics of each websites within the shell #Hope the script helps you out in your daily Azure tasks #> Param() $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 } |