diff --git a/src/main/java/io/cryostat/agent/Registration.java b/src/main/java/io/cryostat/agent/Registration.java index 7757b981..e4c200c3 100644 --- a/src/main/java/io/cryostat/agent/Registration.java +++ b/src/main/java/io/cryostat/agent/Registration.java @@ -57,8 +57,13 @@ class Registration extends AbstractVerticle { + private static final String CRYOSTAT_AGENT_APP_NAME = "cryostat.agent.app.name"; + private static final String CRYOSTAT_AGENT_HOSTNAME = "cryostat.agent.hostname"; + private static final String CRYOSTAT_AGENT_APP_JMX_HOST = "cryostat.agent.app.jmx.host"; + private static final String CRYOSTAT_AGENT_APP_JMX_PORT = "cryostat.agent.app.jmx.port"; private static final String CRYOSTAT_AGENT_REGISTRATION_RETRY_MS = "cryostat.agent.registration.retry-ms"; + static final String EVENT_BUS_ADDRESS = Registration.class.getName() + ".UPDATE"; private static final String NODE_TYPE = "JVM"; @@ -153,14 +158,30 @@ private void tryUpdate(Long id) { } private DiscoveryNode defineSelf() throws UnknownHostException { - String jmxhost = "localhost"; - String appName = "cryostat-agent"; - int port = Integer.valueOf(System.getProperty("com.sun.management.jmxremote.port")); + String jmxhost = config.getValue(CRYOSTAT_AGENT_APP_JMX_HOST, String.class); + String appName = config.getValue(CRYOSTAT_AGENT_APP_NAME, String.class); + + int jmxport = + config.getOptionalValue(CRYOSTAT_AGENT_APP_JMX_PORT, int.class) + .orElse( + Integer.valueOf( + System.getProperty("com.sun.management.jmxremote.port"))); long pid = ProcessHandle.current().pid(); - String hostname = InetAddress.getLocalHost().getHostName(); + String hostname = + config.getOptionalValue(CRYOSTAT_AGENT_HOSTNAME, String.class) + .orElseGet( + () -> { + try { + return InetAddress.getLocalHost().getHostName(); + } catch (UnknownHostException uhe) { + log.error("Unable to determine own hostname", uhe); + return null; + } + }); String javaMain = System.getProperty("sun.java.command", System.getenv("JAVA_MAIN_CLASS")); if (StringUtils.isBlank(javaMain)) { + log.error("Unable to determine application mainclass"); javaMain = null; } long startTime = @@ -174,17 +195,17 @@ private DiscoveryNode defineSelf() throws UnknownHostException { URI.create( String.format( "service:jmx:rmi:///jndi/rmi://%s:%d/jmxrmi", - jmxhost, port)), + jmxhost, jmxport)), appName, instanceId, pid, hostname, - port, + jmxport, javaMain, startTime); DiscoveryNode selfNode = - new DiscoveryNode("cryostat-agent-" + pluginInfo.getId(), NODE_TYPE, target); + new DiscoveryNode(appName + "-" + pluginInfo.getId(), NODE_TYPE, target); return selfNode; } diff --git a/src/main/resources/META-INF/microprofile-config.properties b/src/main/resources/META-INF/microprofile-config.properties index 3cd7c7de..06bebeb4 100644 --- a/src/main/resources/META-INF/microprofile-config.properties +++ b/src/main/resources/META-INF/microprofile-config.properties @@ -6,3 +6,6 @@ cryostat.agent.realm= cryostat.agent.registration.retry-ms=5000 cryostat.agent.webserver.host=0.0.0.0 cryostat.agent.webserver.port=9977 + +cryostat.agent.app.name=cryostat-agent +cryostat.agent.app.jmx.host=localhost