forked from ctigeek/DbSync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreatePerformanceCounters.ps1
38 lines (29 loc) · 1.13 KB
/
CreatePerformanceCounters.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function CreateCounter($counterName)
{
$objCCD1 = New-Object System.Diagnostics.CounterCreationData
$objCCD1.CounterName = $counterName
$objCCD1.CounterType = "NumberOfItems64"
Write-Host "Created performance counter $counterName."
$objCCD1
}
$categoryName = "DbSync"
$categoryExists = [System.Diagnostics.PerformanceCounterCategory]::Exists($categoryName)
If (-Not $categoryExists)
{
$categoryType = [System.Diagnostics.PerformanceCounterCategoryType]::SingleInstance
$objCCDC = New-Object System.Diagnostics.CounterCreationDataCollection
Write-Host "Creating performance counters for category $categoryName."
$counter = CreateCounter("RowsInserted")
$objCCDC.Add($counter) | Out-Null
$counter = CreateCounter("RowsUpdated")
$objCCDC.Add($counter) | Out-Null
$counter = CreateCounter("RowsDeleted")
$objCCDC.Add($counter) | Out-Null
$counter = CreateCounter("RowsErrored")
$objCCDC.Add($counter) | Out-Null
[System.Diagnostics.PerformanceCounterCategory]::Create($categoryName, "", $categoryType, $objCCDC) | Out-Null
}
if ($categoryExists)
{
Write-Host "It already exists."
}