从Win32_PerfRawData_NETFramework_NETCLMemory中选择PercentTimeinG



希望你一切顺利。

目标:从Win32_PerfRawData_NETFramework_NETCLRMemory PercentTimeinGC中提取WMI数据,如perfmon=".NET CLR Memory/%Time in GC"中所示

Enviroment IIS 7,Worker进程花园(4)(ASP.NET4.0应用程序池)(4xw3wp.exe进程)

故事:在本地perfmon中,我们可以在本地监控w3wp.exe的4个实例在垃圾收集中使用的时间,我们希望将这些数据导出到外部监控,如PRTG或自制的看门狗软件。

搜索网络并了解wql脚本和WMI查询会让我们相信这很简单,但事实并非如此。

添加语句"SELECT PercentTimeinGC FROM Win32_PerfRawData_NETFramework_NETCLRMemory"总是返回值"0",无论我们尝试什么wmi测试工具或脚本,但是搜索其他语句已经多次指出这是正确的语句。

所以我们错过了一些东西,或者根本不可能,我不相信。

希望这里的任何人都能告诉我们我们的短期合作;-)

谢谢,祝你今天愉快。

Mike

这个vbs代码可以完成。它是为splunk创建的。

On Error Resume Next
Set objWMISvc = GetObject( "winmgmts:\.rootcimv2" )
Set colItems = objWMISvc.ExecQuery( "Select * from Win32_ComputerSystem", , 48 )
For Each objItem in colItems
    strComputerName = objItem.Name
