Partilhar via


Using Performance Counters

This sample demonstrates how to access Windows Communication Foundation (WCF) performance counters and how to create user-defined performance counters. This sample is based on the Getting Started Sample.

Note

The setup procedure and build instructions for this sample are located at the end of this topic.

In this sample, the client calls the four methods of the ICalculator service. The client continues to do this until it is interrupted by the user. The service remains unchanged.

Performance counters are enabled in the diagnostics section of the Web.config file for the service, as shown in the following sample configuration.

<configuration>
  <system.serviceModel>
    <diagnostics performanceCounters="All" /> 
  </system.serviceModel>
</configuration>

This task can also be done using the Configuration Editor Tool (SvcConfigEditor.exe).

When performance counters are enabled, the entire suite of WCF performance counters is enabled for the service. The .NET Framework automatically maintains performance data at three levels: ServiceModelService, ServiceModelEndpoint and ServiceModelOperation. Each of these levels has performance counters such as "Calls", "Calls per Second", and "Security Calls Not Authorized".

To set up, build, and run the sample

  1. Ensure that you have performed the One-Time Setup Procedure for the Windows Communication Foundation Samples.

  2. To build the C# or Visual Basic .NET edition of the solution, follow the instructions in Building the Windows Communication Foundation Samples.

  3. To run the sample in a single- or cross-computer configuration, follow the instructions in Running the Windows Communication Foundation Samples.

To view performance data

  1. Start the Performance Monitor Tool by clicking Start, Run…, enter perfmon and click OK, or from Control Panel, select Administrative Tools and double-click Performance.

    Note

    You cannot add counters until the sample code is running.

  2. Remove the performance counters that are listed by selecting them and pressing the Delete key.

  3. Add WCF counters by right-clicking the graph pane and selecting Add Counters. In the Add Counters dialog box, select ServiceModelOperation 3.0.0.0, ServiceModelEndpoint 3.0.0.0, or ServiceModelService 3.0.0.0 in the Performance object drop down list box. Select the counters you want to view from the list.

    Note

    There are no WCF performance counters for a service if there are no WCF services running on the computer.

To use the Configuration Editor to enable counters

  1. Open an instance of the SvcConfigEditor.exe.

  2. On the File menu, click Open and then click Config file….

  3. Navigate to the sample application's service folder and open the Web.config file.

  4. Click Diagnostics on the Configuration tree.

  5. Toggle Performance Counter in the Diagnostics window to show 'All'.

  6. Save the configuration file and exit the editor.

ms750527.Important(en-us,VS.100).gif Note:
The samples may already be installed on your computer. Check for the following (default) directory before continuing.

<InstallDrive>:\WF_WCF_Samples

If this directory does not exist, go to Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) Samples for .NET Framework 4 to download all Windows Communication Foundation (WCF) and WF samples. This sample is located in the following directory.

<InstallDrive>:\WF_WCF_Samples\WCF\Basic\Management\PerfCounters

See Also

Other Resources

AppFabric Monitoring Samples