我在天蓝色门户网站的监控中添加了一些新的自定义指标, 现在我想使用power shell检索该性能数据并在我的本地机器中创建一个新计数器,我该如何实现呢?
答案 0 :(得分:1)
Azure提供了Service Management Rest API,以使用GET,POST,PUT ..等获取我们需要的指标 this提供了使用x-ms版本等收集所有指标的电源shell,this链接提供了创建性能计数器的方法
因此我们可以使用服务管理API来获取与azure应用程序相对应的数据,这就是我的工作方式。
function activecons()
{
$WMIComputer = Get-WmiObject win32_operatingsystem -ComputerName mycomputer
$curdate=Convert-TimeToUTC -DateTime ($WMIComputer.ConvertToDateTime($WMIComputer.LocalDateTime))
#Write-Host $curdate
add-type -AssemblyName System.Net.Http
add-type -AssemblyName System.Net.Http.WebRequest
$sub = Get-AzureSubscription "subscription name"
$certificate = Get-Item Cert:\CurrentUser\My\urthumbprint
$subscriptionID = $sub.SubscriptionId
$handler = New-Object System.Net.Http.WebRequestHandler
# Add the management cert to the client certificates collection
$handler.ClientCertificates.Add($certificate)
$httpClient = New-Object System.Net.Http.HttpClient($handler)
# Set the service management API version
$httpClient.DefaultRequestHeaders.Add("x-ms-version", "2014-04-01")
#Write-Host "suresh"
$mediaType = New-Object System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/xml")
$httpClient.DefaultRequestHeaders.Accept.Add($mediaType)
$listServicesUri = "https://management.core.windows.net/$subscriptionID/services/WebSpaces/SoutheastAsiawebspace/sites/o penemrmysql/metrics?names=Http2xx,&StartTime=$curdate"
$listServicesTask = $httpClient.GetAsync($listServicesUri)
$listServicesTask.Wait()
if($listServicesTask.Result.IsSuccessStatusCode -eq "True")
{
# Get the results from the API as XML
[xml] $result = $listServicesTask.Result.Content.ReadAsStringAsync().Result
foreach($svc in $result.MetricResponses.MetricResponse)
{
#Write-Host $svc.Data.DisplayName "" $svc.Data.Unit
$global:active= $svc.Data.Values.MetricSample.Total -as [int]
# $activeconnections=$svc.Data.Values.MetricSample.Total -as [int]
# Write-Host $svc.Data.Values.MetricSample.Maximum "suresh"
# Write-Host $svc.Data.StartTime
#Write-Host $active
#return $active
}
}
}
#$curdate=activecons
#$global:active | Get-Member
#Write-Host $global:active
$categoryName = "Azure-HTTP2xx"
$categoryHelp = "A Performance object for HTTP Synthetic Testing"
$categoryType = [System.Diagnostics.PerformanceCounterCategoryType]::MultiInstance
$categoryExists = [System.Diagnostics.PerformanceCounterCategory]::Exists($categoryName)
If (-Not $categoryExists)
{
$objCCDC = New-Object System.Diagnostics.CounterCreationDataCollection
$objCCD1 = New-Object System.Diagnostics.CounterCreationData
$objCCD1.CounterName = "Total No. of Active connections"
$objCCD1.CounterType = "NumberOfItems32"
$objCCD1.CounterHelp = "Number of ms executing the HTTP Synthetic"
$objCCDC.Add($objCCD1) | Out-Null
[System.Diagnostics.PerformanceCounterCategory]::Create($categoryName, $categoryHelp, $categoryType, $objCCDC) | Out-Null
}
$perfInst1a = New-Object System.Diagnostics.PerformanceCounter($categoryName, "Total No. of Active connections", "openemrmysql", $false)
while(1)
{
$curdate=activecons
$rawvalue=$global:active
Write-host "suresh's "+$rawvalue
$perfInst1a.RawValue=$rawvalue
Start-Sleep -Seconds 30
}