Vote count:
0
I am trying to write 2 scripts in powershell to create and manage perfmon counters.
The first is to create the counters. I found out the following code:
# [System.Diagnostics.PerformanceCounterCategory]::Delete("<categoryNameGoesHere>")
$categoryName = "OffBox-HTTP"
$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 = "Execution-Time-in-ms"
$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, "Execution-Time-in-ms", "www.xbox.com", $false)
As far as I understand, the category will be deleted each time I run this script toghether with the counters in it. If so - how can I avoid it? If I will remove the category delete command, will it stay for each script execution and the new counter will be added to it?
The second one is to update the counter value. I wrote this script, but obviously I create each time a new counter. The question is if this is the correct way, or will it add counter duplicates to the category?
Param(
[string]$category_name,
[string]$counter_name,
[int]$counter_value
)
$categoryExists = [System.Diagnostics.PerformanceCounterCategory]::Exists($category_name)
# If category does not exist yet:
If (-Not $categoryExists)
{
Write-Error "Category does not exist!"
exit
}
# create counter:
$perfmonCounter = New-Object System.Diagnostics.PerformanceCounter($category_name, $counter_name, $false)
#set counter value
$perfmonCounter.RawValue = $counter_value
asked 53 secs ago
Perfrormance counters in powershell
Aucun commentaire:
Enregistrer un commentaire