dendy@dendy-laptop:~$ top -b -n 1 | head -n 5
top - 09:56:29 up 58 min, 2 users, load average: 0.98, 0.97, 0.91
Tasks: 171 total, 1 running, 170 sleeping, 0 stopped, 0 zombie
Cpu(s): 16.4%us, 4.1%sy, 1.1%ni, 76.3%id, 2.0%wa, 0.1%hi, 0.1%si, 0.0%st
Mem: 2508872k total, 1958800k used, 550072k free, 163740k buffers
Swap: 1967920k total, 0k used, 1967920k free, 955112k cached
output yang di ingiinkan :
Cpu;16.4
Mem;2508872;1958800
Swap;1967920
berikut codingannya :
package com.andia.aryandie.latihan.parser;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.LinkedList;
/**
* CPU, MemTotal, MemUsage, Swap
*
* @author dendy
*
*/
public class TopParser {
public static void main(String[] args) {
String filename = "file/top.txt";
File file = new File(filename);
try {
FileReader fileReader = new FileReader(file);
BufferedReader reader = new BufferedReader(fileReader);
String line = "";
LinkedList
try {
while ((line = reader.readLine()) != null) {
String[] fields = line.split(" +");
isiRecord.addLast(line);
if (line.contains("Cpu")) {
System.out.println(fields[0].substring(0, 3) + ";"
+ fields[1].substring(0, 4));
}
if (line.contains("Mem:")) {
System.out.println(fields[0].substring(0, 3) + ";"
+ fields[1].substring(0, 7) + ";"
+ fields[3].substring(0, 7));
}
if (line.contains("Swap:")) {
System.out.println(fields[0].substring(0, 4) + ";"
+ fields[1].substring(0, 7));
}
}
} catch (Exception e) {
}
} catch (Exception e) {
}
}
}
No comments:
Post a Comment