Are there any examples of using the JMX agent? There doesn't seem to be any inside the brooklyn project, so I guess the users are hidden in some AMP-specific entities? [...] I'm trying to enable JMX-based sensors for Websphere Liberty Profile
The way I usually configure entities when I want to be sure that JMX works the way I expect, I set the JMXRMI agent and ports explicitly. In a Java application class, I do it when building an EntitySpec
, setting the configuration in the init()
method. This is from a Cassandra cluster application I was using at Waratek:
@Override
public void init() {
addChild(EntitySpec.create(CassandraDatacenter.class)
.configure(CassandraDatacenter.CLUSTER_NAME, "Brooklyn")
.configure(CassandraDatacenter.INITIAL_SIZE, getConfig(CASSANDRA_CLUSTER_SIZE))
.configure(CassandraDatacenter.ENABLE_AVAILABILITY_ZONES, true)
.configure(DynamicCluster.ZONE_PLACEMENT_STRATEGY, new WaratekNodePlacementStrategy())
.configure(CassandraDatacenter.ENDPOINT_SNITCH_NAME, "GossipingPropertyFileSnitch")
.configure(CassandraDatacenter.MEMBER_SPEC, EntitySpec.create(CassandraNode.class)
.configure(UsesJmx.USE_JMX, Boolean.TRUE)
.configure(UsesJmx.JMX_AGENT_MODE, JmxAgentModes.JMX_RMI_CUSTOM_AGENT)
.configure(UsesJmx.JMX_PORT, PortRanges.fromString("30000+"))
.configure(UsesJmx.RMI_REGISTRY_PORT, PortRanges.fromString("40000+"))
.policy(PolicySpec.create(ServiceFailureDetector.class))
.policy(PolicySpec.create(ServiceRestarter.class)
.configure(ServiceRestarter.FAILURE_SENSOR_TO_MONITOR, ServiceFailureDetector.ENTITY_FAILED)))
.policy(PolicySpec.create(ServiceReplacer.class)
.configure(ServiceReplacer.FAILURE_SENSOR_TO_MONITOR, ServiceRestarter.ENTITY_RESTART_FAILED)));
}
The important parts are the USE_JMX
, JMX_AGENT_MODE
, JMX_PORT
and RMI_REGISTRY_PORT
ConfigKey
(all from the UsesJmx
interface) settings. We enable JMX; set the agent mode to use the JMXRMI custom agent explicitly; and then set the PortRange
for the JMX and RMI registry ports, which will be opened to allow external access. Note that if an entity uses JmxSupport#recommendJmxRmiCustomAgent()
then you don't need to worry about the agent defaults.
For YAML, the following file sets up TomcatServer
in a cluster, using the JMXRMI agent.
---
# Tomcat Cluster
name: "Tomcat Hello World"
location:
jclouds:aws-ec2:eu-wast-1:
hardwareId: m3.medium
services:
- serviceType: brooklyn.entity.webapp.ControlledDynamicWebAppCluster
name: "Tomcat Cluster"
brooklyn.config:
cluster.initial.size: 1
wars.root: https://s3-eu-west-1.amazonaws.com/cloudsoft-amp/hello-world-webapp.war
http.port: "8080+"
proxy.http.port: "8000+"
memberSpec:
$brooklyn:entitySpec:
type: brooklyn.entity.webapp.tomcat.TomcatServer
brooklyn.config:
version: "7.0.53"
jmx.enabled: true
jmx.agent.mode: "JMX_RMI_CUSTOM_AGENT"
jmx.direct.port: "30000+"
rmi.registry.port: "40000+"
...
Although there's no TypeCoercions
adapter registered for UsesJmx.JmxAgentModes
the generic Enum<?>
coercion works for this. Plus, pull request #1324 contains some updates to TypeCoercions
that tries lowerCamel, lower-hyphen and UpperCamel input for all enums.