status page prototype
This commit is contained in:
parent
a19d032ee9
commit
f6f5e5208a
|
@ -38,7 +38,8 @@ public class rusEFISSLContext {
|
|||
|
||||
public static void init(String fileName, String password) throws MalformedURLException {
|
||||
// system property setup does not work under Jenkins?
|
||||
setupCertificates(new File(fileName), password);
|
||||
if (!isJenkins)
|
||||
setupCertificates(new File(fileName), password);
|
||||
|
||||
//key = getFromPath(fileName, "PKCS12", password);
|
||||
}
|
||||
|
|
|
@ -18,9 +18,7 @@ import org.takes.rs.RsJson;
|
|||
import javax.json.Json;
|
||||
import javax.json.JsonArrayBuilder;
|
||||
import javax.json.JsonObject;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.Socket;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
@ -53,8 +51,10 @@ public class Backend {
|
|||
|
||||
new Thread(() -> {
|
||||
try {
|
||||
System.out.println("Starting http backend on " + httpPort);
|
||||
new FtBasic(
|
||||
new TkFork(showOnlineUsers,
|
||||
Monitoring.showStatistics,
|
||||
new FkRegex(VERSION_PATH, BACKEND_VERSION),
|
||||
new FkRegex("/", "<a href='https://rusefi.com/online/'>rusEFI Online</a>")
|
||||
), httpPort
|
||||
|
@ -78,6 +78,7 @@ public class Backend {
|
|||
public void runApplicationConnector(int serverPortForApplications, Listener serverSocketCreationCallback) {
|
||||
// connection from authenticator app which proxies for Tuner Studio
|
||||
// authenticator pushed hello packet on connect
|
||||
System.out.println("Starting application connector at " + serverPortForApplications);
|
||||
BinaryProtocolServer.tcpServerSocket(logger, new Function<Socket, Runnable>() {
|
||||
@Override
|
||||
public Runnable apply(Socket applicationSocket) {
|
||||
|
@ -128,6 +129,7 @@ public class Backend {
|
|||
}
|
||||
|
||||
public void runControllerConnector(int serverPortForControllers, Listener serverSocketCreationCallback) {
|
||||
System.out.println("Starting controller connector at " + serverPortForControllers);
|
||||
BinaryProtocolServer.tcpServerSocket(logger, new Function<Socket, Runnable>() {
|
||||
@Override
|
||||
public Runnable apply(Socket controllerSocket) {
|
||||
|
|
|
@ -10,7 +10,9 @@ public class BackendLauncher {
|
|||
* need this method to be not in Backend class for console to work without all backend classes
|
||||
*/
|
||||
public static void start(String[] args) throws MalformedURLException {
|
||||
/* todo
|
||||
rusEFISSLContext.setupCertificates(new File("keystore.jks"), System.getProperty("RUSEFI_PROXY_PASSWORD"));
|
||||
*/
|
||||
|
||||
UserDetailsResolver userDetailsFunction = new JsonUserDetailsResolver();
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package com.rusefi.server;
|
||||
|
||||
import org.takes.Take;
|
||||
import org.takes.facets.fork.FkRegex;
|
||||
import org.takes.rs.RsJson;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonObjectBuilder;
|
||||
import java.io.IOException;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.OperatingSystemMXBean;
|
||||
|
||||
public class Monitoring {
|
||||
static final FkRegex showStatistics = new FkRegex("/status",
|
||||
(Take) req -> Monitoring.getStatus());
|
||||
|
||||
|
||||
private static String formatSize(long v) {
|
||||
if (v < 1024) return v + " B";
|
||||
int z = (63 - Long.numberOfLeadingZeros(v)) / 10;
|
||||
return String.format("%.1f %sB", (double) v / (1L << (z * 10)), " KMGTPE".charAt(z));
|
||||
}
|
||||
|
||||
private static RsJson getStatus() throws IOException {
|
||||
JsonObjectBuilder builder = Json.createObjectBuilder();
|
||||
OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
|
||||
builder.add("CPU_Load", operatingSystemMXBean.getSystemLoadAverage());
|
||||
builder.add("free_ram", formatSize(Runtime.getRuntime().freeMemory()));
|
||||
builder.add("max_ram", formatSize(Runtime.getRuntime().maxMemory()));
|
||||
|
||||
return new RsJson(builder.build());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue