개발이즈 마이라이프/JavaSE
Machine 의 CPU 정보 얻어 오기
장발의 개발러
2012. 2. 7. 14:14
이걸 응용하면 Java로 시스템 모니터링이 가능해짐!
public static void main(String[] args) {
try {
// Windows 의 경우
// typeperf "\Processor(_Total)\% Processor Time" -sc 10
// -si: 간격, -sc: 수행회수
String cmd = "typeperf \"\\Processor(_Total)\\% Processor Time\" -si 5 -sc 10";
Runtime operator = Runtime.getRuntime();
Process process = operator.exec(cmd);
BufferedReader br = new BufferedReader(new InputStreamReader(
process.getInputStream(), "EUC-KR"));
String temp = br.readLine();
while ((temp = br.readLine()) != null) {
System.out.println(temp);
}
System.out.println("process.waitFor(): " + process.waitFor());
System.out.println("End");
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (InterruptedException ite) {
ite.printStackTrace();
}
}