diff --git a/java_console/io/src/main/java/com/rusefi/server/rusEFISSLContext.java b/java_console/io/src/main/java/com/rusefi/server/rusEFISSLContext.java index 5b8ac8c483..693a2fb77d 100644 --- a/java_console/io/src/main/java/com/rusefi/server/rusEFISSLContext.java +++ b/java_console/io/src/main/java/com/rusefi/server/rusEFISSLContext.java @@ -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); } diff --git a/java_tools/proxy_server/src/main/java/com/rusefi/server/Backend.java b/java_tools/proxy_server/src/main/java/com/rusefi/server/Backend.java index 681b6c9ebd..ac7e1e7827 100644 --- a/java_tools/proxy_server/src/main/java/com/rusefi/server/Backend.java +++ b/java_tools/proxy_server/src/main/java/com/rusefi/server/Backend.java @@ -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("/", "rusEFI Online") ), 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() { @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() { @Override public Runnable apply(Socket controllerSocket) { diff --git a/java_tools/proxy_server/src/main/java/com/rusefi/server/BackendLauncher.java b/java_tools/proxy_server/src/main/java/com/rusefi/server/BackendLauncher.java index 9dd49add44..f9c5a4b1b7 100644 --- a/java_tools/proxy_server/src/main/java/com/rusefi/server/BackendLauncher.java +++ b/java_tools/proxy_server/src/main/java/com/rusefi/server/BackendLauncher.java @@ -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(); diff --git a/java_tools/proxy_server/src/main/java/com/rusefi/server/Monitoring.java b/java_tools/proxy_server/src/main/java/com/rusefi/server/Monitoring.java new file mode 100644 index 0000000000..2b4c07b970 --- /dev/null +++ b/java_tools/proxy_server/src/main/java/com/rusefi/server/Monitoring.java @@ -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()); + } +}