- #查询服务器性能
- $cpu=((get-counter -counter "\processor(_total)\% processor time").CounterSamples|where {$_.InstanceName -eq "_total" }).CookedValue
- $men = gwmi win32_OperatingSystem
- $hostname=((Gwmi Win32_NetworkAdapterConfiguration|?{$_.IPEnabled -and $_.DefaultIPGateway}).IPAddress)[0]
- $Disks = gwmi win32_logicaldisk|?{$_.drivetype -eq 3}
- $Havecpu = "{0:0.0} %" -f $cpu
- $Allmen = "{0:0.0} MB" -f ($men.TotalVisibleMemorySize / 1mB)
- $Freemen = "{0:0.0} MB" -f ($men.FreePhysicalMemory / 1mB)
- $Permem = "{0:0.0} %" -f ((($men.TotalVisibleMemorySize-$men.FreePhysicalMemory)/$men.TotalVisibleMemorySize)*100)
- $logical_read=" {0:0.0} KB" -f ($(((get-counter -counter "\LogicalDisk(_total)\Disk Read Bytes/sec").CounterSamples|where {$_.InstanceName -eq "_total" }).CookedValue) / 1KB)
- $logical_write=" {0:0.0} KB" -f ($(((get-counter -counter "\LogicalDisk(_total)\Disk Write Bytes/sec").CounterSamples|where {$_.InstanceName -eq "_total" }).CookedValue) / 1KB)
- $network_sent=" {0:0.0} KB" -f ($((Get-Counter -Counter "\Network Interface(*)\Bytes Sent/sec").CounterSamples|%{$_.CookedValue}|sort|select -last 1) / 1KB)
- $network_rece=" {0:0.0} KB" -f ($((Get-Counter -Counter "\Network Interface(*)\Bytes Received/sec").CounterSamples|%{$_.CookedValue}|sort|select -last 1) / 1KB)
- Write-Host " $(,"="*25)
- $(get-date) 服务器:" $($hostname.Padleft(16)) "
- CPU利用率:$($Havecpu.Padleft(8))" <#内存总数:$Allmen 内存可用数:$Freemen#> " 内存使用率:$($Permem.Padleft(12) )
- 网络发/秒: $($network_sent.Padleft(8)) 网络收/秒: $($network_rece.Padleft(13) )
- 磁盘读/秒: $($logical_read.Padleft(8)) 磁盘写/秒: $($logical_write.Padleft(13) )
- 盘符 盘总空间 空闲空间 使用空间 使用百分比" -ForegroundColor Green
- foreach ($Disk in $Disks) {
- $Size = "{0:0.0} GB" -f ($Disk.Size / 1GB )
- $FreeSpace = " {0:0.0} GB" -f ($Disk.FreeSpace / 1GB)
- $Used = ([int64]$Disk.size - [int64]$Disk.freespace)
- $SpaceUsed = " {0:0.0} GB" -f ($Used / 1GB)
- $Percent ="{0:0.0} %" -f ($Used * 100 / $Disk.Size)
- #Write-Host " "$Disk.deviceid $Disk.volumename" `t$Size `t$FreeSpace `t$SpaceUsed `t$Percent" -ForegroundColor Green
- $n=5
- Write-Host " "$Disk.deviceid.PadRight($n) -no -ForegroundColor Green
- $n=10
- Write-Host $Size.Padleft($n) -no -ForegroundColor Green
- Write-Host $FreeSpace.Padleft($n) -no -ForegroundColor Green
- Write-Host $SpaceUsed.Padleft($n) -no -ForegroundColor Green
- Write-Host $Percent.Padleft($n) -ForegroundColor Green
- }
复制代码 http://hi.baidu.com/shrekzz/item/a40360495a395be9bdf45188 |