달력

4

« 2024/4 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
일반적으로 Hyper-V 인프라가 구성되면, System Center가 함께 배포가 됩니다. VM의 성능 수집을 위해 VM 자체에 SCOM 에이전트를 설치하지 않고도 기본적인 CPU 사용률, 메모리 사용률(동적 메모리일 경우), 디스크 IO 사용량(Read/Write Bytes/sec) 및 네트워크 IO 사용량(Received/Sent Bytes/sec)을 수집할 수 있습니다.

아래 VB 스크립트는 이 중 CPU와 메모리 사용률을 가져오는 스크립트로 VMM의 WMI 클래스인 Win32_PerfFormattedData_VMMPerfCounters_VMMVirtualMachineCPU 클래스를 쿼리해 정보를 가져오는 방법입니다.


' Collection Rule for vCPU, Dynamic Memory Usages

' $Data/Property[@Name='Object']$
' $Data/Property[@Name='Counter']$
' $Data/Property[@Name='Instance']$
' $Data/Property[@Name='PerfValue']$

Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()

Set wshShell = WScript.CreateObject( "WScript.Shell" )
strComputerName = wshShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
Set wshShell = Nothing

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\virtualization\v2")
Set colItems = objWMIService.ExecQuery("Select ElementName,Name from Msvm_ComputerSystem Where Name <> '"&strComputerName&"'")

intCount = colItems.Count
ReDim VMName(intCount),VMID(intCount)

i = 0
For Each Item in colItems
 VMName(i) = Item.ElementName
 VMID(i) = Item.Name
 i = i + 1
Next
Set colItems = Nothing
Set objWMIService = Nothing

Check = 0
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select Name,PercentGuestRunTime,CurrentPressurePercent from Win32_PerfFormattedData_VMMPerfCounters_VMMVirtualMachineCPU")
For Each Item in colItems
 tmpVMID = Item.Name
 For i = 0 to intCount-1
  If VMID(i) = tmpVMID Then
   Check = 1
   Set propertyBag = oAPI.CreatePropertyBag()
   propertyBag.AddValue "Object","Hyper-V Hypervisor Virtual Processor"
   propertyBag.AddValue "Counter","% Total Run Time"
   propertyBag.AddValue "Instance",VMName(i)
   propertyBag.AddValue "PerfValue",Item.PercentGuestRunTime
   oAPI.AddItem(propertyBag)

   Set propertyBag = oAPI.CreatePropertyBag()
   propertyBag.AddValue "Object","Hyper-V Dynamic Memory VM"
   propertyBag.AddValue "Counter","Current Pressure"
   propertyBag.AddValue "Instance",VMName(i)
   propertyBag.AddValue "PerfValue",Item.CurrentPressurePercent
   oAPI.AddItem(propertyBag)
  End If
 Next
Next
Set colItems = Nothing
Set objWMIService = Nothing

If Check = 1 Then
 oAPI.ReturnItems
End If

Set oBag = Nothing
Set oAPI = Nothing



 
:
Posted by 커널64