Skip to content

Commit

Permalink
add more configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Aug 17, 2022
1 parent 1c69e50 commit e05406f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
35 changes: 28 additions & 7 deletions src/main/java/io/cryostat/agent/Registration.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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 =
Expand All @@ -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;
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/META-INF/microprofile-config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e05406f

Please sign in to comment.