Monitoring Performance Counters with the Script Task
Administrators may need to monitor the performance of Integration Services packages that perform complex transformations on large amounts of data. The System.Diagnostics namespace of the Microsoft .NET Framework provides classes for using existing performance counters and for creating your own performance counters.
Performance counters store application performance information that you can use to analyze the performance of software over time. Performance counters can be monitored locally or remotely by using the Performance Monitor tool. You can store the values of performance counters in variables for later control flow branching in the package.
As an alternative to using performance counters, you can raise the FireProgress event through the Events property of the Dts object. The FireProgress event returns both incremental progress and percentage complete information to the Integration Services runtime.
Note
If you want to create a task that you can more easily reuse across multiple packages, consider using the code in this Script task sample as the starting point for a custom task. For more information, see Developing a Custom Task.
Description
The following example creates a custom performance counter and increments the counter. First, the example determines whether the performance counter already exists. If the performance counter has not been created, the script calls the Create method of the PerformanceCounterCategory object to create it. After the performance counter has been created, the script increments the counter. Finally, the example follows the best practice of calling the Close method on the performance counter when it is no longer needed.
Note
Creating a new performance counter category and performance counter requires administrative rights. Also, the new category and counter persist on the computer after creation.
To configure this Script Task example
- Use an Imports statement in your code to import the System.Diagnostics namespace.
Example Code
Public Sub Main()
Dim myCounter As PerformanceCounter
Try
'Create the performance counter if it does not already exist.
If Not _
PerformanceCounterCategory.Exists("TaskExample") Then
PerformanceCounterCategory.Create("TaskExample", _
"Task Performance Counter Example", "Iterations", _
"Number of times this task has been called.")
End If
'Initialize the performance counter.
myCounter = New PerformanceCounter("TaskExample", _
"Iterations", String.Empty, False)
'Increment the performance counter.
myCounter.Increment()
myCounter.Close()
Dts.TaskResult = Dts.Results.Success
Catch ex As Exception
Dts.Events.FireError(0, _
"Task Performance Counter Example", _
ex.Message & ControlChars.CrLf & ex.StackTrace, _
String.Empty, 0)
Dts.TaskResult = Dts.Results.Failure
End Try
End Sub
Change History
Release | History |
---|---|
14 April 2006 |
|