클러스터 성능 기록 가져오기

적용 대상: Azure Stack HCI, 버전 23H2 및 22H2; Windows Server 2022, Windows Server 2019

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

PowerShell의 사용량

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

Get-ClusterPerformanceHistory

Get-ClusterPerf 별칭을 사용하여 일부 키 입력을 저장합니다.

하나의 특정 볼륨 또는 서버에 대한 메트릭을 가져올 수도 있습니다.

Get-Volume -FileSystemLabel <Label> | Get-ClusterPerformanceHistory

Get-StorageNode -Name <Name> | Get-ClusterPerformanceHistory

.NET 및 C의 사용량#

이 섹션에서는 상태 서비스에 연결하고, 개체 검색을 사용하고, 관찰자를 구현하여 메트릭 스트리밍을 시작하는 방법을 보여 줍니다.

연결

상태 서비스를 쿼리하기 위해 클러스터를 사용하여 CimSession 을 설정합니다. 이렇게 하려면 전체 Microsoft .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)를 쿼리할 수 있습니다.

오류 또는 메트릭을 가져오기 전에 여러 관련 개체의 인스턴스를 가져와야 합니다. 먼저 클러스터의 저장소 공간 다이렉트 나타내는 MSFT_StorageSubSystem 가져옵니다. 이를 사용하여 클러스터의 모든 MSFT_StorageNode 데이터 볼륨의 모든 MSFT_Volume 가져올 수 있습니다. 마지막으로, MSCluster_ClusterHealthService 상태 서비스 자체를 가져와야 합니다.

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 MSCluster_ClusterHealthService itself
    HealthService = session.QueryInstances(@"root\MSCluster", "WQL", "SELECT * FROM MSCluster_ClusterHealthService").First();
}

Get-StorageSubSystem, Get-StorageNodeGet-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());
}

GetMetric을 호출하여 클러스터 멤버 자격을 검색하는 기본 제공 논리를 사용하여 노드 간에 효율적으로 수집되고 동적으로 집계되는 MetricName 매개 변수에서 제공된 메트릭 이름을 기반으로 전문가가 큐레이팅한 필수 메트릭 목록의 스트리밍 샘플을 시작합니다. 샘플은 StreamName 매개 변수에서 제공된 기간을 기준으로 도착합니다.

사용 가능한 메트릭의 전체 목록은 저장소 공간 다이렉트 대한 성능 기록을 참조하세요.

IObserver.OnNext()

이 샘플 코드는 관찰자 디자인 패턴을 사용하여 각 새 메트릭 샘플이 도착할 때 OnNext() 메서드가 호출되는 관찰자를 구현합니다. 스트리밍이 종료 되면 OnCompleted() 메서드가 호출됩니다. 예를 들어 스트리밍을 다시 초기화하여 무기한으로 계속되도록 할 수 있습니다.

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

        if (StreamedResult != null)
        {
            CimInstance Metric = (CimInstance)StreamedResult.ItemValue;
            Console.WriteLine("MetricName: " + Metric.CimInstanceProperties["MetricId"].Value);
            IEnumerable<CimInstance> Records = (IEnumerable<CimInstance>)Metric.CimInstanceProperties["Records"].Value;

            foreach (CimInstance Record in Records)
            {
                // Each Record has "TimeStamp" and "Value. For Illustration, just print the metric"
                Console.WriteLine(record.CimInstanceProperties["TimeStamp"] + ": " + record.CimInstanceProperties["Value"]);

            }

            // 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();
    string[] metricNames = new string[] { "ClusterNode.Cpu.Usage,ClusterNode=RRN44-13-01", "ClusterNode.Cpu.Usage.Host,ClusterNode=RRN44-13-01" };
    MetricsParams.Add(CimMethodParameter.Create("MetricName", metricNames, CimType.StringArray, CimFlags.In));
    MetricsParams.Add(CimMethodParameter.Create("StreamName", "LastHour", CimType.String, CimFlags.In));

    // Enable WMI Streaming
    CimOperationOptions Options = new CimOperationOptions();
    Options.EnableMethodResultStreaming = true;
    // Invoke API
    CimAsyncMultipleResults<CimMethodResultBase> InvokeHandler;
    InvokeHandler = Session.InvokeMethodAsync(
        HealthService.CimSystemProperties.Namespace, HealthService, "GetMetric", MetricsParams, Options
        );
    // Subscribe the Observer
    MetricsObserver<CimMethodResultBase> Observer = new MetricsObserver<CimMethodResultBase>(this);
    IDisposable Disposeable = InvokeHandler.Subscribe(Observer);
}

이러한 메트릭은 시각화하거나, 데이터베이스에 저장하거나, 적합한 방식으로 사용할 수 있습니다.

추가 참조