ヘルス サービスのレポート

適用先:Windows Server 2016

レポートとは

ヘルス サービスにより、記憶域スペース ダイレクト クラスターから現在のパフォーマンスおよび容量の情報を取得するために必要な作業が削減されます。 1 つの新しいコマンドレットにより、厳選された重要なメトリックの一覧が得られます。これらのメトリックは、クラスター メンバーシップを検出する組み込みロジックを使用してノード全体で効率的に収集され、動的に集計されます。 値はすべて、リアルタイムかつ特定の時点のみのものです。

PowerShell での使用法

このコマンドレットを使用して、記憶域スペース ダイレクト クラスター全体のメトリックを取得します。

Get-StorageSubSystem Cluster* | Get-StorageHealthReport

省略可能な Count パラメーターは、1 秒間隔で返される値のセット数を示します。

Get-StorageSubSystem Cluster* | Get-StorageHealthReport -Count <Count>

また、特定のボリュームやサーバーのメトリックを取得することもできます。

Get-Volume -FileSystemLabel <Label> | Get-StorageHealthReport -Count <Count>

Get-StorageNode -Name <Name> | Get-StorageHealthReport -Count <Count>

.NET および C# での使用方法

接続する

ヘルス サービスに対してクエリを実行するには、クラスターとの CimSession を確立する必要があります。 これを行うには、完全な .NET でのみ利用できる一部の機能が必要になります。つまり、Web アプリやモバイル アプリからこれを直接簡単に行うことはできません。 これらのコード サンプルでは、このデータ アクセス層で最も単純な選択肢である C# を使用します。

using System.Security;
using Microsoft.Management.Infrastructure;

public CimSession Connect(string Domain = "...", string Computer = "...", string Username = "...", string Password = "...")
{
    SecureString PasswordSecureString = new SecureString();
    foreach (char c in Password)
    {
        PasswordSecureString.AppendChar(c);
    }

    CimCredential Credentials = new CimCredential(
        PasswordAuthenticationMechanism.Default, Domain, Username, PasswordSecureString);
    WSManSessionOptions SessionOptions = new WSManSessionOptions();
    SessionOptions.AddDestinationCredentials(Credentials);
    Session = CimSession.Create(Computer, SessionOptions);
    return Session;
}

指定するユーザー名は、ターゲット コンピューターのローカル管理者である必要があります。

パスワード SecureString は、ユーザー入力からリアルタイムで直接構築するようにして、パスワードがクリア テキストでメモリに格納されないようにすることをお勧めします。 これは、さまざまなセキュリティの問題を軽減するために役立ちます。 ただし、実際には、ひな形作成の目的で上記のように構築するのが一般的です。

オブジェクトを検出します

CimSession が確立されると、クラスターの Windows Management Instrumentation (WMI) に対してクエリを実行できます。

エラーまたはメトリックを取得するには、その前に、いくつかの関連オブジェクトのインスタンスを取得する必要があります。 まず、クラスター上の記憶域スペース ダイレクトを表すMSFT_StorageSubSystem。 これを使用すると、クラスター内のすべての MSFT_StorageNode と、すべての MSFT_Volume (データ ボリューム) を取得できます。 最後に、MSFT_StorageHealth、つまりヘルス サービス自体も必要になります。

CimInstance Cluster;
List<CimInstance> Nodes;
List<CimInstance> Volumes;
CimInstance HealthService;

public void DiscoverObjects(CimSession Session)
{
    // Get MSFT_StorageSubSystem for Storage Spaces Direct
    Cluster = Session.QueryInstances(@"root\microsoft\windows\storage", "WQL", "SELECT * FROM MSFT_StorageSubSystem")
        .First(Instance => (Instance.CimInstanceProperties["FriendlyName"].Value.ToString()).Contains("Cluster"));

    // Get MSFT_StorageNode for each cluster node
    Nodes = Session.EnumerateAssociatedInstances(Cluster.CimSystemProperties.Namespace,
        Cluster, "MSFT_StorageSubSystemToStorageNode", null, "StorageSubSystem", "StorageNode").ToList();

    // Get MSFT_Volumes for each data volume
    Volumes = Session.EnumerateAssociatedInstances(Cluster.CimSystemProperties.Namespace,
        Cluster, "MSFT_StorageSubSystemToVolume", null, "StorageSubSystem", "Volume").ToList();

    // Get MSFT_StorageHealth itself
    HealthService = Session.EnumerateAssociatedInstances(Cluster.CimSystemProperties.Namespace,
        Cluster, "MSFT_StorageSubSystemToStorageHealth", null, "StorageSubSystem", "StorageHealth").First();
}

これらは、PowerShell で Get-StorageSubSystemGet-StorageNode、および Get-Volume のようなコマンドレットを使用して取得するものと同じオブジェクトです。

Storage Management API クラスに記載されている、同じプロパティのすべてにアクセスできます。

using System.Diagnostics;

foreach (CimInstance Node in Nodes)
{
    // For illustration, write each node's Name to the console. You could also write State (up/down), or anything else!
    Debug.WriteLine("Discovered Node " + Node.CimInstanceProperties["Name"].Value.ToString());
}

GetReport を呼び出して、専門家が厳選した重要なメトリックの一覧のサンプルのストリーミングを開始します。これらのメトリックは、クラスター メンバーシップを検出する組み込みロジックを使用してノード全体で効率的に収集され、動的に集計されます。 サンプルは、その後、1 秒ごとに到着します。 値はすべて、リアルタイムかつ特定の時点のみのものです。

