健康服務報告Health Service reports

適用於 Windows Server 2016Applies to Windows Server 2016

報告為何?What are reports

健康服務降低需要取得動態效能與容量的資訊,從您的儲存空間直接存取叢集的工作。The Health Service reduces the work required to get live performance and capacity information from your Storage Spaces Direct cluster. 一個新 cmdlet 提供基本計量、 有效率地收集,是動態累積節點,以建邏輯偵測叢集成員資格 curated 的的清單。One new cmdlet provides a curated list of essential metrics, which are collected efficiently and aggregated dynamically across nodes, with built-in logic to detect cluster membership. 所有值只都是即時與的時間點。All values are real-time and point-in-time only.

使用中的 PowerShellUsage in PowerShell

使用下列 cmdlet 取得儲存空間直接存取整個叢集計量︰Use this cmdlet to get metrics for the entire Storage Spaces Direct cluster:

Get-StorageSubSystem Cluster* | Get-StorageHealthReport

選擇性計數參數指出多少設值的退貨,在一個第二個時間間隔。The optional Count parameter indicates how many sets of values to return, at one second intervals.

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

您也可以一個特定的音量或伺服器取得計量︰You can also get metrics for one specific volume or server:

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

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

使用.NET 和 C#Usage in .NET and C#

連接Connect

為了查詢健康服務,您將需要建立CimSession與叢集。In order to query the Health Service, you will need to establish a CimSession with the cluster. 若要這樣做,您將需要幾個步驟,將只提供完整.NET 中,這表示您無法輕易地執行此動作直接從 web 或行動裝置應用程式。To do so, you will need some things that are only available in full .NET, meaning you cannot readily do this directly from a web or mobile app. 這些程式碼範例將會使用 C\ #,此資料的存取層最簡單的選擇。These code samples will use C#, the most straightforward choice for this data access layer.

...
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;
}

提供的使用者名稱應該的目標電腦本機系統管理員。The provided Username should be a local Administrator of the target Computer.

我們建議您建構密碼SecureString直接中的使用者輸入的即時,讓他們的密碼永遠不會儲存在記憶體中明文。It is recommended that you construct the Password SecureString directly from user input in real-time, so their password is never stored in memory in cleartext. 這有助於減少各種不同的安全性問題。This helps mitigate a variety of security concerns. 但實際上,它建構上述常見的原型用途。But in practice, constructing it as above is common for prototyping purposes.

探索物件Discover objects

使用CimSession建立,您可以查詢 Windows 管理檢測 (WMI) 叢集上。With the CimSession established, you can query Windows Management Instrumentation (WMI) on the cluster.

您可以取得錯誤或計量之前,您必須將數個相關的物件的執行個體。Before you can get faults or metrics, you will need to get instances of several relevant objects. 第一次,MSFT_StorageSubSystem,表示叢集上儲存空間直接存取。First, the MSFT_StorageSubSystem which represents Storage Spaces Direct on the cluster. 使用的您可以取得每個MSFT_StorageNode中叢集,與每個MSFT_Volume,資料磁碟區。Using that, you can get every MSFT_StorageNode in the cluster, and every MSFT_Volume, the data volumes. 最後,您將必須MSFT_StorageHealth,健康太服務本身。Finally, you will need the MSFT_StorageHealth, the Health Service itself, too.

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 中使用像是 cmdlet 相同的物件取得-StorageSubSystem取得-StorageNode,並取得磁碟區These are the same objects you get in PowerShell using cmdlets like Get-StorageSubSystem, Get-StorageNode, and Get-Volume.

您具有相同可以存取屬性,記載在儲存管理 API 類別You can access all the same properties, documented at Storage Management API Classes.

...
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以開始串流處理我們專家-整理清單的基本計量、有效率地收集,是動態累積節點,以建邏輯偵測叢集成員資格的範例。Invoke GetReport to begin streaming samples of an expert-curated list of essential metrics, which are collected efficiently and aggregated dynamically across nodes, with built-in logic to detect cluster membership. 樣本將會抵達之後每秒。Samples will arrive every second thereafter. 所有值只都是即時與的時間點。All values are real-time and point-in-time only.

有三種範圍的可以串流處理計量︰ 叢集、任何] 節點或任何磁碟區。Metrics can be streamed for three scopes: the cluster, any node, or any volume.

下列被記載計量可在 Windows Server 2016 中的每個範圍的完整清單。The complete list of metrics available at each scope in Windows Server 2016 is documented below.

IObserver.OnNext()IObserver.OnNext()

