Added some test code
This commit is contained in:
parent
2e3b66a22f
commit
fec6184dc8
2 changed files with 19 additions and 3 deletions
3
src/META-INF/MANIFEST.MF
Normal file
3
src/META-INF/MANIFEST.MF
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
Manifest-Version: 1.0
|
||||
Main-Class: wa.server.WebAdminServer
|
||||
|
||||
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
package wa.server.util;
|
||||
|
||||
import zutil.io.MultiPrintStream;
|
||||
import zutil.log.LogUtil;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
|
|
@ -57,12 +58,13 @@ public class ProcStat {
|
|||
BufferedReader in = new BufferedReader(new FileReader(PROC_PATH));
|
||||
String line = null;
|
||||
while((line=in.readLine()) != null){
|
||||
String[] str = line.split("\\w*");
|
||||
if(str[0].equals("cpu"))
|
||||
String[] str = line.split("\\W+");
|
||||
if(str[0].equals("cpu")) {
|
||||
cpuTotal.update(str);
|
||||
}
|
||||
else if(str[0].startsWith("cpu")){
|
||||
int cpuId = Integer.parseInt(str[0].substring(3));
|
||||
if(cpus.size() < cpuId)
|
||||
if(cpus.size() <= cpuId)
|
||||
cpus.add(new CpuStats());
|
||||
cpus.get(cpuId).update(str);
|
||||
}
|
||||
|
|
@ -190,4 +192,15 @@ public class ProcStat {
|
|||
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
while(true){
|
||||
Iterator<CpuStats> it = ProcStat.getCpuStats();
|
||||
for(int i=0; it.hasNext(); ++i){
|
||||
CpuStats cpu = it.next();
|
||||
System.out.print("CPU"+i+": " + cpu.getTotalLoad()+ " ");
|
||||
}
|
||||
System.out.println("Total Load: " + ProcStat.getTotalCpuStats().getTotalLoad());
|
||||
try{Thread.sleep(1000);}catch (Exception e){}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue