통계 성능 데이터 가져오기

WMI에서는 Win32_PerfFormattedData에서 파생된 형식의 성능 클래스의 데이터를 기반으로 통계 성능 데이터를 정의할 수 있습니다. 사용 가능한 통계는 통계 카운터 형식에 정의된 평균, 최소, 최대, 범위 및 분산입니다.

다음 목록에는 특수 통계 카운터 유형이 있습니다.

다음 예제는 다음 방법을 설명합니다.

  • 계산된 데이터의 클래스를 정의하는 MOF 파일 만들기.
  • 클래스의 인스턴스를 만들고, 다시 계산된 통계 값으로 인스턴스의 데이터를 주기적으로 새로 고치는 스크립트 작성하기.

MOF 파일

다음 MOF 코드 예제에서는 Win32_PerfFormattedData_AvailableMBytes라는 새로 계산된 데이터 클래스를 만듭니다. 이 클래스에는 원시 클래스 Win32_PerfRawData_PerfOS_MemoryAvailableMBytes 속성의 데이터가 있습니다. Win32_PerfFormattedData_AvailableBytes 클래스는 Average, Min, Max, RangeVariance 속성을 정의합니다.

MOF 파일은 형식이 지정된 성능 카운터 클래스의 속성 한정자를 사용하여 속성 데이터 원본 및 계산 수식을 정의합니다.

  • Average 속성은 Win32_PerfRawData_PerfOS_Memory.AvailableMBytes 속성에서 원시 데이터를 가져옵니다.
  • Average 속성의 Counter 한정자는 원시 데이터 원본을 지정합니다.
  • CookingType 한정자는 데이터를 계산하기 위한 수식 COOKER_MIN을 지정합니다.
  • SampleWindow 한정자는 계산을 수행하기 전에 가져올 샘플 수를 지정합니다.
// Store the new Win32_PerfFormattedData_MemoryStatistics
//     class in the Root\Cimv2 namespace
#pragma autorecover
#pragma namespace("\\\\.\\Root\\CimV2")

qualifier vendor:ToInstance;
qualifier guid:ToInstance;
qualifier displayname:ToInstance;
qualifier perfindex:ToInstance;
qualifier helpindex:ToInstance;
qualifier perfdetail:ToInstance;
qualifier countertype:ToInstance;
qualifier perfdefault:ToInstance;
qualifier defaultscale:ToInstance;

qualifier dynamic:ToInstance;
qualifier hiperf:ToInstance;
qualifier AutoCook:ToInstance;
qualifier AutoCook_RawClass:ToInstance;
qualifier CookingType:ToInstance;
qualifier Counter:ToInstance;


// Define the Win32_PerFormattedData_MemoryStatistics
//     class, derived from Win32_PerfFormattedData
[
  dynamic,
  // Name of formatted data provider: "WMIPerfInst" for Vista 
  //   and later
  provider("HiPerfCooker_v1"), 
  // Text that will identify new counter in Perfmon
  displayname("My Calculated Counter"),                            
  // A high performance class     
  Hiperf,
  // Contains calculated data 
  Cooked, 
  // Value must be 1 
  AutoCook(1), 
  // Raw performance class to get data for calculations
  AutoCook_RawClass("Win32_PerfRawData_PerfOS_Memory"),
  // Value must be 1        
  AutoCook_RawDefault(1),
  // Name of raw class property to use for timestamp in formulas 
  PerfSysTimeStamp("Timestamp_PerfTime"), 
  // Name of raw class property to use for frequency in formulas
  PerfSysTimeFreq("Frequency_PerfTime"), 
  // Name of raw class property to use for timestamp in formulas
  Perf100NSTimeStamp("Timestamp_Sys100NS"),
  // Name of raw class property to use for frequency in formulas
  Perf100NSTimeFreq("Frequency_Sys100NS"),
  // Name of raw class property to use for timestamp in formulas
  PerfObjTimeStamp("Timestamp_Object"),
  // Name of raw class property to use for frequency in formulas 
  PerfObjTimeFreq("Frequency_Object"),
  // Only one instance of class allowed in namespace
  singleton                                                   
]

