2016-04-14 76 views
0

我一直在对此进行深入研究。我觉得我很接近,但我在试图展示WS时遇到了麻烦。Tomcat的PowerShell内存使用情况

我没找到什么似乎显示每个应用程序的内存

http://www.lmftfy.com/index.php/powershell-get-memory-used-by-a-group-of-processes/

https://foobarcode.wordpress.com/2014/12/12/memory-usage-grouped-by-process-name/

ps tomcat* -ComputerName computerA | Group ProcessName | Select @{Label="Mem";Expression={($_.group |Measure WorkingSet -sum).Sum/1MB }} | Sort Mem 

非常相关的,这工作得很好。

$procs = get-process tomcat* -ComputerName computerA 
    foreach ($proc in $procs){ 
    $WorkingSet = '{0:N0}' -f [int](Group ProcessName | Select (@{Label="Mem";Expression={($proc.group |Measure WorkingSet -sum).Sum/1MB }})) 
    $VirtualMem = '{0:N0}' -f [int]($proc.VM/1MB) 
     write-host 'WS' $WorkingSet 
     write-host 'VM' $VirtualMem 
} 

我们知道WS是不是0 ..

我想我有一个格式问题与:

Mem 
--- 
4.109375 
1006.9453125 
1388.453125 

所以......我们通过大量的计算机要循环WS ..

WS 0 
VM 1,523 
WS 0 
VM 60 
WS 0 
VM 1,917 

我以为我是在这个非常接近..

$procs = get-process tomcat* -ComputerName computerA 
    foreach ($proc in $procs){ 
    $name = $proc.MachineName 
    $process = $proc.ProcessName 
    $WorkingSet = '{0:N0}' -f [int]($proc.WS/1MB) 
    $VirtualMem = '{0:N0}' -f [int]($proc.VM/1MB) 
    write-host $name $process 'WS' $WorkingSet 'VM' $VirtualMem 
} 

但是,使用此当我得到负值..

Tomcat Memory Usage Report - 04/14/2016       
# Server Process ID (PID) Process Name Working Set(Kb) Virtual Memory(Mb) 
25 Server24 5876 tomcat6 1,471 -251  
26 Server25 5832 tomcat6 -1,536 -1,118 
27 Server26 1824 tomcat6 -1,497 -1,133 
28 Server27 7916 tomcat6 1,661 -1,013 
29 Server28 6340 tomcat6 888 1,690 
30 Server29 6700 tomcat6 -1,242 1,611 
31 Server30 9880 Tomcat6 1,007 1,523 

回答

0

这是否帮助任何?

(Get-Counter -ListSet Process | Get-Counter) | 
Where {$_.InstanceName -eq 'TomCat' -and $_.path -like '*working set*'} 
0

您应该使用$proc.workingset64,如果你在64位系统上得到负值