次の方法で共有


スクリプト タスクによるパフォーマンス カウンタの監視

システム管理者は、大容量のデータ上で複雑な変換を実行する Integration Services パッケージのパフォーマンスを監視する必要が生じる場合があります。Microsoft.NET Framework の System.Diagnostics 名前空間には、既存のパフォーマンス カウンタを使用したり、ユーザー独自のパフォーマンス カウンタを作成するためのクラスが用意されています。

パフォーマンス カウンタはアプリケーションのパフォーマンス情報を格納するので、これを使用して、時間経過に伴うソフトウェアのパフォーマンスを分析できます。パフォーマンス カウンタは [パフォーマンス モニタ] ツールを使用して、ローカルまたはリモートで監視できます。パフォーマンス カウンタの値を変数に格納して、後でパッケージ内で制御フローを分岐するために使用できます。

パフォーマンス カウンタを使用する代わりに、Dts オブジェクトの Events プロパティを介して、FireProgress イベントを発生させることができます。FireProgress イベントは、進捗状況および完了した割合に関する情報を、Integration Services ランタイムに返します。

注意注意

複数のパッケージでより簡単に再利用できるタスクを作成する場合は、このスクリプト タスク サンプルのコードを基にした、カスタム タスクの作成を検討してください。詳細については、「カスタム タスクの開発」を参照してください。

説明

次の例では、カスタム パフォーマンス カウンタを作成し、カウンタの値を増やします。最初に、パフォーマンス カウンタが既に存在しているかどうかを判別します。パフォーマンス カウンタが作成されていない場合、スクリプトは PerformanceCounterCategory オブジェクトの Create メソッドを呼び出してパフォーマンス カウンタを作成します。パフォーマンス カウンタが作成されたら、スクリプトはそのカウンタの値を増やします。最後に、この例ではベスト プラクティスに従って、パフォーマンス カウンタが不要になると、そのカウンタに対して Close メソッドを呼び出します。

注意注意

パフォーマンス カウンタ カテゴリとパフォーマンス カウンタを新しく作成するには、管理権限が必要です。また、新しいカテゴリとカウンタは、作成後もコンピュータに保存されます。

このスクリプト タスクの例を構成するには

  • コードで Imports ステートメントを使用して、System.Diagnostics 名前空間をインポートします。

コード例

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 = ScriptResults.Success
    Catch ex As Exception
        Dts.Events.FireError(0, _
            "Task Performance Counter Example", _
            ex.Message & ControlChars.CrLf & ex.StackTrace, _
            String.Empty, 0)
        Dts.TaskResult = ScriptResults.Failure
    End Try

End Sub
public class ScriptMain
{



public void Main()
        {

            PerformanceCounter myCounter;

            try
            {
                //Create the performance counter if it does not already exist.
                if (!PerformanceCounterCategory.Exists("TaskExample"))
                {
                    PerformanceCounterCategory.Create("TaskExample", "Task Performance Counter Example", "Iterations", "Number of times this task has been called.");
                }

                //Initialize the performance counter.
                myCounter = new PerformanceCounter("TaskExample", "Iterations", String.Empty, false);

                //Increment the performance counter.
                myCounter.Increment();

                myCounter.Close();
                Dts.TaskResult = (int)ScriptResults.Success;
            }
            catch (Exception ex)
            {
                Dts.Events.FireError(0, "Task Performance Counter Example", ex.Message + "\r" + ex.StackTrace, String.Empty, 0);
                Dts.TaskResult = (int)ScriptResults.Failure;
            }

            Dts.TaskResult = (int)ScriptResults.Success;
        }
Integration Services のアイコン (小) 最新の Integration Services の入手

マイクロソフトが提供する最新のダウンロード、アーティクル、サンプル、ビデオ、およびコミュニティで選択されたソリューションについては、MSDN または TechNet の Integration Services のページを参照してください。

これらの更新が自動で通知されるようにするには、ページの RSS フィードを購読します。