4.2 An Example of Querying Performance Counters
The following example demonstrates how a PLA client, such as a performance counter consumer, uses the Performance Logs and Alerts Protocol to query for performance counter values.
-
HRESULT CollectPerformanceCounter (Machine, DCSName, CounterName, SampleInterval, MaxSamples) { // Create the DataCollectorSet and the IPerformanceCounterDataCollector MULTI_QI mqi CoCreateInstance (Machine, NULL, Machine, COSERVERINFO, 1, mqi) DataSet = (IDataCollectorSet*)mqi.pItf Dataset->get_DataCollectors (DataCollectorCollection) DataCollectorCollection->CreateDataCollector (plaPerformanceCounter, DataCollector) DataCollector->QueryInterface (PerformanceCounterDataCollectorID, PerformanceCounterCollector) // Set the properties of the IPerformanceCounterDataCollector PerformanceCounterCollector->SampleInterval = SampleInterval PerformanceCounterCollector->SegmentMaxRecords = MaxSamples PerformanceCounterArray = SafeArrayCreateVector(VT_BSTR, 0, 1) SafeArrayPutElement(PerformanceCounterArray, 0, CounterName) PerformanceCounterCollector->PerformanceCounters (PerformanceCounterArray) // Commit the data collector and start it DataSet->Commit (DCSName, NULL, plaCreateOrModify, NULL) DataSet->Start (VARIANT_TRUE) } int main (char** argv, int argc) { // Network name of the PLA server Machine = target-machine // Name of the Data Collector Set to create DCSName = CounterSample // Counter to collect CounterName = \Process(*)\% Processor Time // Collect a sample every second SampleInterval = 1 // Collect no more than 1000 samples MaxSamples = 1000 CollectPerformanceCounter(Machine, DCSName, CounterName, SampleInterval, MaxSamples) }