Configuration of Performance Monitor Logs with .NET

D

David Wagner

Hi,

I am looking at wanting to configure and manage some
Performance Monitor logs through a C# application.
Specifically, I want to be able to define and configure
named performance log configurations and be able to start
and stop the logging through my application. I have done
some digging, but have not been able to figure how I would
do this from C#.

I need the application to be able to work in both Windows
2000 and 2003. I realize that the Windows 2003 system
includes a command line utility (logman) that does
everything I need it to do, however, it is not available
on Windows 2000 and I can not count on being able to use
the remote configuration abilities of that utility.

The PerformanceCounter object in the Diagnostics
namespace, as well as the pdh.dll functions, would seem to
allow me to create my own performance logging mechanism,
but why re-invent the wheel when it seems obvious that
there must be a way to do it from code if the perfmon MMC
snapin and the Windows 2003 logman utility are able to
accomplish the task.

Has anyone already crossed this bridge and be willing to
share the solution?

Thanks,
David Wagner
 
G

Greg Ewing [MVP]

David, so you want to be able to publish PerfMon stats? Right? If that's
the case then your best bet is to go with the PerformanceCounter class in
the Diagnostics namespace. It's a matter of design as to how to make it
easy to turn on and off.

If you want some sample code let me know and I'll post it here when I get
home.
 
D

David Wagner

Greg,

To be clear, what I want to do is configure, start, and
stop logging of performance counters using the
system "Performance Logs and Alerts" service (smlogsvc)
via my application. The Perfmon MMC snap-in does these
operations in its application, however, I need to be able
to do them programmatically in my application. I do not
want to do the actual logging of the counters within in my
application. Just configure, start, and stop the logging
based on criteria required by the application.

For example, the Perfmon MMC application (Administrative
Tools -> Performance) allows for the creation of
persistent named "Counter Logs". These logs can then be
started and stopped using the tool with output sent to
specified log files. My application needs to be able to
configured a named Counter Log with a specified set of
counters, output location, interval, etc. and then manage
the starting and stopping of the Counter Log sampling.
Note that the application will not be running during the
whole time that the sampling is occurring, so it needs to
be able to start the logging and then exit and then come
back in at a later time and stop the logging later.

The easiest way to think of this is to assume that I need
to duplicate the functionality of the perfmon MMC
application Counter Log configuration and management
functionality in my application.

If the PerformanceCounter object allows me to accomplish
these tasks then I have misread what it can do, because it
looks to me as if it only provides the ability to read
counter values from existing instances or from log files.
This would not seem to be the same as wanting to tell the
service that I want the counter's logged or not logged.

If you have example code on this subject, I would
appreciate seeing it.

Thanks,
David Wagner
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top