Лучший отвечающий
Запись в счетчик производительности

Вопрос
-
Powrshell умеет создавать свои счетчики производительности (new-object System.Diagnostics.CounterCreationData) и читать данные из счетчиков (Get-Counter -Counter...)
А как записать значение в свой счетчик?
26 августа 2013 г. 9:46
Ответы
-
$categoryName = "Custom Performance Counter" $exists = [System.Diagnostics.PerformanceCounterCategory]::Exists($categoryName) if ($exists) { [System.Diagnostics.PerformanceCounterCategory]::Delete($categoryName) } $counterData = New-Object System.Diagnostics.CounterCreationDataCollection $counter = New-Object System.Diagnostics.CounterCreationData $counter.CounterType = [System.Diagnostics.PerformanceCounterType]::AverageCount64 $counter.CounterName = "Total_Clients" $counterData.Add($counter) $counter = new-object System.Diagnostics.CounterCreationData $counter.CounterType = [System.Diagnostics.PerformanceCounterType]::AverageBase $counter.CounterName = "Total_Clients Base" $counterData.Add($counter) [System.Diagnostics.PerformanceCounterCategory]::Create( $categoryName, $categoryName, [System.Diagnostics.PerformanceCounterCategoryType]::SingleInstance, $counterData ) # Установим значение для счетчика $counter = New-Object System.Diagnostics.PerformanceCounter("Custom Performance Counter","Total_Clients",$false) $counter.RawValue = 100 # Вывод PS 1 > (Get-Counter "\Custom Performance Counter\Total_Clients").CounterSamples.RawValue 100
- Помечено в качестве ответа Андрей Каптелин 26 августа 2013 г. 18:29
26 августа 2013 г. 18:14Отвечающий
Все ответы
-
Обновляйте свойство - PerformanceCounter.RawValue Property
- Предложено в качестве ответа Dmitriy VereshchakMicrosoft contingent staff, Moderator 26 августа 2013 г. 11:08
26 августа 2013 г. 11:05Отвечающий -
Обновляйте свойство - PerformanceCounter.RawValue Property
Это понятно. Осталось понять как это сделать не в С, C# и VB, а в powershell. Ну или vbs.26 августа 2013 г. 17:21 -
$categoryName = "Custom Performance Counter" $exists = [System.Diagnostics.PerformanceCounterCategory]::Exists($categoryName) if ($exists) { [System.Diagnostics.PerformanceCounterCategory]::Delete($categoryName) } $counterData = New-Object System.Diagnostics.CounterCreationDataCollection $counter = New-Object System.Diagnostics.CounterCreationData $counter.CounterType = [System.Diagnostics.PerformanceCounterType]::AverageCount64 $counter.CounterName = "Total_Clients" $counterData.Add($counter) $counter = new-object System.Diagnostics.CounterCreationData $counter.CounterType = [System.Diagnostics.PerformanceCounterType]::AverageBase $counter.CounterName = "Total_Clients Base" $counterData.Add($counter) [System.Diagnostics.PerformanceCounterCategory]::Create( $categoryName, $categoryName, [System.Diagnostics.PerformanceCounterCategoryType]::SingleInstance, $counterData ) # Установим значение для счетчика $counter = New-Object System.Diagnostics.PerformanceCounter("Custom Performance Counter","Total_Clients",$false) $counter.RawValue = 100 # Вывод PS 1 > (Get-Counter "\Custom Performance Counter\Total_Clients").CounterSamples.RawValue 100
- Помечено в качестве ответа Андрей Каптелин 26 августа 2013 г. 18:29
26 августа 2013 г. 18:14Отвечающий