-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WFLY-12165 Expose management metrics for HotRod caches
- Loading branch information
Showing
19 changed files
with
853 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
.../java/org/jboss/as/clustering/infinispan/subsystem/remote/RemoteCacheContainerMetric.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2019, Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. See the copyright.txt file in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
|
||
package org.jboss.as.clustering.infinispan.subsystem.remote; | ||
|
||
import java.util.function.ToIntFunction; | ||
|
||
import org.infinispan.client.hotrod.jmx.RemoteCacheManagerMXBean; | ||
import org.jboss.as.clustering.controller.Metric; | ||
import org.jboss.as.clustering.infinispan.subsystem.InfinispanModel; | ||
import org.jboss.as.controller.AttributeDefinition; | ||
import org.jboss.as.controller.ModelVersion; | ||
import org.jboss.as.controller.OperationFailedException; | ||
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; | ||
import org.jboss.as.controller.registry.AttributeAccess; | ||
import org.jboss.as.controller.transform.description.DiscardAttributeChecker; | ||
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder; | ||
import org.jboss.dmr.ModelNode; | ||
import org.jboss.dmr.ModelType; | ||
|
||
/** | ||
* @author Paul Ferraro | ||
*/ | ||
public enum RemoteCacheContainerMetric implements Metric<RemoteCacheManagerMXBean>, ToIntFunction<RemoteCacheManagerMXBean> { | ||
|
||
ACTIVE_CONNECTIONS("active-connections") { | ||
@Override | ||
public int applyAsInt(RemoteCacheManagerMXBean manager) { | ||
return manager.getActiveConnectionCount(); | ||
} | ||
}, | ||
CONNECTIONS("connections") { | ||
@Override | ||
public int applyAsInt(RemoteCacheManagerMXBean manager) { | ||
return manager.getConnectionCount(); | ||
} | ||
}, | ||
IDLE_CONNECTIONS("idle-connections") { | ||
@Override | ||
public int applyAsInt(RemoteCacheManagerMXBean manager) { | ||
return manager.getIdleConnectionCount(); | ||
} | ||
} | ||
; | ||
static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder builder) { | ||
if (InfinispanModel.VERSION_11_0_0.requiresTransformation(version)) { | ||
builder.getAttributeBuilder().setDiscard(DiscardAttributeChecker.ALWAYS, ACTIVE_CONNECTIONS.getName(), CONNECTIONS.getName(), IDLE_CONNECTIONS.getName()); | ||
} | ||
} | ||
|
||
private final AttributeDefinition definition; | ||
|
||
RemoteCacheContainerMetric(String name) { | ||
this.definition = new SimpleAttributeDefinitionBuilder(name, ModelType.INT) | ||
.setFlags(AttributeAccess.Flag.GAUGE_METRIC) | ||
.setStorageRuntime() | ||
.build(); | ||
} | ||
|
||
@Override | ||
public AttributeDefinition getDefinition() { | ||
return this.definition; | ||
} | ||
|
||
@Override | ||
public ModelNode execute(RemoteCacheManagerMXBean manager) throws OperationFailedException { | ||
return new ModelNode(this.applyAsInt(manager)); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...g/jboss/as/clustering/infinispan/subsystem/remote/RemoteCacheContainerMetricExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2019, Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. See the copyright.txt file in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
|
||
package org.jboss.as.clustering.infinispan.subsystem.remote; | ||
|
||
import org.infinispan.client.hotrod.jmx.RemoteCacheManagerMXBean; | ||
import org.jboss.as.clustering.controller.Metric; | ||
import org.jboss.as.clustering.controller.MetricExecutor; | ||
import org.jboss.as.controller.OperationContext; | ||
import org.jboss.as.controller.OperationFailedException; | ||
import org.jboss.as.controller.PathAddress; | ||
import org.jboss.dmr.ModelNode; | ||
import org.wildfly.clustering.infinispan.client.InfinispanClientRequirement; | ||
import org.wildfly.clustering.infinispan.client.RemoteCacheContainer; | ||
import org.wildfly.clustering.service.PassiveServiceSupplier; | ||
|
||
/** | ||
* @author Paul Ferraro | ||
*/ | ||
public class RemoteCacheContainerMetricExecutor implements MetricExecutor<RemoteCacheManagerMXBean> { | ||
|
||
@Override | ||
public ModelNode execute(OperationContext context, Metric<RemoteCacheManagerMXBean> metric) throws OperationFailedException { | ||
PathAddress address = context.getCurrentAddress(); | ||
String name = address.getLastElement().getValue(); | ||
|
||
RemoteCacheContainer container = new PassiveServiceSupplier<RemoteCacheContainer>(context.getServiceRegistry(true), InfinispanClientRequirement.REMOTE_CONTAINER.getServiceName(context, name)).get(); | ||
return (container != null) ? metric.execute(container) : null; | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
...va/org/jboss/as/clustering/infinispan/subsystem/remote/RemoteCacheContainerOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2019, Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. See the copyright.txt file in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
|
||
package org.jboss.as.clustering.infinispan.subsystem.remote; | ||
|
||
import org.infinispan.client.hotrod.jmx.RemoteCacheManagerMXBean; | ||
import org.jboss.as.clustering.controller.Operation; | ||
import org.jboss.as.clustering.infinispan.subsystem.InfinispanExtension; | ||
import org.jboss.as.clustering.infinispan.subsystem.InfinispanModel; | ||
import org.jboss.as.controller.AttributeDefinition; | ||
import org.jboss.as.controller.ExpressionResolver; | ||
import org.jboss.as.controller.ModelVersion; | ||
import org.jboss.as.controller.OperationDefinition; | ||
import org.jboss.as.controller.OperationFailedException; | ||
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; | ||
import org.jboss.as.controller.SimpleOperationDefinitionBuilder; | ||
import org.jboss.as.controller.descriptions.ModelDescriptionConstants; | ||
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder; | ||
import org.jboss.dmr.ModelNode; | ||
import org.jboss.dmr.ModelType; | ||
|
||
/** | ||
* @author Paul Ferraro | ||
*/ | ||
public enum RemoteCacheContainerOperation implements Operation<RemoteCacheManagerMXBean> { | ||
|
||
SWITCH_CLUSTER("switch-cluster", ModelType.BOOLEAN) { | ||
private final AttributeDefinition name = new SimpleAttributeDefinitionBuilder(ModelDescriptionConstants.NAME, ModelType.STRING) | ||
.setRequired(true) | ||
.build(); | ||
|
||
@Override | ||
public ModelNode execute(ExpressionResolver resolver, ModelNode operation, RemoteCacheManagerMXBean manager) throws OperationFailedException { | ||
String name = operation.get(this.name.getName()).asString(); | ||
return new ModelNode(manager.switchToCluster(name)); | ||
} | ||
|
||
@Override | ||
public AttributeDefinition[] getParameters() { | ||
return new AttributeDefinition[] { this.name }; | ||
} | ||
}, | ||
; | ||
static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder builder) { | ||
if (InfinispanModel.VERSION_11_0_0.requiresTransformation(version)) { | ||
builder.discardOperations(SWITCH_CLUSTER.getName()); | ||
} | ||
} | ||
|
||
private final OperationDefinition definition; | ||
|
||
RemoteCacheContainerOperation(String name, ModelType replyType) { | ||
this.definition = new SimpleOperationDefinitionBuilder(name, InfinispanExtension.SUBSYSTEM_RESOLVER.createChildResolver(RemoteCacheResourceDefinition.WILDCARD_PATH)) | ||
.setParameters(this.getParameters()) | ||
.setReplyType(replyType) | ||
.setRuntimeOnly() | ||
.build(); | ||
} | ||
|
||
@Override | ||
public OperationDefinition getDefinition() { | ||
return this.definition; | ||
} | ||
} |
Oops, something went wrong.