add scope controls to jmx driver

This commit is contained in:
Jonathan Shook 2020-07-16 09:31:06 -05:00
parent c81c5187c2
commit 16e4309e7f
3 changed files with 35 additions and 7 deletions

View File

@ -2,28 +2,34 @@ package io.nosqlbench.driver.jmx.ops;
import io.nosqlbench.driver.jmx.ValueConverter;
import io.nosqlbench.virtdata.library.basics.core.threadstate.SharedState;
import org.apache.commons.math4.analysis.function.Exp;
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 {
public final static String READVAR = "readvar";
public final static String AS_TYPE = "as_type";
public final static String AS_NAME = "as_name";
public final static String SCOPE = "scope";
protected final String attribute;
protected final String asType;
protected final String asName;
protected final SharedState.Scope scope;
public JMXReadOperation(JMXConnector connector, ObjectName objectName, String attribute, Map<String, String> cfg) {
super(connector, objectName);
this.attribute = attribute;
this.asType = cfg.remove(AS_TYPE);
this.asName = cfg.remove(AS_NAME);
String scopeName = cfg.remove(SCOPE);
if (scopeName != null) {
scope = SharedState.Scope.valueOf(scopeName);
} else {
scope = SharedState.Scope.process;
}
}
@Override
@ -33,9 +39,17 @@ public class JMXReadOperation extends JmxOp {
if (asType != null) {
value = ValueConverter.convert(asType, value);
}
String storedName = (asName == null) ? attribute : asName;
SharedState.tl_ObjectMap.get().put(storedName, value);
switch (scope) {
case process:
SharedState.gl_ObjectMap.put(storedName, value);
break;
case thread:
SharedState.tl_ObjectMap.get().put(storedName, value);
break;
}
}

View File

@ -37,10 +37,14 @@ statements:
readvar: Value
as_type: int
as_name: pending_tasks
# process or thread, process is default
scope: process
```
The `as_type` and `as_name` are optional, and if provided will set the name and data type used in
the thread local variable map.
The `as_type` and `as_name`, and `scope` are optional, and if provided will set the name and
data type used in the thread local variable map, and whether the variable is stored in the
thread scope or the process (global) scope.
- *as_type* can be any of long, int, double, float, byte, short, or String. If the original type
is convertable to a number, then it will be converted to a number and then to the desired type. If it
@ -48,13 +52,18 @@ is not, it will be converted to String form first and then to the desired type.
contains dots, as in a fully-qualified class name, then direct class casting will be used if the
types are compatible.
- *as_name* will change the name used to store the value in the map.
- *scope* can be either `thread` or `process` and determines the scope of the varaible map
which is used to store the variable.
A combined format is available if you don't want to put every command property on a separate line.
In this format, the first entry in the command map is taken as the command name and a set of key=value
command arguments. It is semantically equivalent to the above example, only more compact.
```
statements:
- read1: readvar=Value as_type=int as_name=pending_tasks
- read1: readvar=Value as_type=int as_name=pending_tasks
url: service:jmx:rmi:///jndi/rmi://dsehost:7199/jmxrmi
object: org.apache.cassandra.metrics:type=Compaction,name=PendingTasks
```

View File

@ -8,6 +8,11 @@ import java.util.concurrent.ConcurrentHashMap;
*/
public class SharedState {
public enum Scope {
process,
thread
}
// A thread-local map of objects by name
public static ThreadLocal<HashMap<String,Object>> tl_ObjectMap = ThreadLocal.withInitial(HashMap::new);