我一直在研究这个问题。我认为非常接近,但我在尝试显示 WS 时遇到了问题。
我确实发现与显示每个应用程序的内存非常相关
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
这很好用。
Mem
---
4.109375
1006.9453125
1388.453125
所以...我们想遍历多台计算机:
$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..
我想我的 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
最佳答案
这有什么帮助吗?
(Get-Counter -ListSet Process | Get-Counter) |
Where {$_.InstanceName -eq 'TomCat' -and $_.path -like '*working set*'}
关于Tomcat 的 PowerShell 内存使用情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36632719/