package pSystemWatch;
import com.jezhumble.javasysmon.*;
import java.text.SimpleDateFormat;
import java.util.Date;
public class SystemWatchFinal {
private static JavaSysMon MONITOR = new JavaSysMon();
public double getCpuFrequency() {
return MONITOR.cpuFrequencyInHz() / 1000000000;
}
public int getCpuNumber() {
return MONITOR.numCpus();
}
public String getBiggestProcess() {
// gat array of all process
ProcessInfo[] table = MONITOR.processTable();
// start with the first one and iterate
ProcessInfo biggest = table[0];
for (ProcessInfo pi : MONITOR.processTable()) {
// check if the current consumes more bytes then the previous
if (pi.getTotalBytes() > biggest.getTotalBytes()) {
biggest = pi;
}
}
return biggest.getName();
}
public String getBootTime(){
// get up time in seconds
long uptime = getUpTime();
// caluculate time difference to now
long millisecondsSincebootTime = new Date().getTime() - uptime * 1000;
// setup a nice date format
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss dd.MMM yyyy");
return formatter.format(new Date(millisecondsSincebootTime));
}
public String getOS() {
return MONITOR.osName();
}
public double getRamFree() {
return MONITOR.physical().getFreeBytes() / 1024 / 1024;
}
public double getRamTotal() {
return MONITOR.physical().getTotalBytes() / 1024 / 1024;
}
public long getUpTime() {
return MONITOR.uptimeInSeconds();
}
public String[] getProcessByName(String name){
ProcessInfo myProcess = null;
// iterate over all processes and check for the right name
for(ProcessInfo pi : MONITOR.processTable()){
if(pi.getName().equals(name)){
myProcess = pi;
break;
}
}
// build up the answer array if there was a matching process
if(myProcess != null){
String[] ans = new String[3];
ans[0] = myProcess.getName();
ans[1] = myProcess.getOwner();
ans[2] = Long.toString(myProcess.getTotalBytes());
return ans;
}else{
return null;
}
}
}