Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SSHUtil.java #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/main/java/common/toolkit/java/util/io/SSHUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,21 @@ private static HostPerformanceEntity getHostPerformance( Connection conn ) throw
// 第四行通常是这样:
// Mem: 1572988k total, 1490452k used, 82536k free, 138300k
// buffers
String[] memArray = line.replace( MEM_USAGE_STRING, EMPTY_STRING ).split( COMMA );
//Ubuntu14下,第4行是这样:KiB Mem: 3037852 total, 1626320 used, 1411532 free, 141148 buffers
//Ubuntu14下,多了KiB,因此对此“KiB"进行替换
String[] memArray = line.replace("KiB",EMPTY_STRING).replace( MEM_USAGE_STRING, EMPTY_STRING ).split( COMMA );

totalMem = StringUtil.trimToEmpty( memArray[0].replace( "total", EMPTY_STRING ) ).replace( "k", EMPTY_STRING );
freeMem = StringUtil.trimToEmpty( memArray[2].replace( "free", EMPTY_STRING ) ).replace( "k", EMPTY_STRING );
buffersMem = StringUtil.trimToEmpty( memArray[3].replace( "buffers", EMPTY_STRING ) ).replace( "k", EMPTY_STRING );
} else if ( 5 == lineNum ) {
// 第四行通常是这样:
// Swap: 2096472k total, 252k used, 2096220k free, 788540k
// cached
String[] memArray = line.replace( SWAP_USAGE_STRING, EMPTY_STRING ).split( COMMA );
//Ubuntu14下,是这样:KiB Swap: 2093052 total, 0 used, 2093052 free. 523408 cached Mem
//Ubuntu14,free后是".",而不是",",导致分割时 memArray[3]为null;同时,最后多了"Mem"
String[] memArray = line.replace(".",COMMA).replace("Mem", EMPTY_STRING).replace( SWAP_USAGE_STRING, EMPTY_STRING ).split( COMMA );

cachedMem = StringUtil.trimToEmpty( memArray[3].replace( "cached", EMPTY_STRING ) ).replace( "k", EMPTY_STRING );

if ( StringUtil.isBlank( totalMem, freeMem, buffersMem, cachedMem ) )
Expand Down