メトリックは、クラスター、任意のノード、任意のボリュームの 3 つのスコープに対してストリーミングできます。

Windows Server 2016 の各スコープで利用できるメトリックの完全な一覧については、以下で説明します。

IObserver.OnNext()

このサンプル コードでは、オブザーバー デザイン パターンを使用して、メトリックの新しいサンプルが到着するごとに呼び出される OnNext() メソッドを持つオブザーバーを実装します。 OnCompleted() メソッドは、ストリーミングが終了したときに呼び出されます。 たとえば、ストリーミングの再開に使用すれば、無期限に続行することができます。

class MetricsObserver<T> : IObserver<T>
{
    public void OnNext(T Result)
    {
        // Cast
        CimMethodStreamedResult StreamedResult = Result as CimMethodStreamedResult;

        if (StreamedResult != null)
        {
            // For illustration, you could store the metrics in this dictionary
            Dictionary<string, string> Metrics = new Dictionary<string, string>();

            // Unpack
            CimInstance Report = (CimInstance)StreamedResult.ItemValue;
            IEnumerable<CimInstance> Records = (IEnumerable<CimInstance>)Report.CimInstanceProperties["Records"].Value;
            foreach (CimInstance Record in Records)
            {
                /// Each Record has "Name", "Value", and "Units"
                Metrics.Add(
                    Record.CimInstanceProperties["Name"].Value.ToString(),
                    Record.CimInstanceProperties["Value"].Value.ToString()
                    );
            }

            // TODO: Whatever you want!
        }
    }
    public void OnError(Exception e)
    {
        // Handle Exceptions
    }
    public void OnCompleted()
    {
        // Reinvoke BeginStreamingMetrics(), defined in the next section
    }
}

ストリーミングを開始する

オブザーバーを定義すると、ストリーミングを開始できます。

メトリックのスコープを設定するターゲットの CimInstance を指定します。 クラスター、任意のノード、または任意のボリュームを指定できます。

count パラメーターは、ストリーミングが終了する前のサンプル数です。

CimInstance Target = Cluster; // From among the objects discovered in DiscoverObjects()

public void BeginStreamingMetrics(CimSession Session, CimInstance HealthService, CimInstance Target)
{
    // Set Parameters
    CimMethodParametersCollection MetricsParams = new CimMethodParametersCollection();
    MetricsParams.Add(CimMethodParameter.Create("TargetObject", Target, CimType.Instance, CimFlags.In));
    MetricsParams.Add(CimMethodParameter.Create("Count", 999, CimType.UInt32, CimFlags.In));
    // Enable WMI Streaming
    CimOperationOptions Options = new CimOperationOptions();
    Options.EnableMethodResultStreaming = true;
    // Invoke API
    CimAsyncMultipleResults<CimMethodResultBase> InvokeHandler;
    InvokeHandler = Session.InvokeMethodAsync(
        HealthService.CimSystemProperties.Namespace, HealthService, "GetReport", MetricsParams, Options
        );
    // Subscribe the Observer
    MetricsObserver<CimMethodResultBase> Observer = new MetricsObserver<CimMethodResultBase>(this);
    IDisposable Disposeable = InvokeHandler.Subscribe(Observer);
}

言うまでもなく、これらのメトリックは視覚化したり、データベースに格納したり、最適な方法で使用したりすることができます。

レポートのプロパティ

メトリックのすべてのサンプルでは、個々のメトリックに対応した多数の "レコード" が 1 つの "レポート" に含まれます。

完全なスキーマについては、storagewmi.mof 内で MSFT_StorageHealthReport クラスと MSFT_HealthRecord クラスを調べてください。

次の表に示すように、各メトリックには 3 つのプロパティしかありません。

プロパティ
名前 IOLatencyAverage
0.00021
ユニット 3

ユニット = { 0, 1, 2, 3, 4 }、ここで 0 = "Bytes"、1 = "BytesPerSecond"、2 = "CountPerSecond"、3 = "Seconds"、4 = "Percentage"。

カバレッジ

Windows Server 2016 の各スコープで使用できるメトリックを以下に示します。

MSFT_StorageSubSystem

名前 ユニット
CPUUsage 4
CapacityPhysicalPooledAvailable 0
CapacityPhysicalPooledTotal 0
CapacityPhysicalTotal 0
CapacityPhysicalUnpooled 0
CapacityVolumesAvailable 0
CapacityVolumesTotal 0
IOLatencyAverage 3
IOLatencyRead 3
IOLatencyWrite 3
IOPSRead 2
IOPSTotal 2
IOPSWrite 2
IOThroughputRead 1
IOThroughputTotal 1
IOThroughputWrite 1
MemoryAvailable 0
MemoryTotal 0

MSFT_StorageNode

名前 ユニット
CPUUsage 4
IOLatencyAverage 3
IOLatencyRead 3
IOLatencyWrite 3
IOPSRead 2
IOPSTotal 2
IOPSWrite 2
IOThroughputRead 1
IOThroughputTotal 1
IOThroughputWrite 1
MemoryAvailable 0
MemoryTotal 0

MSFT_Volume

名前 ユニット
CapacityAvailable 0
CapacityTotal 0
IOLatencyAverage 3
IOLatencyRead 3
IOLatencyWrite 3
IOPSRead 2
IOPSTotal 2
IOPSWrite 2
IOThroughputRead 1
IOThroughputTotal 1
IOThroughputWrite 1

その他の参照情報