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 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()); } public String getOS() { return os; } public void setOS(String os) { this.os = os; } public String getCPUModel() { return cpu; } public int getCPUcount() { return cpucount; } public void setCPUcount(int cpucount) { this.cpucount = cpucount; } public int getMemTotal() { return memTotal; } public void setMemTotal(int memTotal) { this.memTotal = memTotal; } public int getMemFree() { return memFree; } public void setMemFree(int memFree) { this.memFree = memFree; } public float getLoad() { return load; } public void setLoad(float load) { this.load = load; } public long getUptime() { return uptime; } public void setUptime(long uptime) { this.uptime = uptime; } public State getState() { return state == null ? State.OFFLINE : state; } public void setState(State state) { this.state = state; } public long getLastpoll() { return lastpoll; } public void setLastpoll(long lastpoll) { this.lastpoll = lastpoll; } public void setCPU(String cpu) { this.cpu = cpu; } public String getUptimeFormatted() { return DateFormatUtils.format(uptime * 1000, "HH:mm:ss"); } public String getLastPollFormatted() { return getDate(lastpoll, "dd.MM.yyyy HH:MM:ss"); } }