class Win32_PerfFormattedData_MemoryStatistics
          : Win32_PerfFormattedData
{

// Define the properties for the class. 
// All the properties perform different
//     statistical operations on the same
//     property, AvailableMBytes, in the raw class

// Define the Average property,
//     which uses the "COOKER_AVERAGE" counter type and 
//     gets its data from the AvailableMBytes 
//     property in the raw class

    [
     CookingType("COOKER_AVERAGE"),
     Counter("AvailableMBytes"),
     SampleWindow(10)
    ]
    uint64 Average = 0;

// Define the Min property, which uses
//     the "COOKER_MIN" counter type and 
//     gets its data from the AvailableMBytes
//     property in the raw class

    [
     CookingType("COOKER_MIN"),
     Counter("AvailableMBytes"),
     SampleWindow(10)
    ]
    uint64 Min = 0;

// Define the Max property, which uses
//     the "COOKER_MAX" counter type and 
//     gets its data from the
//     AvailableMBytes property in the raw class

    [
     CookingType("COOKER_MAX"),
     Counter("AvailableMBytes"),
     SampleWindow(10)
    ]
    uint64 Max = 0;

// Define the Range property, which uses
//     the "COOKER_RANGE" counter type and 
//     gets its data from the AvailableMBytes
//     property in the raw class

    [
     CookingType("COOKER_RANGE"),
     Counter("AvailableMBytes"),
     SampleWindow(10)
    ]
    uint64 Range = 0;

// Define the Variance property, which uses
//     the "COOKER_VARIANCE" counter type and 
//     gets its data from the AvailableMBytes
//     property in the raw class

    [
     CookingType("COOKER_VARIANCE"),
     Counter("AvailableMBytes"),
     SampleWindow(10)
    ]
    uint64 Variance = 0;
};

스크립트

다음 스크립트 코드 예제에서는 이전에 만든 MOF를 사용하여 사용 가능한 메모리(MB)에 대한 통계를 가져옵니다. 이 스크립트는 SWbemRefresher 스크립팅 개체를 사용하여 MOF 파일이 만드는 통계 클래스의 인스턴스 Win32_PerfFormattedData_MemoryStatistics가 있는 리프레셔를 만듭니다. 스크립트 사용에 관한 자세한 내용은 스크립트에서 WMI 데이터 새로 고침을 참조하세요. C++에서 작업 하는 경우 C++에서 성능 데이터 액세스를 참조하세요.

참고

SWbemRefresher.Add 호출에서 항목을 가져온 후에 SWbemRefreshableItem.Object를 호출하지 않으면 스크립트가 실패합니다. 기준 값을 얻기 위해 루프를 입력하기 전에 SWbemRefresher.Refresh를 호출하지 않으면 통계 속성이 첫 번째 패스에서 0입니다.

 

' Connect to the Root\Cimv2 namespace
strComputer = "."
Set objService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")

' Create a refresher
Set Refresher = CreateObject("WbemScripting.SWbemRefresher")
If Err <> 0 Then
WScript.Echo Err
WScript.Quit
End If

' Add the single instance of the statistics
'    class to the refresher
Set obMemoryStatistics = Refresher.Add(objService, _
    "Win32_PerfFormattedData_MemoryStatistics=@").Object

' Refresh once to obtain base values for cooking calculations
Refresher.Refresh

Const REFRESH_INTERVAL = 10

' Refresh every REFRESH_INTERVAL seconds 
For I=1 to 3
  WScript.Sleep REFRESH_INTERVAL * 1000
  Refresher.Refresh

  WScript.Echo "System memory statistics" _
      & "(Available Megabytes) " _
      & "for the past 100 seconds - pass " & i 
  WScript.Echo "Average = " _
     & obMemoryStatistics.Average & VBNewLine & "Max = " _
     & obMemoryStatistics.Max & VBNewLine & "Min = " _
     & obMemoryStatistics.Min & VBNewLine & "Range = " _ 
     & obMemoryStatistics.Range & VBNewLine & "Variance = " _
     & obMemoryStatistics.Variance 
Next

스크립트 실행

다음 절차에서는 예제를 사용하는 방법을 설명합니다.

예제 스크립트를 실행하려면

  1. MOF 코드와 스크립트를 모두 컴퓨터의 파일에 복사합니다.
  2. MOF 파일에 .mof 확장명을 부여하고 스크립트 파일에는 .vbs 설명을 제공합니다.
  3. 명령줄에서 파일이 저장되는 디렉터리를 변경하고 MOF 파일에서 Mofcomp를 실행합니다. 예를 들어, 파일 이름을 CalculatedData.mof로 지정하면 그 명령은 MofcompCalculatedData.mof다.
  4. 스크립트를 실행합니다.

성능 데이터 모니터링

WMI 사전 설치 성능 클래스에 액세스

형식이 지정된 성능 카운터 클래스의 속성 한정자

통계 카운터 형식