space metrics, heap metrics

This commit is contained in:
Jonathan Shook 2024-10-11 15:16:12 -05:00
parent ddd39d9237
commit 4fa93955c0
5 changed files with 63 additions and 37 deletions

View File

@ -131,7 +131,7 @@ public abstract class BaseDriverAdapter<R extends Op, S> extends NBBaseComponent
@Override
public final synchronized DriverSpaceCache<? extends S> getSpaceCache() {
if (spaceCache == null) {
spaceCache = new DriverSpaceCache<>(getSpaceInitializer(getConfiguration()));
spaceCache = new DriverSpaceCache<>(this, getSpaceInitializer(getConfiguration()));
}
return spaceCache;
}

View File

@ -16,6 +16,10 @@
package io.nosqlbench.adapters.api.activityimpl.uniform;
import io.nosqlbench.nb.api.components.core.NBBaseComponent;
import io.nosqlbench.nb.api.components.core.NBComponent;
import io.nosqlbench.nb.api.engine.metrics.instruments.MetricCategory;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@ -42,14 +46,21 @@ import java.util.function.Function;
* @param <S>
* The type which will represent the cache for a given type of adapter.
*/
public class DriverSpaceCache<S> {
public class DriverSpaceCache<S> extends NBBaseComponent {
private final ConcurrentHashMap<String, S> cache = new ConcurrentHashMap<>();
private final Function<String, S> newSpaceFunction;
public DriverSpaceCache(Function<String, S> newSpaceFunction) {
public DriverSpaceCache(NBComponent parent, Function<String, S> newSpaceFunction) {
super(parent);
this.newSpaceFunction = newSpaceFunction;
this.create().gauge(
"spaces",
() -> (double) this.getElements().size(),
MetricCategory.Internals,
"the number of spaces instantiated by this adapter instance"
);
}
public S get(String name) {

View File

@ -159,8 +159,9 @@ public class ConfigModel implements NBConfigModel {
@Override
public NBConfiguration matchConfig(Map<String, ?> sharedConfig) {
LinkedHashMap<String, Object> extracted = new LinkedHashMap<>();
Map<String, Param<?>> namedParams = getNamedParams();
for (String providedCfgField : sharedConfig.keySet()) {
if (getNamedParams().containsKey(providedCfgField)) {
if (namedParams.containsKey(providedCfgField)) {
extracted.put(providedCfgField, sharedConfig.get(providedCfgField));
}
}

View File

@ -317,8 +317,7 @@ public class NBCLI implements Function<String[], Integer>, NBLabeledElement {
.pathname(resourceToCat).first();
final Content<?> data = tocat.orElseThrow(
() -> new BasicError("Unable to find " + resourceToCat +
" in classpath to cat out"));
() -> new BasicError("Unable to find " + resourceToCat + " in classpath to cat out"));
System.out.println(data.get());
NBCLI.logger.info(() -> "Dumped internal resource '" + data.asPath() + "' to stdout");
@ -340,9 +339,7 @@ public class NBCLI implements Function<String[], Integer>, NBLabeledElement {
.pathname(resourceToCopy).first();
final Content<?> data = tocopy.orElseThrow(
() -> new BasicError(
"Unable to find " + resourceToCopy +
" in classpath to copy out")
() -> new BasicError("Unable to find " + resourceToCopy + " in classpath to copy out")
);
final Path writeTo = Path.of(data.asPath().getFileName().toString());
@ -381,7 +378,6 @@ public class NBCLI implements Function<String[], Integer>, NBLabeledElement {
String topic = options.wantsTopicalHelpFor();
Optional<? extends NBHelpTopic> infoFor = NBJavaCommandLoader.getInfoFor(topic);
// infoFor = infoFor.or(() -> MarkdownFinder.forHelpTopic(options.wantsTopicalHelpFor()));
infoFor.ifPresent(info -> {
System.out.print(info.getHelp());
@ -409,29 +405,6 @@ public class NBCLI implements Function<String[], Integer>, NBLabeledElement {
.build()
);
// if ((null != reportPromPushTo) || (null != reportGraphiteTo) || (null != options.wantsReportCsvTo())) {
// final MetricReporters reporters = MetricReporters.getInstance();
// reporters.addRegistry("workloads", ActivityMetrics.getMetricRegistry());
//
// if (null != reportPromPushTo)
// reporters.addPromPush(reportPromPushTo, options.wantsMetricsPrefix(), promPushConfig);
// if (null != reportGraphiteTo) reporters.addGraphite(reportGraphiteTo, options.wantsMetricsPrefix());
// if (null != options.wantsReportCsvTo())
// reporters.addCSVReporter(options.wantsReportCsvTo(), options.wantsMetricsPrefix());
// if (options.wantsLoggedMetrics()) {
// reporters.addLogger();
// }
// reporters.start(10, options.getReportInterval());
// }
//
// if (options.getConsoleLogLevel().isGreaterOrEqualTo(NBLogLevel.WARN)) {
// options.setWantsStackTraces(true);
// NBCLI.logger.debug(() -> "enabling stack traces since log level is " + options.getConsoleLogLevel());
// }
// client machine metrics; TODO: modify pollInterval
// intentionally not shown for warn-only
NBCLI.logger.info(() -> "console logging level is " + options.getConsoleLogLevel());
Map<String, String> props = Map.of(
@ -441,10 +414,6 @@ public class NBCLI implements Function<String[], Integer>, NBLabeledElement {
"prompush_cache", "prompush_cache.txt",
"heartbeat", String.valueOf(options.wantsHeartbeatIntervalMs())
);
/**
* At this point, the command stream from the CLI should be handed into the session, and the session should
* marshal and transform it for any scenario invocations directly.
*/
try (
NBSession session = new NBSession(

View File

@ -31,6 +31,10 @@ import io.nosqlbench.nb.api.labels.NBLabeledElement;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.lang.management.MemoryManagerMXBean;
import java.lang.management.MemoryPoolMXBean;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@ -45,6 +49,7 @@ import java.util.function.Function;
public class NBSession extends NBHeartbeatComponent implements Function<List<Cmd>, ExecutionResult>, NBTokenWords {
private final static Logger logger = LogManager.getLogger(NBSession.class);
// private final ClientSystemMetricChecker clientMetricChecker;
private MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
private final Map<String, NBBufferedContainer> containers = new ConcurrentHashMap<>();
@ -69,6 +74,46 @@ public class NBSession extends NBHeartbeatComponent implements Function<List<Cmd
new NBSessionSafetyMetrics(this);
// on-heap
create().gauge(
"on_heap_memory_used",
() -> (double) mbean.getHeapMemoryUsage().getUsed(),
MetricCategory.Internals,
"heap memory used for nb"
);
create().gauge(
"on_heap_memory_max",
() -> (double) mbean.getHeapMemoryUsage().getMax(),
MetricCategory.Internals,
"heap memory max for nb"
);
create().gauge(
"on_heap_memory_committed",
() -> (double) mbean.getHeapMemoryUsage().getCommitted(),
MetricCategory.Internals,
"heap memory committed for nb"
);
// off-heap
create().gauge(
"off_heap_memory_used",
() -> (double) mbean.getNonHeapMemoryUsage().getUsed(),
MetricCategory.Internals,
"off-heap memory used for nb"
);
create().gauge(
"off_heap_memory_max",
() -> (double) mbean.getNonHeapMemoryUsage().getMax(),
MetricCategory.Internals,
"off-heap memory max for nb"
);
create().gauge(
"off_heap_memory_committed",
() -> (double) mbean.getNonHeapMemoryUsage().getCommitted(),
MetricCategory.Internals,
"off-heap memory committed for nb"
);
create().gauge(
"session_time",
() -> (double) System.nanoTime(),