2016-03-25 4 views
0
#http://stackoverflow.com/a/24036900/175063 

$user = "uuuu" 
$pwd = "pppp" 
$source = "http://1.1.1.1/manager/jmxproxy?get=java.lang:type=Memory&att=HeapMemoryUsage" 
$destination = "D:\Work\ps\test.xml" 
$wc = new-object System.Net.WebClient 
$p = New-Object System.Net.WebProxy 'http://proxy:8080' 
$p.UseDefaultCredentials = $true 
$wc.proxy = $p 
$credCache = New-Object System.Net.CredentialCache 
$creds = New-Object System.Net.NetworkCredential($user, $pwd) 
$credCache.Add($source, "Basic", $creds) 
$wc.Credentials = $credCache 
$wc.DownloadFile($source, $destination) 

# max=1445462016, used=898674904 
# free 

foreach ($thing in Get-Content $destination) { 
    $max = $thing.split("max=") 
    $used = $thing.split("used=") 

    Write-Host $max 
    Write-Host $used 
} 

#$free = $max - $used 
#Write-Host $free 

文字列ダウンロードされたファイルは、ワンライナーです:は最大にしたい文字列から使用

OK - Attribute get 'java.lang:type=Memory' - HeapMemoryUsage= javax.management.openmbean.CompositeDataSupport(compositeType=javax.management.openmbean.CompositeType(name=java.lang.management.MemoryUsage,items=((itemName=committed,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=init,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=max,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)),(itemName=used,itemType=javax.management.openmbean.SimpleType(name=java.lang.Long)))),contents={committed=1444478976, init=1494220800, max=1445462016, used=868228272})

そして、私は本当にそれから望むすべてがある:へ

max=1445462016 
used=868228272

be:

1445462016-868228272=577233744

答えて

0

私はこれを正しく解釈したと思います。あなたはしたいですか?コンソールでこれを表示したり、変数に格納、私はここにコンソールを想定しています:

write-host "$max-$used="($max-$used) 
+0

私の問題は、解析することができないか、最大値または使用された値を得ることができないことです。数学部分を行う方法を知っています。 – Leptonator

0

私は自分のソリューションを考え出した...私はそれが最善の方法ではないかもしれない知っているが、動作しているようです..

#http://stackoverflow.com/a/24036900/175063 

$user="uuuu" 
$pwd="pppp" 
$source="http://1.1.1.1/manager/jmxproxy?get=java.lang:type=Memory&att=HeapMemoryUsage" 
$destination="D:\Work\ps\test.xml" 
$wc=new-object System.Net.WebClient 
$p = New-Object System.Net.WebProxy 'http://proxy:8080' 
$p.UseDefaultCredentials = $true 
$wc.proxy=$p 
$credCache=new-object System.Net.CredentialCache 
$creds=new-object System.Net.NetworkCredential($user,$pwd) 
$credCache.Add($source, "Basic", $creds) 
$wc.Credentials=$credCache 
$wc.DownloadFile($source, $destination) 

# max=1445462016, used=898674904 
# free 

foreach ($thing in Get-Content $destination) { 
    # , max=1445462016, used=696318832}) 
    # $a = $a.substring(2,3) 
    # MID: https://technet.microsoft.com/en-us/library/ee176901.aspx 
    # LEN: https://technet.microsoft.com/en-us/library/ee176895.aspx 
    # Instr: https://technet.microsoft.com/en-us/library/ee176876.aspx 
    $len = $thing.length 
    $maxst = $thing.indexof("max=") 
    $usedst = $thing.indexof("used=") 

    $max=$thing.substring($maxst+4,$len-$usedst-6) 
    $used=$thing.substring($usedst+5,$len-$usedst-7) 
    $free=$max-$used 

    # , max=1445462016, used=696318832}) 

    write-host $len 
    write-host $maxst 
    write-host $usedst 
    write-host $max 
    write-host $used 
    write-host $free 
} 
2

私は、正規表現で文字列のcontents={...}部分から値を抽出改行でカンマを交換し、ハッシュテーブルに結果を変換します。次に、計算のために値を整数にキャストするだけです。

Get-Content $destination | Where-Object { 
    $_ -match ',contents=\{(.+?)\}' 
} | ForEach-Object { 
    $values = $matches[1] -replace ', ', "`n" | ConvertFrom-StringData 

    $free = [int]$values['max'] - [int]$values['used'] 

    'Max: {0}' -f $values['max'] 
    'Used: {0}' -f $values['used'] 
    'Free: {0}' -f $free 
} 
関連する問題