Skip to content

Commit

Permalink
Introduce the new local-jmx managed server - so you don't have to go …
Browse files Browse the repository at this point in the history
…over jolokia if you are monitoring the same VM as where the agent is installed
  • Loading branch information
jmazzitelli committed Nov 30, 2016
1 parent 667a368 commit bf116f2
Show file tree
Hide file tree
Showing 20 changed files with 892 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@
<param name="restart" type="bool" default-value="false" description="Should the server be restarted after shutdown?"/>
</operation-dmr>
<operation-dmr name="Suspend" internal-name="suspend">
<param name="timemout" type="int" description="Timeout in seconds to allow active connections to drain"/>
<param name="timeout" type="int" default-value="0" description="Timeout in seconds to allow active connections to drain"/>
</operation-dmr>
<operation-dmr name="Deploy" internal-name="deploy"/>
<operation-dmr name="Undeploy" internal-name="undeploy"/>
Expand Down Expand Up @@ -1060,7 +1060,7 @@
</resource-type-dmr>
</resource-type-set-dmr>

<!-- JMX metadata for monitoring Jolokia-enabled applications -->
<!-- JMX metadata for monitoring Jolokia-enabled or local JMX applications -->

<avail-set-jmx name="RuntimeAvailsJMX" enabled="true">
<avail-jmx name="VM Avail"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@
<param name="restart" type="bool" default-value="false" description="Should the server be restarted after shutdown?"/>
</operation-dmr>
<operation-dmr name="Suspend" internal-name="suspend" >
<param name="timeout" type="int" default-value="0" description="Timeout in seconds to allow active connections to drain"/>
<param name="timeout" type="int" default-value="0" description="Timeout in seconds to allow active connections to drain"/>
</operation-dmr>
<operation-dmr name="Deploy" internal-name="deploy"/>
<operation-dmr name="Undeploy" internal-name="undeploy"/>
Expand Down Expand Up @@ -990,6 +990,89 @@
</resource-type-dmr>
</resource-type-set-dmr>

<!-- JMX metadata for monitoring Jolokia-enabled or local JMX applications -->

<avail-set-jmx name="RuntimeAvailsJMX" enabled="true">
<avail-jmx name="VM Avail"
interval="30"
time-units="seconds"
attribute="StartTime"
up-regex="[0123456789]+" />
</avail-set-jmx>

<avail-set-jmx name="MemoryPoolAvailsJMX" enabled="true">
<avail-jmx name="Memory Pool Avail"
interval="30"
time-units="seconds"
attribute="Valid"
up-regex="[tT].*" />
</avail-set-jmx>

<metric-set-jmx name="RuntimeMetricsJMX" enabled="true">
<metric-jmx name="VM Uptime"
interval="30"
time-units="seconds"
metric-units="milliseconds"
attribute="Uptime" />
<metric-jmx name="Used Heap Memory"
interval="30"
time-units="seconds"
metric-units="bytes"
object-name="java.lang:type=Memory"
attribute="HeapMemoryUsage#used" />
<metric-jmx name="Aggregate GC Collection Time"
interval="30"
time-units="seconds"
metric-units="milliseconds"
object-name="java.lang:type=GarbageCollector,name=*"
attribute="CollectionTime" />
</metric-set-jmx>

<metric-set-jmx name="MemoryPoolMetricsJMX" enabled="true">
<metric-jmx name="Initial"
interval="2"
time-units="minutes"
metric-units="bytes"
attribute="Usage#init" />
<metric-jmx name="Used"
interval="1"
time-units="minutes"
metric-units="bytes"
attribute="Usage#used" />
<metric-jmx name="Committed"
interval="1"
time-units="minutes"
metric-units="bytes"
attribute="Usage#committed" />
<metric-jmx name="Max"
interval="2"
time-units="minutes"
metric-units="bytes"
attribute="Usage#max" />
</metric-set-jmx>

<resource-type-set-jmx name="MainJMX" enabled="true">
<resource-type-jmx name="Runtime MBean"
resource-name-template="JMX [%_ManagedServerName%][%type%]"
object-name="java.lang:type=Runtime"
metric-sets="RuntimeMetricsJMX"
avail-sets="RuntimeAvailsJMX" >
<resource-config-jmx name="OS Name" object-name="java.lang:type=OperatingSystem" attribute="Name" />
<resource-config-jmx name="Java VM Name" attribute="VmName" />
</resource-type-jmx>
</resource-type-set-jmx>

<resource-type-set-jmx name="MemoryPoolJMX" enabled="true">
<resource-type-jmx name="Memory Pool MBean"
parents="Runtime MBean"
resource-name-template="JMX [%_ManagedServerName%] %type% %name%"
object-name="java.lang:type=MemoryPool,name=*"
metric-sets="MemoryPoolMetricsJMX"
avail-sets="MemoryPoolAvailsJMX" >
<resource-config-jmx name="Type" attribute="Type" />
</resource-type-jmx>
</resource-type-set-jmx>

<managed-servers>
<remote-dmr name="Another Remote Server"
enabled="false"
Expand All @@ -1002,6 +1085,11 @@
<local-dmr name="Local"
enabled="true"
resource-type-sets="Standalone Environment,Deployment,Web Component,EJB,Datasource,XA Datasource,JDBC Driver,Transaction Manager,Messaging,Socket Binding Group,Clustering,Hawkular" />

