상태 관리 서비스 보고서

적용 대상: Windows Server 2016

보고서란?

상태 관리 서비스 저장소 공간 Direct 클러스터에서 라이브 성능 및 용량 정보를 가져오는 데 필요한 작업을 줄입니다. 하나의 새 cmdlet은 클러스터 멤버 자격을 검색하는 기본 제공 논리를 사용하여 노드 간에 효율적으로 수집되고 동적으로 집계되는 큐레이팅된 필수 메트릭 목록을 제공합니다. 모든 값은 실시간 및 지정 시간 값으로만 제공됩니다.

PowerShell의 사용량

이 cmdlet을 사용하여 전체 저장소 공간 Direct 클러스터에 대한 메트릭을 가져옵니다.

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에서만 사용할 수 있는 몇 가지 항목이 필요합니다. 즉, 웹 또는 모바일 앱에서 직접 이 작업을 수행할 수 없습니다. 이러한 코드 샘플은 이 데이터 액세스 계층에서 가장 간단한 선택인 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이 설정되면 클러스터에서 WMI(Windows Management Instrumentation)를 쿼리할 수 있습니다.

오류 또는 메트릭을 가져오기 전에 여러 관련 개체의 인스턴스를 가져와야 합니다. 먼저 클러스터의 저장소 공간 Direct를 나타내는 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();
}

Get-StorageSubSystem, Get-StorageNode 및 Get-Volume같은 cmdlet을 사용하여 PowerShell에서 가져오는 것과 동일한 개체입니다.

스토리지 관리 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초마다 도착합니다. 모든 값은 실시간 및 지정 시간 값으로만 제공됩니다.

메트릭은 클러스터, 노드 또는 볼륨의 세 가지 범위에 대해 스트리밍할 수 있습니다.

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

말할 필요도 없이 이러한 메트릭을 시각화하거나, 데이터베이스에 저장하거나, 어떤 방식으로든 적합하게 사용할 수 있습니다.

보고서의 속성

메트릭의 모든 샘플은 개별 메트릭에 해당하는 많은 "레코드"를 포함하는 하나의 "보고서"입니다.

전체 스키마의 경우 storagewmi.mof에서 MSFT_StorageHealthReportMSFT_HealthRecord 클래스를 검사합니다.

각 메트릭에는 이 테이블당 세 개의 속성만 있습니다.

속성 예제
이름 IOLatencyAverage
0.00021
단위 3

Units = { 0, 1, 2, 3, 4 }, 여기서 0 = "바이트", 1 = "BytesPerSecond", 2 = "CountPerSecond", 3 = "Seconds" 또는 4 = "Percentage"입니다.

범위

다음은 Windows Server 2016의 각 범위에 사용할 수 있는 메트릭입니다.

MSFT_StorageSubSystem

이름 Units
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

이름 Units
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

이름 Units
CapacityAvailable 0
CapacityTotal 0
IOLatencyAverage 3
IOLatencyRead 3
IOLatencyWrite 3
IOPSRead 2
IOPSTotal 2
IOPSWrite 2
IOThroughputRead 1
IOThroughputTotal 1
IOThroughputWrite 1

추가 참조