80 lines
2.2 KiB
Java
Raw Normal View History

package com.wasteinformationserver.basicutils;
import java.io.IOException;
import java.net.URL;
2019-12-12 12:39:28 +01:00
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
2019-12-12 12:39:28 +01:00
import java.util.Date;
import java.util.Properties;
public class Info {
2020-01-23 18:32:29 +01:00
private static String version = "not init";
private static String builddate = "not init";
private static String starttime = "not init";
2020-01-23 18:32:29 +01:00
/**
* get Software Version (defined in gradle build file)
*
* @return Version as string
*/
2019-12-12 12:39:28 +01:00
public static String getVersion() {
return version;
}
2020-01-23 18:32:29 +01:00
/**
* get Software build date
*
* @return Date as string
*/
2019-12-12 12:39:28 +01:00
public static String getBuilddate() {
return builddate;
}
2020-01-23 18:32:29 +01:00
/**
* get Server start time
*
* @return start time
*/
2019-12-12 12:39:28 +01:00
public static String getStarttime() {
return starttime;
}
2020-01-23 18:32:29 +01:00
/**
* initialize the version and builddate variables
*/
public static void init() {
2019-12-12 12:39:28 +01:00
starttime = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(new Date());
Properties prop = new Properties();
try {
URL url = Info.class.getResource("/version.properties");
prop.load(url.openStream());
2020-01-23 18:32:29 +01:00
version = (String) prop.get("version");
builddate = (String) prop.get("buildtime");
} catch (IOException e) {
e.printStackTrace();
}
}
2019-12-12 12:39:28 +01:00
2020-01-23 18:32:29 +01:00
/**
* print memory utilization
*/
public static void getMemoryUsage() {
2019-12-12 12:39:28 +01:00
Runtime runtime = Runtime.getRuntime();
NumberFormat format = NumberFormat.getInstance();
StringBuilder sb = new StringBuilder();
long maxMemory = runtime.maxMemory();
long allocatedMemory = runtime.totalMemory();
long freeMemory = runtime.freeMemory();
sb.append("free memory: " + format.format(freeMemory / 1024) + "\n");
sb.append("allocated memory: " + format.format(allocatedMemory / 1024) + "\n");
sb.append("max memory: " + format.format(maxMemory / 1024) + "\n");
sb.append("total free memory: " + format.format((freeMemory + (maxMemory - allocatedMemory)) / 1024) + "\n");
System.out.println(sb.toString());
}
}