2016-03-25 9 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 

dize indirilen dosya tek liner geçerli:max istiyorum ve ipten kullanılan

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})

Ve gerçekten ondan istediğim şey: hiç

max=1445462016 
used=868228272

be:

1445462016-868228272=577233744

cevap

0

Bunu doğru şekilde yorumladım, ister misiniz? Ben kendi çözümünü anladım

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

Benim sorunum, bulamamış ya da en çok kullanılan değerleri kullanamıyorum .. Matematik bölümünü nasıl yapacağımı biliyorum .. – Leptonator

0

... Ben en iyi yolu olmayabilir biliyorum ama iş gibi görünüyor: konsolda bu görüntülemek veya bir değişkende saklayın, burada konsolu farz ediyorum ..

#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

Ben, normal bir ifade ile dize contents={...} kısmından değerleri ayıklamak yenisatırlar ile virgül yerine ve bir Hashtable sonucu dönüştürmek istiyorum. Daha sonra, değerleri hesaplama için tamsayılara vermeniz yeterlidir.

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 
}