<remote-jmx name="Remote JMX" enabled="false" resource-type-sets="MainJMX,MemoryPoolJMX" url="http://localhost:8080/jolokia-war"/>

<local-jmx name="Local JMX" enabled="false" resource-type-sets="MainJMX,MemoryPoolJMX" />

</managed-servers>

<platform enabled="true">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright 2015-2016 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hawkular.agent.monitor.extension;

import org.hawkular.agent.monitor.extension.MonitorServiceConfiguration.EndpointConfiguration;
import org.hawkular.agent.monitor.log.AgentLoggers;
import org.hawkular.agent.monitor.log.MsgLogger;
import org.hawkular.agent.monitor.protocol.EndpointService;
import org.hawkular.agent.monitor.protocol.ProtocolService;
import org.hawkular.agent.monitor.protocol.ProtocolServices;
import org.hawkular.agent.monitor.protocol.jmx.JMXNodeLocation;
import org.hawkular.agent.monitor.protocol.jmx.JMXSession;
import org.hawkular.agent.monitor.service.MonitorService;
import org.hawkular.agent.monitor.util.Util;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.dmr.ModelNode;

public class LocalJMXAdd extends MonitorServiceAddStepHandler {
private static final MsgLogger log = AgentLoggers.getLogger(LocalJMXAdd.class);

public static final LocalJMXAdd INSTANCE = new LocalJMXAdd();

private LocalJMXAdd() {
super(LocalJMXAttributes.ATTRIBUTES);
}

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
throws OperationFailedException {

if (context.isBooting()) {
return;
}

MonitorService monitorService = getMonitorService(context);
if (monitorService == null) {
return; // the agent wasn't enabled, nothing to do
}

MonitorServiceConfiguration config = Util.getMonitorServiceConfiguration(context);
String newEndpointName = context.getCurrentAddressValue();

// Register the feed under the tenant of the new managed server.
// If endpoint has a null tenant then there is nothing to do since it will just reuse the agent's tenant ID
EndpointConfiguration endpointConfig = config.getJmxConfiguration().getEndpoints().get(newEndpointName);
boolean isEnabled = endpointConfig.isEnabled();

String newTenantId = endpointConfig.getTenantId();
if (newTenantId != null) {
try {
monitorService.registerFeed(newTenantId, 0);
} catch (Exception e) {
isEnabled = false;
log.warnCannotRegisterFeedForNewManagedServer(newTenantId, newEndpointName, e.toString());
}
}

if (isEnabled) {
// create a new endpoint service
ProtocolServices newServices = monitorService.createProtocolServicesBuilder()
.jmxProtocolService(config.getJmxConfiguration()).build();
EndpointService<JMXNodeLocation, JMXSession> endpointService = newServices.getJmxProtocolService()
.getEndpointServices().get(newEndpointName);

// put the new endpoint service in the original protocol services container
ProtocolService<JMXNodeLocation, JMXSession> jmxService = monitorService.getProtocolServices()
.getJmxProtocolService();
jmxService.add(endpointService);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright 2015-2016 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hawkular.agent.monitor.extension;

import org.hawkular.agent.monitor.api.Avail;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.operations.validation.EnumValidator;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;

public interface LocalJMXAttributes {

SimpleAttributeDefinition ENABLED = new SimpleAttributeDefinitionBuilder("enabled",
ModelType.BOOLEAN)
.setAllowNull(true)
.setDefaultValue(new ModelNode(true))
.setAllowExpression(true)
.addFlag(AttributeAccess.Flag.RESTART_NONE)
.build();

SimpleAttributeDefinition MBEAN_SERVER_NAME = new SimpleAttributeDefinitionBuilder("mbean-server-name",
ModelType.STRING)
.setAllowNull(true)
.setAllowExpression(true)
.addFlag(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.build();

SimpleAttributeDefinition SET_AVAIL_ON_SHUTDOWN = new SimpleAttributeDefinitionBuilder("set-avail-on-shutdown",
ModelType.STRING)
.setAllowNull(true)
.setValidator(EnumValidator.create(Avail.class, true, true))
.setAllowExpression(true)
.addFlag(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.build();

SimpleAttributeDefinition RESOURCE_TYPE_SETS = new SimpleAttributeDefinitionBuilder("resource-type-sets",
ModelType.STRING)
.setAllowNull(true)
.setAllowExpression(true)
.addFlag(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.build();

SimpleAttributeDefinition TENANT_ID = new SimpleAttributeDefinitionBuilder("tenant-id",
ModelType.STRING)
.setAllowNull(true)
.setAllowExpression(true)
.addFlag(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.build();

SimpleAttributeDefinition METRIC_ID_TEMPLATE = new SimpleAttributeDefinitionBuilder("metric-id-template",
ModelType.STRING)
.setAllowNull(true)
.setAllowExpression(true)
.addFlag(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.build();

SimpleAttributeDefinition METRIC_TAGS = new SimpleAttributeDefinitionBuilder("metric-tags",
ModelType.STRING)
.setAllowNull(true)
.setAllowExpression(true)
.addFlag(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.build();

AttributeDefinition[] ATTRIBUTES = {
ENABLED,
MBEAN_SERVER_NAME,
SET_AVAIL_ON_SHUTDOWN,
RESOURCE_TYPE_SETS,
TENANT_ID,
METRIC_ID_TEMPLATE,
METRIC_TAGS
};
}

0 comments on commit bf116f2

Please sign in to comment.