Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Monitor Your Applications With Vista's Performance Logs and Alerts : Page 5

Instrument real-time and logged performance monitoring in your applications with the new Performance Logs and Alerts API.


advertisement
Creating Data Collectors
Adding data collectors using the RPM is the preferred method for creating collectors; however, you can also create them programmatically using the IDataCollectorSet.DataCollectors property:

// Create a simple performance counter collector IPerformanceCounterDataCollector performanceCollector = (IPerformanceCounterDataCollector) collectorSet.DataCollectors.CreateDataCollector( DataCollectorType.plaPerformanceCounter); performanceCollector.name = @"Sample performance counter collector"; performanceCollector.PerformanceCounters = new string[] { @"\Process(*)\% Processor Time" }; performanceCollector.SampleInterval = 5; // Configure additional properties... // Add it to the data collector set collectorSet.DataCollectors.Add(performanceCollector); // Commit the set under a new name collectorSet.Commit( @"Service\DevX with additonal collectors", null, CommitMode.plaCreateOrModify);

The IDataCollectorSet.DataCollectors property is an instance of the DataCollectorCollection class. It provides two methods for creating a data collector. The first, DataCollectorCollection.CreateDataCollector, accepts a DataCollectorType enumeration as a parameter. You can cast the returned IDataCollector instance to the appropriate interface as shown in the preceding code snippet.

The other method, DataCollectorCollection.CreateDataCollectorFromXml, accepts an XML string used to configure the data collector. You can extract the appropriate XML segment from an exported data collector set's XML. For example, the DevX.Pla.Template.xml file used in this article contains this segment:

<PerformanceCounterDataCollector> <DataCollectorType>0</DataCollectorType> <Name>Performance Counter</Name> <FileName>Performance Counter</FileName> <FileNameFormat>0</FileNameFormat> <FileNameFormatPattern> </FileNameFormatPattern> <LogAppend>0</LogAppend> <LogCircular>0</LogCircular> <LogOverwrite>0</LogOverwrite> <LatestOutputLocation> </LatestOutputLocation> <DataSourceName> </DataSourceName> <SampleInterval>1</SampleInterval> <SegmentMaxRecords>0</SegmentMaxRecords> <LogFileFormat>3</LogFileFormat> <Counter>\Process(*)\*</Counter> <Counter>\PhysicalDisk(*)\*</Counter> <Counter>\Processor(*)\*</Counter> <Counter>\ProcessorPerformance(*)\*</Counter> ... </PerformanceCounterDataCollector>

 
Figure 12. Scheduling Runs: You schedule data collector set runs using the Properties window. You don't have to provide a schedule, so some data collector sets may not be scheduled.
Save this segment as a separate XML file to create a performance counter data collector with DataCollectorCollection.CreateDataCollectorFromXml.

The same programmatic and XML file approaches for configuring a performance counter data collector apply to the other types of data collectors; however, the specifics of configuring each type of data collector are outside the scope of this article. See the Best Practices section at the end of this article for more information.

Scheduling Data Collector Set Runs
Open the properties dialog for a data collector set in the RPM to create and modify scheduled runs (see Figure 12).

Programmatically, use the IDataCollectorSet.Schedules property to schedule runs.



if (collectorSet.SchedulesEnabled) { // Create and configure a schedule ISchedule schedule = collectorSet.Schedules.CreateSchedule(); DateTime now = DateTime.Now.AddHours(1); schedule.StartDate = now; schedule.EndDate = now.AddDays(7); schedule.Days = WeekDays.plaEveryday; schedule.StartTime = now; // Add the schedule to the data collector set collectorSet.Schedules.Add(schedule); // Commit the set under a new name collectorSet.Commit( @"Service\DevX with schedule", null, CommitMode.plaCreateOrModify); }

After running the preceding code, if you export this data collector set's XML file you'll find an appropriate section for the schedule:

<Schedule> <StartDate>5/3/2007</StartDate> <EndDate>5/10/2007</EndDate> <StartTime>1:27:10 PM</StartTime> <Days>127</Days> </Schedule>

Best Practices for Creating PLA-Enabled Applications
The PLA API can be intimidating to learn and tedious to program if you don't have some extra help. Consider adopting these best practices when approaching PLA-enabled applications:

  • Become familiar with the Windows Vista Reliability and Performance Monitor. It's a valuable development tool for PLA programmers.
  • Determine which data collectors you need for your application, and invest some time learning how to configure them properly. Most of the data collectors represent a deep topic area—it doesn't make sense to try to learn them all at once.
  • The deepest topic is performance counters. You might find the article Extracting Performance Data from Your .NET Applications valuable.
  • Use the XML capabilities of the PLA API to keep data collector set configuration decoupled from your application code.


Seth Livingston is the CTO of Adventos, LLC, a training, mentoring, and delivery partner for Microsoft solutions and software development best practices. Seth splits his time among seminars, classes, mentoring, and guiding Adventos' technical direction. He lives in McKinney, Texas.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap