mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
JMX printvar improvements
This commit is contained in:
parent
532c385497
commit
974ee6569d
@ -1,6 +1,7 @@
|
||||
package io.nosqlbench.driver.jmx;
|
||||
|
||||
import io.nosqlbench.driver.jmx.ops.JMXExplainOperation;
|
||||
import io.nosqlbench.driver.jmx.ops.JMXPrintOperation;
|
||||
import io.nosqlbench.driver.jmx.ops.JMXReadOperation;
|
||||
import io.nosqlbench.driver.jmx.ops.JmxOp;
|
||||
import io.nosqlbench.engine.api.templating.CommandTemplate;
|
||||
@ -42,9 +43,11 @@ public class ReadyJmxOp {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (cmdmap.containsKey("readvar")) {
|
||||
return new JMXReadOperation(connector, objectName, cmdmap.get("readvar"), cmdmap.get("as_type"),cmdmap.get("as_name"));
|
||||
} else if (cmdmap.containsKey("explain")) {
|
||||
if (cmdmap.containsKey(JMXReadOperation.READVAR)) {
|
||||
return new JMXReadOperation(connector, objectName, cmdmap.get(JMXReadOperation.READVAR), cmdmap);
|
||||
} else if (cmdmap.containsKey(JMXPrintOperation.PRINTVAR)) {
|
||||
return new JMXPrintOperation(connector,objectName, cmdmap.get(JMXPrintOperation.PRINTVAR), cmdmap);
|
||||
} else if (cmdmap.containsKey(JMXExplainOperation.EXPLAIN)) {
|
||||
return new JMXExplainOperation(connector,objectName);
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,8 @@ import javax.management.remote.JMXConnector;
|
||||
import java.io.IOException;
|
||||
|
||||
public class JMXExplainOperation extends JmxOp {
|
||||
public final static String EXPLAIN = "explain";
|
||||
|
||||
public JMXExplainOperation(JMXConnector connector, ObjectName objectName) {
|
||||
super(connector,objectName);
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
package io.nosqlbench.driver.jmx.ops;
|
||||
|
||||
import io.nosqlbench.driver.jmx.ValueConverter;
|
||||
import io.nosqlbench.virtdata.library.basics.core.threadstate.SharedState;
|
||||
|
||||
import javax.management.ObjectName;
|
||||
import javax.management.remote.JMXConnector;
|
||||
import java.util.Map;
|
||||
|
||||
public class JMXPrintOperation extends JMXReadOperation {
|
||||
public static final String PRINTVAR = "printvar";
|
||||
|
||||
public JMXPrintOperation(JMXConnector connector, ObjectName objectName, String attribute, Map<String, String> cfg) {
|
||||
super(connector, objectName, attribute, cfg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
Object value = readObject(attribute);
|
||||
System.out.println("# read JMX attribute '" + attribute + "' as " + value.getClass() +
|
||||
((asType != null) ? " as_type=" + asType : "") +
|
||||
((asName != null) ? " as_name=" + asName : ""));
|
||||
|
||||
if (asType != null) {
|
||||
value = ValueConverter.convert(asType, value);
|
||||
}
|
||||
String storedName = (asName == null) ? attribute : asName;
|
||||
|
||||
System.out.println(storedName + "=" + value + "\n");
|
||||
}
|
||||
|
||||
}
|
@ -8,35 +8,35 @@ import javax.management.*;
|
||||
import javax.management.remote.JMXConnector;
|
||||
import javax.management.remote.JMXServiceURL;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public class JMXReadOperation extends JmxOp {
|
||||
private final String attribute;
|
||||
private final String asType;
|
||||
private final String asName;
|
||||
public final static String READVAR = "readvar";
|
||||
public final static String AS_TYPE = "as_type";
|
||||
public final static String AS_NAME = "as_name";
|
||||
|
||||
public JMXReadOperation(JMXConnector connector, ObjectName objectName, String attribute, String asType, String asName) {
|
||||
protected final String attribute;
|
||||
protected final String asType;
|
||||
protected final String asName;
|
||||
|
||||
public JMXReadOperation(JMXConnector connector, ObjectName objectName, String attribute, Map<String, String> cfg) {
|
||||
super(connector, objectName);
|
||||
this.attribute = attribute;
|
||||
this.asType = asType;
|
||||
this.asName = asName;
|
||||
this.asType = cfg.remove(AS_TYPE);
|
||||
this.asName = cfg.remove(AS_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
try {
|
||||
Object value = getMBeanConnection().getAttribute(objectName, this.attribute);
|
||||
logger.trace("read attribute '" + value +"': " + value);
|
||||
Object value = readObject(attribute);
|
||||
|
||||
if (asType!=null) {
|
||||
value = ValueConverter.convert(asType,value);
|
||||
}
|
||||
|
||||
String storedName = (asName==null) ? attribute : asName;
|
||||
SharedState.tl_ObjectMap.get().put(storedName,value);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
if (asType != null) {
|
||||
value = ValueConverter.convert(asType, value);
|
||||
}
|
||||
String storedName = (asName == null) ? attribute : asName;
|
||||
|
||||
SharedState.tl_ObjectMap.get().put(storedName, value);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -32,5 +32,15 @@ public abstract class JmxOp {
|
||||
}
|
||||
}
|
||||
|
||||
protected Object readObject(String attributeName) {
|
||||
try {
|
||||
Object value = getMBeanConnection().getAttribute(objectName, attributeName);
|
||||
logger.trace("read attribute '" + value + "': " + value);
|
||||
return value;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void execute();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user