Skip to content

Instantly share code, notes, and snippets.

@gbiellem
Last active March 12, 2017 07:44
Show Gist options
  • Save gbiellem/cf71538808397b0dd55b1b9f24a169d7 to your computer and use it in GitHub Desktop.
Save gbiellem/cf71538808397b0dd55b1b9f24a169d7 to your computer and use it in GitHub Desktop.
Create NServiceBus Performance counters without the NSB Powershell DLL
#requires -RunAsAdministrator
Function InstallNSBPerfCounters {
$category = @{Name="NServiceBus"; Description="NServiceBus statistics"}
$counters = New-Object System.Diagnostics.CounterCreationDataCollection
$counters.AddRange(@(
New-Object System.Diagnostics.CounterCreationData "Critical Time", "Age of the oldest message in the queue.", NumberOfItems32
New-Object System.Diagnostics.CounterCreationData "SLA violation countdown", "Seconds until the SLA for this endpoint is breached.", NumberOfItems32
New-Object System.Diagnostics.CounterCreationData "# of msgs successfully processed / sec", "The current number of messages processed successfully by the transport per second.", RateOfCountsPerSecond32
New-Object System.Diagnostics.CounterCreationData "# of msgs pulled from the input queue /sec", "The current number of messages pulled from the input queue by the transport per second.", RateOfCountsPerSecond32
New-Object System.Diagnostics.CounterCreationData "# of msgs failures / sec", "The current number of failed processed messages by the transport per second.", RateOfCountsPerSecond32
))
$install = $false
if ([System.Diagnostics.PerformanceCounterCategory]::Exists($category.Name)) {
$existingCounters = ([System.Diagnostics.PerformanceCounterCategory]::GetCategories() | ? CategoryName -eq $category.Name).GetCounters()
if ($existingCounters.Count -ne $counters.Count) {
$install = $true
}
else {
foreach ($counter in $counters) {
$found = $existingCounters | ? CounterName -eq $counter.CounterName | ? CounterType -eq $counter.CounterType | ? CounterHelp -eq $counter.CounterHelp
if (-not $found) {
$install = $true
break
}
}
}
}
else {
$install = $true
}
if ($install) {
if ([System.Diagnostics.PerformanceCounterCategory]::Exists($category.Name)) {
[System.Diagnostics.PerformanceCounterCategory]::Delete($category.Name)
}
[void] [System.Diagnostics.PerformanceCounterCategory]::Create($category.Name, $category.Description, [System.Diagnostics.PerformanceCounterCategoryType]::MultiInstance, $counters)
[System.Diagnostics.PerformanceCounter]::CloseSharedResources()
}
}
InstallNSBPerfCounters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment