126 lines
2.8 KiB
Java
126 lines
2.8 KiB
Java
package de.gurkengewuerz.monitoring.object;
|
|
|
|
import org.sqlite.date.DateFormatUtils;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Calendar;
|
|
|
|
/**
|
|
* Created by gurkengewuerz.de on 21.10.2017.
|
|
*/
|
|
public class ServerStatus {
|
|
|
|
private String os;
|
|
private String cpu;
|
|
private int cpucount;
|
|
private int memTotal;
|
|
private int memFree;
|
|
private float load;
|
|
private long uptime;
|
|
private State state;
|
|
private long lastpoll;
|
|
|
|
public ServerStatus(String os, String cpu, int cpucount, int memTotal, int memFree, float load, long uptime, State state, long lastpoll) {
|
|
this.os = os == null ? "Unknown" : os;
|
|
this.cpu = cpu == null ? "Unknown" : cpu;
|
|
this.cpucount = cpucount;
|
|
this.memTotal = memTotal;
|
|
this.memFree = memFree;
|
|
this.load = load;
|
|
this.uptime = uptime;
|
|
this.state = state;
|
|
this.lastpoll = lastpoll;
|
|
}
|
|
|
|
public String getOS() {
|
|
return os;
|
|
}
|
|
|
|
public String getCPUModel() {
|
|
return cpu;
|
|
}
|
|
|
|
public int getCPUcount() {
|
|
return cpucount;
|
|
}
|
|
|
|
public int getMemTotal() {
|
|
return memTotal;
|
|
}
|
|
|
|
public int getMemFree() {
|
|
return memFree;
|
|
}
|
|
|
|
public float getLoad() {
|
|
return load;
|
|
}
|
|
|
|
public long getUptime() {
|
|
return uptime;
|
|
}
|
|
|
|
public State getState() {
|
|
return state == null ? State.OFFLINE : state;
|
|
}
|
|
|
|
public long getLastpoll() {
|
|
return lastpoll;
|
|
}
|
|
|
|
public void setOS(String os) {
|
|
this.os = os;
|
|
}
|
|
|
|
public void setCPU(String cpu) {
|
|
this.cpu = cpu;
|
|
}
|
|
|
|
public void setCPUcount(int cpucount) {
|
|
this.cpucount = cpucount;
|
|
}
|
|
|
|
public void setMemTotal(int memTotal) {
|
|
this.memTotal = memTotal;
|
|
}
|
|
|
|
public void setMemFree(int memFree) {
|
|
this.memFree = memFree;
|
|
}
|
|
|
|
public void setLoad(float load) {
|
|
this.load = load;
|
|
}
|
|
|
|
public void setUptime(long uptime) {
|
|
this.uptime = uptime;
|
|
}
|
|
|
|
public void setState(State state) {
|
|
this.state = state;
|
|
}
|
|
|
|
public void setLastpoll(long lastpoll) {
|
|
this.lastpoll = lastpoll;
|
|
}
|
|
|
|
public String getUptimeFormatted() {
|
|
return DateFormatUtils.format(uptime * 1000, "HH:mm:ss");
|
|
}
|
|
|
|
public String getLastPollFormatted() {
|
|
return getDate(lastpoll, "dd.MM.yyyy HH:MM:ss");
|
|
}
|
|
|
|
|
|
public static String getDate(long milliSeconds, String dateFormat) {
|
|
// Create a DateFormatter object for displaying date in specified format.
|
|
SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);
|
|
|
|
// Create a calendar object that will convert the date and time value in milliseconds to date.
|
|
Calendar calendar = Calendar.getInstance();
|
|
calendar.setTimeInMillis(milliSeconds);
|
|
return formatter.format(calendar.getTime());
|
|
}
|
|
}
|