Next
CommandLine = "c:windowssystem32inetsrvw3wp.exe"
processName = "w3wp.exe"
QueryLine = "select * from win32_process where Name = " & """" & processName & """"
Computer = "."
Set WMIService = GetObject("winmgmts:\" & Computer & "rootcimv2")
Set Items = WMIService.ExecQuery(QueryLine, , 48)
For Each SubItems In Items
 If inStr(SubItems.CommandLine, "0") Then
    WScript.Echo "New Event:"
    w3wpRunningCount = w3wpRunningCount + 1
  WScript.Echo "CommandLine=" & SubItems.CommandLine
  creationdate = SubItems.CreationDate
  creationyear = Left(creationdate, 4)
  creationmonth = Mid(creationdate, 5, 2)
  creationday = Mid(creationdate, 7, 2)

  WScript.Echo "CreationDate=" & creationmonth & "-" & creationday & "-" & creationyear
  WScript.Echo "ProcessId=" & SubItems.ProcessId
  WScript.Echo "ThreadCount=" & SubItems.ThreadCount
  WScript.Echo "WorkingSetSizeMbytes=" & SubItems.WorkingSetSize/1024/1024
  WScript.Echo "PeakWorkingSetSizeMbytes=" & SubItems.PeakWorkingSetSize/1024
  WScript.Echo "PageFaults=" & SubItems.PageFaults
  WScript.Echo "EstAddedLatencyInSec=" & SubItems.PageFaults*8/1000
  WScript.Echo "PageFileUsageMbytes=" & SubItems.PageFileUsage/1024
  WScript.Echo "PeakPageFileUsageMbytes=" & SubItems.PeakPageFileUsage/1024
checkProcessorTime(SubItems.ProcessId)
      getclrmemoryobjectproperties(SubItems.ProcessId)
      getclrexceptionsobjects(objectName)
      getclrjitobjects(objectName)
      getclrlocksandthreadsobjects(objectName)
      getclrinteropobjects(objectName)
      getclrloadingobjects(objectName)
      getdpforsqlobjects(SubItems.ProcessId)
Next
WScript.Echo "New Event:"
wscript.Echo "w3wpRunningCount=" & w3wpRunningCount
machineinterrogationstart()

Function checkProcessorTime(PID)
set objService = getobject("winmgmts:")
Set objProcess = GetObject("winmgmts:{impersonationLevel=impersonate}//localhost")
Set objItems = objProcess.ExecQuery("Select PercentProcessorTime from Win32_PerfFormattedData_PerfProc_Process where IDProcess=" &PID& "")
for each objItem in objItems
Wscript.Echo "PercentCPU=" & objItem.PercentProcessorTime
Next
End Function
Function getclrmemoryobjectproperties(PID)
  Set clrmemoryobjects = WMIService.ExecQuery("select * from win32_perfformatteddata_netframework_netclrmemory where ProcessId = " & """" & PID & """")
  For Each clrmemoryobject in clrmemoryobjects
    echo_out(clrmemoryobject.Name),"ProcessName"
    echo_out(clrmemoryobject.AllocatedBytesPersec),"AllocatedBytesPersec"
    echo_out(clrmemoryobject.FinalizationSurvivors),"FinalizationSurvivors"
    echo_out(clrmemoryobject.Gen0heapsize),"Gen0heapsize"
    echo_out(clrmemoryobject.Gen0PromotedBytesPerSec),"Gen0PromotedBytesPerSec"
    echo_out(clrmemoryobject.Gen1heapsize),"Gen1heapsize"
    echo_out(clrmemoryobject.Gen1PromotedBytesPerSec),"Gen1PromotedBytesPerSec"
    echo_out(clrmemoryobject.Gen2heapsize),"Gen2heapsize"
    echo_out(clrmemoryobject.LargeObjectHeapsize),"LargeObjectHeapsize"
    echo_out(clrmemoryobject.NumberBytesinallHeaps),"NumberBytesinallHeaps"
    echo_out(clrmemoryobject.NumberGCHandles),"NumberGCHandles"
    echo_out(clrmemoryobject.NumberGen0Collections),"NumberGen0Collections"
    echo_out(clrmemoryobject.NumberGen1Collections),"NumberGen1Collections"
    echo_out(clrmemoryobject.NumberGen2Collections),"NumberGen2Collections"
    echo_out(clrmemoryobject.NumberInducedGC),"NumberInducedGC"
    echo_out(clrmemoryobject.NumberofPinnedObjects),"NumberofPinnedObjects"
    echo_out(clrmemoryobject.NumberofSinkBlocksinuse),"NumberofSinkBlocksinuse"
    echo_out(clrmemoryobject.NumberTotalcommittedBytes),"NumberTotalcommittedBytes"
    echo_out(clrmemoryobject.NumberTotalreservedBytes),"NumberTotalreservedBytes"
    echo_out(clrmemoryobject.PercentTimeinGC),"PercentTimeinGC"
    echo_out(clrmemoryobject.PromotedFinalizationMemoryfromGen0),"PromotedFinalizationMemoryfromGen0"
    echo_out(clrmemoryobject.PromotedMemoryfromGen0),"PromotedMemoryfromGen0"
    echo_out(clrmemoryobject.PromotedMemoryfromGen1),"PromotedMemoryfromGen1"
    objectName=clrmemoryobject.Name
  Next
End Function
Function getclrexceptionsobjects(objectName)
  Set clrexceptionsobjects = WMIService.ExecQuery("select * from win32_perfformatteddata_netframework_netclrexceptions where Name = " & """" & objectName & """")
  For Each clrexceptionsobject in clrexceptionsobjects
    echo_out(clrexceptionsobject.NumberofExcepsThrown),"NumberofExcepsThrown"
  Next
End Function
Function getclrjitobjects(objectName)
  Set clrjitobjects = WMIService.ExecQuery("select * from win32_perfformatteddata_netframework_netclrjit where Name = " & """" & objectName & """")
  For Each clrjitobject in clrjitobjects
    echo_out(clrjitobject.PercentTimeinJit),"PercentTimeinJit"
  Next
End Function
Function getclrlocksandthreadsobjects(objectName)
  Set clrlocksandthreadsobjects = WMIService.ExecQuery("select * from win32_perfformatteddata_netframework_netclrlocksandthreads where Name = " & """" & objectName & """")
  For Each clrlocksandthreadsobject in clrlocksandthreadsobjects
    echo_out(clrlocksandthreadsobject.NumberofcurrentlogicalThreads),"NumberofcurrentlogicalThreads"
    echo_out(clrlocksandthreadsobject.NumberofcurrentphysicalThreads),"NumberofcurrentphysicalThreads"
    echo_out(clrlocksandthreadsobject.CurrentQueueLength),"CurrentQueueLength"
    echo_out(clrlocksandthreadsobject.ContentionRatePersec),"ContentionRatePersec"
  Next
End Function
Function getclrinteropobjects(objectName)
  Set clrinteropobjects = WMIService.ExecQuery("select * from win32_perfformatteddata_netframework_netclrinterop where Name = " & """" & objectName & """")
  For Each clrinteropobject in clrinteropobjects
    echo_out(clrinteropobject.NumberofStubs),"NumberofStubs"
  Next
End Function
Function getclrloadingobjects(objectName)
  Set clrloadingobjects = WMIService.ExecQuery("select * from win32_perfformatteddata_netframework_netclrloading where Name = " & """" & clrmemoryobject.Name & """")
  For Each clrloadingobject in clrloadingobjects
    echo_out(clrloadingobject.CurrentAssemblies),"CurrentAssemblies"
    echo_out(clrloadingobject.RateofAssemblies),"RateofAssemblies"
    echo_out(clrloadingobject.BytesinLoaderHeap),"BytesinLoaderHeap"
  Next
End Function
Function getdpforsqlobjects(PID)
  Set dpforsqlobjects = WMIService.ExecQuery("select * from win32_perfformatteddata_netdataproviderforsqlserver_netdataproviderforsqlserver where Name like " & """%" & PID & "%""")
  For Each dpforsqlobject in dpforsqlobjects
    echo_out(dpforsqlobject.NumberOfActiveConnections),"SQLNumberofActiveConnections"
    echo_out(dpforsqlobject.NumberOfFreeConnections),"SQLNumberOfFreeConnections"
    echo_out(dpforsqlobject.SoftConnectsPerSecond),"SQLSoftConnectsPerSecond"
  Next
End Function
Function machineinterrogationstart()
  getaspobjects()
  getaspappobjects()
End Function
Function getaspobjects()
  Set aspobjects = WMIService.ExecQuery("select * from win32_perfformatteddata_aspnet_aspnet")
  for each aspobject in aspobjects
    echo_out(aspobject.ApplicationRestarts),"ASPApplicationRestarts"
    echo_out(aspobject.RequestExecutionTime),"ASPRequestExecutionTime"
    echo_out(aspobject.RequestWaitTime),"ASPRequestWaitTime"
    echo_out(aspobject.RequestsCurrent),"ASPRequestsCurrent"
    echo_out(aspobject.WorkerProcessRestarts),"ASPWorkerProcessRestarts"
  Next
End Function
Function getaspappobjects()
  Set aspappobjects = WMIService.ExecQuery("select * from win32_perfformatteddata_aspnet_aspnetapplications")
  for each aspappobject in aspappobjects
    echo_out(aspappobject.CacheTotalHitRatio),"ASPAppCacheTotalHitRatio"
    echo_out(aspappobject.CompilationsTotal),"ASPAppCompilationsTotal"
    echo_out(aspappobject.ErrorsDuringExecution),"ASPAppErrorsDuringExecution"
    echo_out(aspappobject.RequestsPerSec),"ASPAppRequestsPerSec"
  Next
End Function
Function echo_out(propertyvalue,propertydescription)
  wscript.echo propertydescription & "=" & propertyvalue
End Function

相关内容

  • 没有找到相关文章

最新更新