範例程式碼使用觀察者設計模式實作觀察者的OnNext()計量的每個新範例到達時,將會叫用方法。This sample code uses the Observer Design Pattern to implement an Observer whose OnNext() method will be invoked when each new sample of metrics arrives. OnCompleted()方法將會被如何稱呼如果/串流結束時。Its OnCompleted() method will be called if/when streaming ends. 例如,您可能會使用該重新起始串流處理,讓它永遠會繼續。For example, you might use it to reinitiate streaming, so it continues indefinitely.

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
    }
}

開始串流處理Begin streaming

使用定義觀察者,您就可以開始串流處理。With the Observer defined, you can begin streaming.

指定目標CimInstance以您想計量範圍。Specify the target CimInstance to which you want the metrics scoped. 它可以是叢集、任何] 節點或任何磁碟區。It can be the cluster, any node, or any volume.

計數參數串流結束之前是範例數目。The count parameter is the number of samples before streaming ends.

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);
}

可想而知,這些計量可以視覺化、儲存在資料庫中,或使用您它們的方式。Needless to say, these metrics can be visualized, stored in a database, or used in whatever way you see fit.

屬性的報告Properties of reports

計量的每一個範例是一個」報告」其中包含許多」記錄」個人計量相對應。Every sample of metrics is one "report" which contains many "records" corresponding to individual metrics.

完整架構、檢查MSFT_StorageHealthReportMSFT_HealthRecord中類別storagewmi.mofFor the full schema, inspect the MSFT_StorageHealthReport and MSFT_HealthRecord classes in storagewmi.mof.

每個計量具有每本表只需三個屬性。Each metric has just three properties, per this table.

屬性Property 範例Example
名稱Name IOLatencyAverageIOLatencyAverage
值。Value 0.000210.00021
單位Units 33

單位 = {0 1、2、3、4}、0 =」位元組」,1 =」BytesPerSecond」,2 =」CountPerSecond」,3 =」秒」或 4 =」百分比」。Units = { 0, 1, 2, 3, 4 }, where 0 = "Bytes", 1 = "BytesPerSecond", 2 = "CountPerSecond", 3 = "Seconds", or 4 = "Percentage".

涵蓋範圍Coverage

以下是計量適用於 Windows Server 2016 中的每個範圍。Below are the metrics available for each scope in Windows Server 2016.

MSFT_StorageSubSystemMSFT_StorageSubSystem

名稱Name 單位Units
CPUUsageCPUUsage 44
CapacityPhysicalPooledAvailableCapacityPhysicalPooledAvailable 00
CapacityPhysicalPooledTotalCapacityPhysicalPooledTotal 00
CapacityPhysicalTotalCapacityPhysicalTotal 00
CapacityPhysicalUnpooledCapacityPhysicalUnpooled 00
CapacityVolumesAvailableCapacityVolumesAvailable 00
CapacityVolumesTotalCapacityVolumesTotal 00
IOLatencyAverageIOLatencyAverage 33
IOLatencyReadIOLatencyRead 33
IOLatencyWriteIOLatencyWrite 33
IOPSReadIOPSRead 22
IOPSTotalIOPSTotal 22
IOPSWriteIOPSWrite 22
IOThroughputReadIOThroughputRead 11
IOThroughputTotalIOThroughputTotal 11
IOThroughputWriteIOThroughputWrite 11
MemoryAvailableMemoryAvailable 00
MemoryTotalMemoryTotal 00

MSFT_StorageNodeMSFT_StorageNode

名稱Name 單位Units
CPUUsageCPUUsage 44
IOLatencyAverageIOLatencyAverage 33
IOLatencyReadIOLatencyRead 33
IOLatencyWriteIOLatencyWrite 33
IOPSReadIOPSRead 22
IOPSTotalIOPSTotal 22
IOPSWriteIOPSWrite 22
IOThroughputReadIOThroughputRead 11
IOThroughputTotalIOThroughputTotal 11
IOThroughputWriteIOThroughputWrite 11
MemoryAvailableMemoryAvailable 00
MemoryTotalMemoryTotal 00

MSFT_VolumeMSFT_Volume

名稱Name 單位Units
CapacityAvailableCapacityAvailable 00
CapacityTotalCapacityTotal 00
IOLatencyAverageIOLatencyAverage 33
IOLatencyReadIOLatencyRead 33
IOLatencyWriteIOLatencyWrite 33
IOPSReadIOPSRead 22
IOPSTotalIOPSTotal 22
IOPSWriteIOPSWrite 22
IOThroughputReadIOThroughputRead 11
IOThroughputTotalIOThroughputTotal 11
IOThroughputWriteIOThroughputWrite 11

也了See also