运行状况服务报表Health Service reports

适用于:Windows Server 2019、Windows Server 2016Applies to: Windows Server 2019, 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 提供了一个特选的基本指标列表,它们使用内置逻辑来检测群集成员身份,以动态方式跨节点进行收集和聚合。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.

在 PowerShell 中的用法Usage 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

若要查询运行状况服务,需要建立与群集的CimSessionIn 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 @ no__t,这是此数据访问层最简单的选择。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 MANAGEMENT INSTRUMENTATION (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 @ no__t-1StorageSubSystem表示群集上存储空间直通。First, the MSFT_StorageSubSystem which represents Storage Spaces Direct on the cluster. 使用它,你可以获取群集中的每个msft @ no__t-1StorageNode ,以及每个msft @ no__t-3Volume,这些数据卷。Using that, you can get every MSFT_StorageNode in the cluster, and every MSFT_Volume, the data volumes. 最后,还需要MSFT @ no__t-1StorageHealth,运行状况服务本身。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 中使用StorageSubSystemStorageNodeVolume等 cmdlet 获取的相同对象。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.

指定要为其指定指标范围的目标CimInstanceSpecify the target CimInstance to which you want the metrics scoped. 它可以是群集、任何节点或任何卷。It can be the cluster, any node, or any volume.

Count 参数是流式处理结束之前的样本数。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.

对于完整的架构,请在storagewmi中检查msft @ no__t-1StorageHealthReportmsft @ no__t-3HealthRecord类。For the full schema, inspect the MSFT_StorageHealthReport and MSFT_HealthRecord classes in storagewmi.mof.

每个指标仅有三个属性,每个表。Each metric has just three properties, per this table.

PropertyProperty 示例Example
名称Name IOLatencyAverageIOLatencyAverage
ReplTest1Value 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