mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
rehome all metrics construction patterns, remove ActivityMetrics
This commit is contained in:
@@ -22,7 +22,6 @@ import com.codahale.metrics.Timer;
|
||||
import io.nosqlbench.adapter.amqp.dispensers.AmqpBaseOpDispenser;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.labels.NBLabels;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -56,28 +55,17 @@ public class AmqpAdapterMetrics {
|
||||
|
||||
public void initS4JAdapterInstrumentation() {
|
||||
// Histogram metrics
|
||||
messageSizeHistogram =
|
||||
amqpBaseOpDispenser.create().histogram(
|
||||
"message_size", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
|
||||
messageSizeHistogram = amqpBaseOpDispenser.create().histogram("message_size");
|
||||
// Timer metrics
|
||||
bindTimer = amqpBaseOpDispenser.create().timer(
|
||||
"bind", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
executeTimer =
|
||||
amqpBaseOpDispenser.create().timer(
|
||||
"execute", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
|
||||
bindTimer = amqpBaseOpDispenser.create().timer("bind");
|
||||
executeTimer = amqpBaseOpDispenser.create().timer("execute");
|
||||
// End-to-end metrics
|
||||
// Latency
|
||||
e2eMsgProcLatencyHistogram =
|
||||
amqpBaseOpDispenser.create().histogram("e2e_msg_latency", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
e2eMsgProcLatencyHistogram = amqpBaseOpDispenser.create().histogram("e2e_msg_latency");
|
||||
// Error metrics
|
||||
msgErrOutOfSeqCounter =
|
||||
amqpBaseOpDispenser.create().counter("err_msg_oos");
|
||||
msgErrLossCounter =
|
||||
amqpBaseOpDispenser.create().counter("err_msg_loss");
|
||||
msgErrDuplicateCounter =
|
||||
amqpBaseOpDispenser.create().counter("err_msg_dup");
|
||||
msgErrOutOfSeqCounter = amqpBaseOpDispenser.create().counter("err_msg_oos");
|
||||
msgErrLossCounter = amqpBaseOpDispenser.create().counter("err_msg_loss");
|
||||
msgErrDuplicateCounter = amqpBaseOpDispenser.create().counter("err_msg_dup");
|
||||
}
|
||||
|
||||
public Timer getBindTimer() { return bindTimer; }
|
||||
|
||||
@@ -30,7 +30,7 @@ import io.nosqlbench.adapter.cqld4.optypes.Cqld4CqlOp;
|
||||
import io.nosqlbench.adapters.api.activityimpl.BaseOpDispenser;
|
||||
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter;
|
||||
import io.nosqlbench.adapters.api.templating.ParsedOp;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import io.nosqlbench.api.config.standard.ConfigModel;
|
||||
import io.nosqlbench.api.config.standard.NBConfigModel;
|
||||
import io.nosqlbench.api.config.standard.NBConfiguration;
|
||||
import io.nosqlbench.api.config.standard.Param;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.api.labels.NBLabels;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import io.nosqlbench.virtdata.api.bindings.VirtDataConversions;
|
||||
|
||||
@@ -19,7 +19,6 @@ package io.nosqlbench.adapter.http.core;
|
||||
import com.codahale.metrics.Histogram;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.labels.NBLabels;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
|
||||
public class HttpMetrics implements NBLabeledElement {
|
||||
|
||||
@@ -20,9 +20,9 @@ import com.codahale.metrics.Counter;
|
||||
import com.codahale.metrics.Histogram;
|
||||
import com.codahale.metrics.Timer;
|
||||
import io.nosqlbench.adapter.kafka.dispensers.KafkaBaseOpDispenser;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBMetricHistogram;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.labels.NBLabels;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -56,21 +56,20 @@ public class KafkaAdapterMetrics {
|
||||
|
||||
public void initS4JAdapterInstrumentation() {
|
||||
// Histogram metrics
|
||||
messageSizeHistogram = kafkaBaseOpDispenser.create().histogram(
|
||||
"message_size", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
messageSizeHistogram = kafkaBaseOpDispenser.create().histogram("message_size");
|
||||
|
||||
// Timer metrics
|
||||
bindTimer =
|
||||
this.kafkaBaseOpDispenser.create().timer(
|
||||
"bind", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
"bind");
|
||||
executeTimer =
|
||||
this.kafkaBaseOpDispenser.create().timer(
|
||||
"execute", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
"execute");
|
||||
|
||||
// End-to-end metrics
|
||||
// Latency
|
||||
e2eMsgProcLatencyHistogram =
|
||||
kafkaBaseOpDispenser.create().histogram("e2e_msg_latency", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
kafkaBaseOpDispenser.create().histogram("e2e_msg_latency");
|
||||
// Error metrics
|
||||
msgErrOutOfSeqCounter =
|
||||
kafkaBaseOpDispenser.create().counter("err_msg_oos");
|
||||
|
||||
@@ -17,11 +17,9 @@
|
||||
package io.nosqlbench.adapter.pulsar.util;
|
||||
|
||||
import com.codahale.metrics.Counter;
|
||||
import com.codahale.metrics.Gauge;
|
||||
import com.codahale.metrics.Histogram;
|
||||
import com.codahale.metrics.Timer;
|
||||
import io.nosqlbench.adapter.pulsar.dispensers.PulsarBaseOpDispenser;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.pulsar.client.api.Consumer;
|
||||
@@ -75,28 +73,15 @@ public class PulsarAdapterMetrics {
|
||||
pulsarBaseOpDispenser.create().counter("err_msg_dup");
|
||||
|
||||
// Histogram metrics
|
||||
messageSizeHistogram =
|
||||
pulsarBaseOpDispenser.create().histogram(
|
||||
"message_size", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
e2eMsgProcLatencyHistogram =
|
||||
pulsarBaseOpDispenser.create().histogram(
|
||||
"e2e_msg_latency", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
payloadRttHistogram =
|
||||
pulsarBaseOpDispenser.create().histogram(
|
||||
"payload_rtt", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
messageSizeHistogram = pulsarBaseOpDispenser.create().histogram("message_size");
|
||||
e2eMsgProcLatencyHistogram = pulsarBaseOpDispenser.create().histogram("e2e_msg_latency");
|
||||
payloadRttHistogram = pulsarBaseOpDispenser.create().histogram("payload_rtt");
|
||||
|
||||
// Timer metrics
|
||||
bindTimer =
|
||||
pulsarBaseOpDispenser.create().timer("bind", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
executeTimer =
|
||||
pulsarBaseOpDispenser.create().timer(
|
||||
"execute", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
createTransactionTimer =
|
||||
pulsarBaseOpDispenser.create().timer(
|
||||
"create_transaction", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
commitTransactionTimer =
|
||||
pulsarBaseOpDispenser.create().timer(
|
||||
"commit_transaction", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
bindTimer = pulsarBaseOpDispenser.create().timer("bind");
|
||||
executeTimer = pulsarBaseOpDispenser.create().timer("execute");
|
||||
createTransactionTimer = pulsarBaseOpDispenser.create().timer("create_transaction");
|
||||
commitTransactionTimer = pulsarBaseOpDispenser.create().timer("commit_transaction");
|
||||
}
|
||||
|
||||
public Counter getMsgErrOutOfSeqCounter() {
|
||||
|
||||
@@ -19,7 +19,6 @@ package io.nosqlbench.adapter.s4j.util;
|
||||
import com.codahale.metrics.Histogram;
|
||||
import com.codahale.metrics.Timer;
|
||||
import io.nosqlbench.adapter.s4j.dispensers.S4JBaseOpDispenser;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -39,17 +38,11 @@ public class S4JAdapterMetrics {
|
||||
|
||||
public void initS4JAdapterInstrumentation() {
|
||||
// Histogram metrics
|
||||
this.messageSizeHistogram =
|
||||
s4jBaseOpDispenser.create().histogram(
|
||||
"message_size", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
this.messageSizeHistogram = s4jBaseOpDispenser.create().histogram("message_size");
|
||||
|
||||
// Timer metrics
|
||||
this.bindTimer =
|
||||
s4jBaseOpDispenser.create().timer(
|
||||
"bind", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
this.executeTimer =
|
||||
s4jBaseOpDispenser.create().timer(
|
||||
"execute", ActivityMetrics.DEFAULT_HDRDIGITS);
|
||||
this.bindTimer = s4jBaseOpDispenser.create().timer("bind");
|
||||
this.executeTimer = s4jBaseOpDispenser.create().timer("execute");
|
||||
}
|
||||
|
||||
public Timer getBindTimer() { return bindTimer; }
|
||||
|
||||
@@ -25,7 +25,6 @@ import io.nosqlbench.adapters.api.metrics.ThreadLocalNamedTimers;
|
||||
import io.nosqlbench.adapters.api.templating.ParsedOp;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.labels.NBLabels;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.api.errors.OpConfigError;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
@@ -183,8 +182,8 @@ public abstract class BaseOpDispenser<T extends Op, S> extends NBBaseComponent i
|
||||
if (this.instrument) {
|
||||
final int hdrDigits = pop.getStaticConfigOr("hdr_digits", 4);
|
||||
|
||||
successTimer = create().timer(ActivityMetrics.sanitize("successfor_"+getOpName()),hdrDigits);
|
||||
errorTimer = create().timer(ActivityMetrics.sanitize("errorsfor_"+getOpName()),hdrDigits);
|
||||
successTimer = create().timer("successfor_"+getOpName(),hdrDigits);
|
||||
errorTimer = create().timer("errorsfor_"+getOpName(),hdrDigits);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ package io.nosqlbench.adapters.api.metrics;
|
||||
|
||||
import com.codahale.metrics.Timer;
|
||||
import com.codahale.metrics.Timer.Context;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.adapters.api.templating.ParsedOp;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBMetricTimer;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
@@ -18,7 +18,6 @@ package io.nosqlbench.engine.api.activityapi.ratelimits;
|
||||
|
||||
import com.codahale.metrics.Gauge;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.codahale.metrics.Timer;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.engine.api.util.Colors;
|
||||
import io.nosqlbench.api.engine.activityimpl.ActivityDef;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ package io.nosqlbench.engine.api.activityapi.ratelimits;
|
||||
|
||||
import com.codahale.metrics.Timer;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -33,7 +33,6 @@ import io.nosqlbench.adapters.api.activityimpl.OpMapper;
|
||||
import io.nosqlbench.api.labels.NBLabels;
|
||||
import io.nosqlbench.api.config.standard.NBConfiguration;
|
||||
import io.nosqlbench.api.engine.activityimpl.ActivityDef;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.api.errors.BasicError;
|
||||
import io.nosqlbench.api.errors.OpConfigError;
|
||||
import io.nosqlbench.engine.api.activityapi.cyclelog.filters.IntPredicateDispenser;
|
||||
|
||||
@@ -18,8 +18,6 @@ package io.nosqlbench.engine.api.activityimpl.input;
|
||||
import com.codahale.metrics.Gauge;
|
||||
import io.nosqlbench.api.engine.activityimpl.ActivityDef;
|
||||
import io.nosqlbench.api.engine.activityimpl.CyclesSpec;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBFunctionGauge;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.engine.api.activityapi.core.ActivityDefObserver;
|
||||
|
||||
@@ -30,8 +30,6 @@ import io.nosqlbench.api.Shutdownable;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.api.config.standard.*;
|
||||
import io.nosqlbench.api.engine.activityimpl.ActivityDef;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBFunctionGauge;
|
||||
import io.nosqlbench.api.errors.BasicError;
|
||||
import io.nosqlbench.api.errors.OpConfigError;
|
||||
import io.nosqlbench.api.labels.NBLabels;
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package io.nosqlbench.engine.api.metrics;
|
||||
|
||||
import com.codahale.metrics.Counter;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -19,7 +19,6 @@ package io.nosqlbench.engine.api.metrics;
|
||||
import com.codahale.metrics.Histogram;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.engine.activityimpl.ActivityDef;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
package io.nosqlbench.engine.api.metrics;
|
||||
|
||||
import com.codahale.metrics.Meter;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -17,9 +17,7 @@
|
||||
package io.nosqlbench.engine.api.metrics;
|
||||
|
||||
import com.codahale.metrics.Timer;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.engine.activityimpl.ActivityDef;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2023 nosqlbench
|
||||
*
|
||||
* 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 io.nosqlbench.engine.api.metrics;
|
||||
|
||||
import com.codahale.metrics.Metric;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class ActivityMetricsTest {
|
||||
|
||||
@Test
|
||||
public void testMountSubRegistry() throws Exception {
|
||||
MetricRegistry r1 = new MetricRegistry();
|
||||
r1.counter("counter1");
|
||||
|
||||
int extant = ActivityMetrics.getMetricRegistry().getMetrics().size();
|
||||
|
||||
ActivityMetrics.mountSubRegistry("aprefixhere_",r1);
|
||||
Map<String, Metric> metrics = ActivityMetrics.getMetricRegistry().getMetrics();
|
||||
assertThat(metrics).containsKey("aprefixhere_counter1");
|
||||
assertThat(metrics).hasSize(extant+1);
|
||||
|
||||
r1.counter("counter2");
|
||||
metrics = ActivityMetrics.getMetricRegistry().getMetrics();
|
||||
assertThat(metrics).hasSize(extant+2);
|
||||
assertThat(metrics).containsKey("aprefixhere_counter2");
|
||||
|
||||
r1.remove("counter1");
|
||||
metrics = ActivityMetrics.getMetricRegistry().getMetrics();
|
||||
assertThat(metrics).hasSize(extant+1);
|
||||
assertThat(metrics).containsKey("aprefixhere_counter2");
|
||||
|
||||
r1.remove("counter2");
|
||||
metrics = ActivityMetrics.getMetricRegistry().getMetrics();
|
||||
assertThat(metrics).hasSize(extant);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSanityCheckSanitize() {
|
||||
String result = ActivityMetrics.sanitize("test-dynamic-params.input_cycles_first");
|
||||
assertThat(result).isEqualTo("test_dynamic_params__input_cycles_first");
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,6 @@ import io.nosqlbench.engine.core.lifecycle.process.NBCLIErrorHandler;
|
||||
import io.nosqlbench.engine.core.lifecycle.session.NBSession;
|
||||
import io.nosqlbench.engine.core.logging.LoggerConfig;
|
||||
import io.nosqlbench.engine.core.metadata.MarkdownFinder;
|
||||
import io.nosqlbench.engine.core.metrics.MetricReporters;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import io.nosqlbench.nb.annotations.ServiceSelector;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -245,8 +244,9 @@ public class NBCLI implements Function<String[], Integer>, NBLabeledElement {
|
||||
|
||||
NBIO.addGlobalIncludes(options.wantsIncludes());
|
||||
|
||||
ActivityMetrics.setHdrDigits(options.getHdrDigits());
|
||||
ActivityMetrics.setLabelValidator(options.getAnnotateLabelSpec());
|
||||
// TODO: metrics
|
||||
// ActivityMetrics.setHdrDigits(options.getHdrDigits());
|
||||
// ActivityMetrics.setLabelValidator(options.getAnnotateLabelSpec());
|
||||
|
||||
if (options.wantsBasicHelp()) {
|
||||
System.out.println(this.loadHelpFile("basic.md"));
|
||||
@@ -368,46 +368,36 @@ 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.wantsEnableChart()) {
|
||||
NBCLI.logger.info("Charting enabled");
|
||||
if (0 == options.getHistoLoggerConfigs().size()) {
|
||||
NBCLI.logger.info("Adding default histologger configs");
|
||||
final String pattern = ".*";
|
||||
final String file = options.getChartHdrFileName();
|
||||
final String interval = "1s";
|
||||
options.setHistoLoggerConfigs(pattern, file, interval);
|
||||
}
|
||||
}
|
||||
|
||||
for (
|
||||
final LoggerConfigData histoLogger : options.getHistoLoggerConfigs())
|
||||
ActivityMetrics.addHistoLogger(sessionName, histoLogger.pattern, histoLogger.file, histoLogger.interval);
|
||||
for (
|
||||
final LoggerConfigData statsLogger : options.getStatsLoggerConfigs())
|
||||
ActivityMetrics.addStatsLogger(sessionName, statsLogger.pattern, statsLogger.file, statsLogger.interval);
|
||||
for (
|
||||
final LoggerConfigData classicConfigs : options.getClassicHistoConfigs())
|
||||
ActivityMetrics.addClassicHistos(sessionName, classicConfigs.pattern, classicConfigs.file, classicConfigs.interval);
|
||||
|
||||
if (options.getConsoleLogLevel().isGreaterOrEqualTo(NBLogLevel.WARN)) {
|
||||
options.setWantsStackTraces(true);
|
||||
NBCLI.logger.debug(() -> "enabling stack traces since log level is " + options.getConsoleLogLevel());
|
||||
}
|
||||
// TODO: metrics
|
||||
// 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());
|
||||
// }
|
||||
//
|
||||
// for (
|
||||
// final LoggerConfigData histoLogger : options.getHistoLoggerConfigs())
|
||||
// ActivityMetrics.addHistoLogger(sessionName, histoLogger.pattern, histoLogger.file, histoLogger.interval);
|
||||
// for (
|
||||
// final LoggerConfigData statsLogger : options.getStatsLoggerConfigs())
|
||||
// ActivityMetrics.addStatsLogger(sessionName, statsLogger.pattern, statsLogger.file, statsLogger.interval);
|
||||
// for (
|
||||
// final LoggerConfigData classicConfigs : options.getClassicHistoConfigs())
|
||||
// ActivityMetrics.addClassicHistos(sessionName, classicConfigs.pattern, classicConfigs.file, classicConfigs.interval);
|
||||
//
|
||||
// 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
|
||||
this.clientMetricChecker = new ClientSystemMetricChecker(10);
|
||||
|
||||
@@ -18,7 +18,6 @@ package io.nosqlbench.engine.core.lifecycle;
|
||||
|
||||
import com.codahale.metrics.*;
|
||||
import com.codahale.metrics.ConsoleReporter.Builder;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.api.engine.metrics.reporters.Log4JMetricsReporter;
|
||||
import io.nosqlbench.api.engine.metrics.reporters.Log4JMetricsReporter.LoggingLevel;
|
||||
import io.nosqlbench.engine.core.metrics.NBMetricsSummary;
|
||||
@@ -57,17 +56,18 @@ public class ExecutionMetricsResult extends ExecutionResult {
|
||||
public String getMetricsSummary() {
|
||||
final ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
try (final PrintStream ps = new PrintStream(os)) {
|
||||
final Builder builder = ConsoleReporter.forRegistry(ActivityMetrics.getMetricRegistry())
|
||||
.convertDurationsTo(TimeUnit.MICROSECONDS)
|
||||
.convertRatesTo(TimeUnit.SECONDS)
|
||||
.filter(MetricFilter.ALL)
|
||||
.outputTo(ps);
|
||||
final Set<MetricAttribute> disabled = new HashSet<>(ExecutionMetricsResult.INTERVAL_ONLY_METRICS);
|
||||
if (60000 > this.getElapsedMillis()) disabled.addAll(ExecutionMetricsResult.OVER_ONE_MINUTE_METRICS);
|
||||
builder.disabledMetricAttributes(disabled);
|
||||
final ConsoleReporter consoleReporter = builder.build();
|
||||
consoleReporter.report();
|
||||
consoleReporter.close();
|
||||
// TODO: metrics
|
||||
// final Builder builder = ConsoleReporter.forRegistry(ActivityMetrics.getMetricRegistry())
|
||||
// .convertDurationsTo(TimeUnit.MICROSECONDS)
|
||||
// .convertRatesTo(TimeUnit.SECONDS)
|
||||
// .filter(MetricFilter.ALL)
|
||||
// .outputTo(ps);
|
||||
// final Set<MetricAttribute> disabled = new HashSet<>(ExecutionMetricsResult.INTERVAL_ONLY_METRICS);
|
||||
// if (60000 > this.getElapsedMillis()) disabled.addAll(ExecutionMetricsResult.OVER_ONE_MINUTE_METRICS);
|
||||
// builder.disabledMetricAttributes(disabled);
|
||||
// final ConsoleReporter consoleReporter = builder.build();
|
||||
// consoleReporter.report();
|
||||
// consoleReporter.close();
|
||||
}
|
||||
final String result = os.toString(StandardCharsets.UTF_8);
|
||||
return result;
|
||||
@@ -88,31 +88,33 @@ public class ExecutionMetricsResult extends ExecutionResult {
|
||||
ExecutionResult.logger.debug("-- active data on this last report. (The workload has already stopped.) Record --");
|
||||
ExecutionResult.logger.debug("-- metrics to an external format to see values for each reporting interval. --");
|
||||
ExecutionResult.logger.debug("-- BEGIN METRICS DETAIL --");
|
||||
final Log4JMetricsReporter reporter = Log4JMetricsReporter.forRegistry(ActivityMetrics.getMetricRegistry())
|
||||
.withLoggingLevel(LoggingLevel.DEBUG)
|
||||
.convertDurationsTo(TimeUnit.MICROSECONDS)
|
||||
.convertRatesTo(TimeUnit.SECONDS)
|
||||
.filter(MetricFilter.ALL)
|
||||
.outputTo(ExecutionResult.logger)
|
||||
.build();
|
||||
reporter.report();
|
||||
reporter.close();
|
||||
// TODO: metrics
|
||||
// final Log4JMetricsReporter reporter = Log4JMetricsReporter.forRegistry(ActivityMetrics.getMetricRegistry())
|
||||
// .withLoggingLevel(LoggingLevel.DEBUG)
|
||||
// .convertDurationsTo(TimeUnit.MICROSECONDS)
|
||||
// .convertRatesTo(TimeUnit.SECONDS)
|
||||
// .filter(MetricFilter.ALL)
|
||||
// .outputTo(ExecutionResult.logger)
|
||||
// .build();
|
||||
// reporter.report();
|
||||
// reporter.close();
|
||||
ExecutionResult.logger.debug("-- END METRICS DETAIL --");
|
||||
}
|
||||
|
||||
public void reportMetricsCountsTo(final PrintStream printStream) {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
|
||||
ActivityMetrics.getMetricRegistry().getMetrics().forEach((k, v) -> {
|
||||
if (v instanceof Counting counting) {
|
||||
final long count = counting.getCount();
|
||||
if (0 < count) NBMetricsSummary.summarize(sb, k, v);
|
||||
} else if (v instanceof Gauge<?> gauge) {
|
||||
final Object value = gauge.getValue();
|
||||
if (value instanceof Number n) if (0 != n.doubleValue()) NBMetricsSummary.summarize(sb, k, v);
|
||||
}
|
||||
});
|
||||
|
||||
// TODO: metrics
|
||||
// ActivityMetrics.getMetricRegistry().getMetrics().forEach((k, v) -> {
|
||||
// if (v instanceof Counting counting) {
|
||||
// final long count = counting.getCount();
|
||||
// if (0 < count) NBMetricsSummary.summarize(sb, k, v);
|
||||
// } else if (v instanceof Gauge<?> gauge) {
|
||||
// final Object value = gauge.getValue();
|
||||
// if (value instanceof Number n) if (0 != n.doubleValue()) NBMetricsSummary.summarize(sb, k, v);
|
||||
// }
|
||||
// });
|
||||
//
|
||||
printStream.println("-- BEGIN NON-ZERO metric counts (run longer for full report):");
|
||||
printStream.print(sb);
|
||||
printStream.println("-- END NON-ZERO metric counts:");
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
package io.nosqlbench.engine.core.lifecycle.activity;
|
||||
|
||||
import com.codahale.metrics.Gauge;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBFunctionGauge;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.NBMetricGauge;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.labels.NBLabels;
|
||||
@@ -467,12 +465,15 @@ public class ActivityExecutor implements NBLabeledElement, ActivityController, P
|
||||
}
|
||||
|
||||
private void unregisterMetrics() {
|
||||
// TODO: metrics
|
||||
// ActivityMetrics.unregister(this.threadsGauge);
|
||||
if (this.threadsGauge != null) {
|
||||
ActivityMetrics.unregister(this.threadsGauge);
|
||||
this.threadsGauge = null;
|
||||
}
|
||||
ActivityMetrics.unregister(this.threadsGauge);
|
||||
|
||||
this.threadsGauge = null;
|
||||
}
|
||||
|
||||
|
||||
private boolean shutdownExecutorService(int secondsToWait) {
|
||||
|
||||
activitylogger.debug(() -> "Shutting down motor executor for (" + activity.getAlias() + ")");
|
||||
|
||||
@@ -18,7 +18,6 @@ package io.nosqlbench.engine.core.lifecycle.scenario.context;
|
||||
import io.nosqlbench.api.config.standard.TestComponent;
|
||||
import io.nosqlbench.api.engine.activityimpl.ActivityDef;
|
||||
import io.nosqlbench.api.engine.activityimpl.ParameterMap;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.components.NBBaseComponent;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.components.NBComponentErrorHandler;
|
||||
@@ -425,7 +424,8 @@ public class ActivitiesController extends NBBaseComponent {
|
||||
}
|
||||
|
||||
public void reportMetrics() {
|
||||
ActivityMetrics.reportTo(System.out);
|
||||
// TODO: metrics
|
||||
// ActivityMetrics.reportTo(System.out);
|
||||
}
|
||||
|
||||
public List<ProgressMeterDisplay> getProgressMeters() {
|
||||
|
||||
@@ -1,211 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2023 nosqlbench
|
||||
*
|
||||
* 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 io.nosqlbench.engine.core.metrics;
|
||||
|
||||
import com.codahale.metrics.*;
|
||||
import com.codahale.metrics.graphite.Graphite;
|
||||
import com.codahale.metrics.graphite.GraphiteReporter;
|
||||
import io.nosqlbench.api.engine.metrics.reporters.PromPushReporter;
|
||||
import io.nosqlbench.api.Shutdownable;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.engine.core.lifecycle.process.ShutdownManager;
|
||||
import io.nosqlbench.api.engine.metrics.reporters.Log4JMetricsReporter;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class MetricReporters implements Shutdownable {
|
||||
private static final Logger logger = LogManager.getLogger(MetricReporters.class);
|
||||
private static final MetricReporters instance = new MetricReporters();
|
||||
|
||||
private final List<PrefixedRegistry> metricRegistries = new ArrayList<>();
|
||||
private final List<ScheduledReporter> scheduledReporters = new ArrayList<>();
|
||||
|
||||
private MetricReporters() {
|
||||
ShutdownManager.register(this);
|
||||
}
|
||||
|
||||
public static MetricReporters getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public MetricReporters addRegistry(String registryPrefix, MetricRegistry metricsRegistry) {
|
||||
this.metricRegistries.add(new PrefixedRegistry(registryPrefix, metricsRegistry));
|
||||
return this;
|
||||
}
|
||||
|
||||
public MetricReporters addGraphite(String dest, String prefix) {
|
||||
logger.debug(() -> "Adding graphite reporter to " + dest + " with prefix " + prefix);
|
||||
if (0 <= dest.indexOf(':')) {
|
||||
String[] split = dest.split(":");
|
||||
addGraphite(split[0],Integer.valueOf(split[1]),prefix);
|
||||
} else {
|
||||
addGraphite(dest, 2003, prefix);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public void addCSVReporter(String directoryName, String prefix) {
|
||||
logger.debug(() -> "Adding CSV reporter to " + directoryName + " with prefix " + prefix);
|
||||
|
||||
if (metricRegistries.isEmpty()) {
|
||||
throw new RuntimeException("There are no metric registries.");
|
||||
}
|
||||
|
||||
File csvDirectory = new File(directoryName);
|
||||
if (!csvDirectory.exists()) {
|
||||
if (!csvDirectory.mkdirs()) {
|
||||
throw new RuntimeException("Error creating CSV reporting directory:" + csvDirectory.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
for (PrefixedRegistry prefixedRegistry : metricRegistries) {
|
||||
CsvReporter csvReporter = CsvReporter.forRegistry(prefixedRegistry.metricRegistry)
|
||||
.convertDurationsTo(TimeUnit.NANOSECONDS)
|
||||
.convertRatesTo(TimeUnit.SECONDS)
|
||||
.filter(ActivityMetrics.METRIC_FILTER)
|
||||
.formatFor(Locale.US)
|
||||
.build(csvDirectory);
|
||||
|
||||
scheduledReporters.add(csvReporter);
|
||||
}
|
||||
}
|
||||
|
||||
public MetricReporters addGraphite(String host, int graphitePort, String globalPrefix) {
|
||||
|
||||
logger.debug(() -> "Adding graphite reporter to " + host + " with port " + graphitePort + " and prefix " + globalPrefix);
|
||||
|
||||
if (metricRegistries.isEmpty()) {
|
||||
throw new RuntimeException("There are no metric registries.");
|
||||
}
|
||||
|
||||
for (PrefixedRegistry prefixedRegistry : metricRegistries) {
|
||||
|
||||
Graphite graphite = new Graphite(new InetSocketAddress(host, graphitePort));
|
||||
String _prefix = null != prefixedRegistry.prefix ? !prefixedRegistry.prefix.isEmpty() ? globalPrefix + '.' + prefixedRegistry.prefix : globalPrefix : globalPrefix;
|
||||
GraphiteReporter graphiteReporter = GraphiteReporter.forRegistry(prefixedRegistry.metricRegistry)
|
||||
.prefixedWith(_prefix)
|
||||
.convertRatesTo(TimeUnit.SECONDS)
|
||||
.convertDurationsTo(TimeUnit.NANOSECONDS)
|
||||
.filter(ActivityMetrics.METRIC_FILTER)
|
||||
.build(graphite);
|
||||
|
||||
scheduledReporters.add(graphiteReporter);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public MetricReporters addPromPush(final String reportPromPushTo, final String prefix, final String config) {
|
||||
|
||||
logger.debug(() -> "Adding prompush reporter to " + reportPromPushTo + " with prefix label to " + prefix);
|
||||
|
||||
if (metricRegistries.isEmpty()) {
|
||||
throw new RuntimeException("There are no metric registries.");
|
||||
}
|
||||
|
||||
for (PrefixedRegistry prefixedRegistry : metricRegistries) {
|
||||
final PromPushReporter promPushReporter =
|
||||
new PromPushReporter(
|
||||
reportPromPushTo,
|
||||
prefixedRegistry.metricRegistry,
|
||||
"prompush",
|
||||
MetricFilter.ALL,
|
||||
TimeUnit.SECONDS,
|
||||
TimeUnit.NANOSECONDS,
|
||||
config
|
||||
);
|
||||
scheduledReporters.add(promPushReporter);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public MetricReporters addLogger() {
|
||||
logger.debug("Adding log4j reporter for metrics");
|
||||
|
||||
if (metricRegistries.isEmpty()) {
|
||||
throw new RuntimeException("There are no metric registries.");
|
||||
}
|
||||
|
||||
for (PrefixedRegistry prefixedRegistry : metricRegistries) {
|
||||
|
||||
Log4JMetricsReporter reporter4j = Log4JMetricsReporter.forRegistry(prefixedRegistry.metricRegistry)
|
||||
.convertRatesTo(TimeUnit.SECONDS)
|
||||
.convertDurationsTo(TimeUnit.NANOSECONDS)
|
||||
.filter(ActivityMetrics.METRIC_FILTER)
|
||||
.outputTo(logger)
|
||||
.build();
|
||||
|
||||
scheduledReporters.add(reporter4j);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public MetricReporters start(int consoleIntervalSeconds, int remoteIntervalSeconds) {
|
||||
for (ScheduledReporter scheduledReporter : scheduledReporters) {
|
||||
logger.info(() -> "starting reporter: " + scheduledReporter.getClass().getSimpleName());
|
||||
if (scheduledReporter instanceof ConsoleReporter) {
|
||||
scheduledReporter.start(consoleIntervalSeconds, TimeUnit.SECONDS);
|
||||
} else {
|
||||
scheduledReporter.start(remoteIntervalSeconds, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public MetricReporters stop() {
|
||||
for (ScheduledReporter scheduledReporter : scheduledReporters) {
|
||||
logger.info(() -> "stopping reporter: " + scheduledReporter);
|
||||
scheduledReporter.stop();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public MetricReporters report() {
|
||||
for (ScheduledReporter scheduledReporter : scheduledReporters) {
|
||||
logger.info(() -> "flushing reporter data: " + scheduledReporter);
|
||||
scheduledReporter.report();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
for (ScheduledReporter reporter : scheduledReporters) {
|
||||
reporter.report();
|
||||
reporter.stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class PrefixedRegistry {
|
||||
public String prefix;
|
||||
public MetricRegistry metricRegistry;
|
||||
|
||||
public PrefixedRegistry(String prefix, MetricRegistry metricRegistry) {
|
||||
this.prefix = prefix;
|
||||
this.metricRegistry = metricRegistry;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 nosqlbench
|
||||
*
|
||||
* 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 io.nosqlbench.engine.core.metrics;
|
||||
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import io.nosqlbench.api.engine.activityapi.core.MetricRegistryService;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
|
||||
@Service(value = MetricRegistryService.class, selector = "metrics-context")
|
||||
public class MetricsContext implements MetricRegistryService {
|
||||
|
||||
private static MetricsContext instance;
|
||||
|
||||
private final MetricReporters metricReporters = MetricReporters.getInstance();
|
||||
private final MetricRegistry metrics = new NBMetricsRegistry();
|
||||
|
||||
public static MetricsContext getInstance() {
|
||||
synchronized (MetricsContext.class) {
|
||||
if (instance == null) {
|
||||
instance = new MetricsContext();
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public MetricReporters getReporters() {
|
||||
return metricReporters;
|
||||
}
|
||||
|
||||
public MetricRegistry getMetrics() {
|
||||
return metrics;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to unclutter code. This will be used everywhere.
|
||||
* @return The default metric context.
|
||||
*/
|
||||
public static MetricRegistry metrics() {
|
||||
return getInstance().getMetrics();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetricRegistry getMetricRegistry() {
|
||||
return getMetrics();
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,6 @@
|
||||
package io.nosqlbench.engine.extensions.histologger;
|
||||
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.script.ScriptContext;
|
||||
@@ -34,6 +33,7 @@ public class HdrHistoLogPlugin {
|
||||
}
|
||||
|
||||
public void logHistoIntervals(String session, String pattern, String filename, String interval) {
|
||||
ActivityMetrics.addHistoLogger(session, pattern, filename, interval);
|
||||
// TODO: metrics
|
||||
// ActivityMetrics.addHistoLogger(session, pattern, filename, interval);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package io.nosqlbench.engine.extensions.histostatslogger;
|
||||
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.script.ScriptContext;
|
||||
@@ -35,6 +34,7 @@ public class HistoStatsPlugin {
|
||||
}
|
||||
|
||||
public void logHistoStats(String sessionComment, String pattern, String filename , String interval) {
|
||||
ActivityMetrics.addStatsLogger(sessionComment, pattern, filename, interval);
|
||||
throw new RuntimeException("replace me after merge");
|
||||
// ActivityMetrics.addStatsLogger(sessionComment, pattern, filename, interval);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package io.nosqlbench.engine.extensions.scriptingmetrics;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import io.nosqlbench.api.config.LabeledScenarioContext;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.api.engine.metrics.DoubleSummaryGauge;
|
||||
import io.nosqlbench.api.engine.metrics.wrappers.RelevancyMeasures;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -1,319 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2023 nosqlbench
|
||||
*
|
||||
* 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 io.nosqlbench.api.engine.metrics;
|
||||
|
||||
import com.codahale.metrics.*;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.labels.NBLabels;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import io.nosqlbench.components.NBNamedElement;
|
||||
import io.nosqlbench.api.labels.NBLabelsFilter;
|
||||
import io.nosqlbench.api.engine.activityapi.core.MetricRegistryService;
|
||||
import io.nosqlbench.api.engine.metrics.instruments.*;
|
||||
import io.nosqlbench.api.engine.util.Unit;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.DoubleSummaryStatistics;
|
||||
import java.util.List;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.prefs.BackingStoreException;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ActivityMetrics {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(ActivityMetrics.class);
|
||||
|
||||
public static final String HDRDIGITS_PARAM = "hdr_digits";
|
||||
public static final int DEFAULT_HDRDIGITS = 4;
|
||||
private static int _HDRDIGITS = DEFAULT_HDRDIGITS;
|
||||
|
||||
private static MetricRegistry registry;
|
||||
|
||||
public static MetricFilter METRIC_FILTER = (name, metric) -> {
|
||||
return true;
|
||||
};
|
||||
private static final List<MetricsCloseable> metricsCloseables = new ArrayList<>();
|
||||
private static NBLabelsFilter labelValidator;
|
||||
private static NBLabelsFilter labelFilter;
|
||||
|
||||
|
||||
public static int getHdrDigits() {
|
||||
return _HDRDIGITS;
|
||||
}
|
||||
|
||||
public static void setHdrDigits(int hdrDigits) {
|
||||
ActivityMetrics._HDRDIGITS = hdrDigits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a named metric for an activity, synchronized on the activity
|
||||
*
|
||||
* @param named
|
||||
* The activity def that the metric will be for
|
||||
* @param metricFamilyName
|
||||
* The full metric name
|
||||
* @param metricProvider
|
||||
* A function to actually create the metric if needed
|
||||
* @return a Metric, or null if the metric for the name was already present
|
||||
*/
|
||||
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
|
||||
private static Metric register(NBLabels labels, MetricProvider metricProvider) {
|
||||
|
||||
labels = labelFilter != null ? labelFilter.apply(labels) : labels;
|
||||
labels = labelValidator != null ? labelValidator.apply(labels) : labels;
|
||||
|
||||
final String graphiteName = labels.linearizeValues('.', "[activity]", "[space]", "[op]", "name");
|
||||
Metric metric = get().getMetrics().get(graphiteName);
|
||||
|
||||
if (null == metric) {
|
||||
synchronized (labels) {
|
||||
metric = get().getMetrics().get(graphiteName);
|
||||
if (null == metric) {
|
||||
metric = metricProvider.getMetric();
|
||||
Metric registered = get().register(graphiteName, metric);
|
||||
logger.debug(() -> "registered metric: " + graphiteName);
|
||||
return registered;
|
||||
}
|
||||
}
|
||||
}
|
||||
return metric;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls to this version of register must be done with a pre-built metric instrument.
|
||||
* This means that it is not suitable for lazily creating metric objects directly on
|
||||
* instances which are one of many. Instead, call this to register metrics at the start
|
||||
* of an owning element.
|
||||
*
|
||||
* This version of register expects that you have fully labeled a metric, including
|
||||
* addint the 'name' field, also known as the <em>metric family name</em> in some specifications.
|
||||
*
|
||||
* It is due to be replaced by a different registry format soon.
|
||||
*
|
||||
* @param labeledMetric
|
||||
* @return the metric instance
|
||||
*/
|
||||
public static <M extends NBLabeledMetric> M register(M labeledMetric) {
|
||||
NBLabels labels = labeledMetric.getLabels();
|
||||
labels = labelFilter != null ? labelFilter.apply(labels) : labels;
|
||||
labels = labelValidator != null ? labelValidator.apply(labels) : labels;
|
||||
|
||||
final String graphiteName = labels.linearizeValues('.', "[activity]", "[space]", "[op]", "name");
|
||||
// String sanitized = sanitize(graphiteName);
|
||||
// if (!graphiteName.equals(sanitized)) {
|
||||
// throw new RuntimeException("Attempted to register a metric which was not compatible with labeled metric forms. Submitted as '" + graphiteName + "', but should likely be '" + sanitized + "'");
|
||||
// }
|
||||
Metric metric = get().getMetrics().get(graphiteName);
|
||||
|
||||
metric = get().getMetrics().get(graphiteName);
|
||||
if (metric!=null) {
|
||||
logger.warn("Metric already registered for '" + graphiteName + "', probably logic error which could invalidate metric values.");
|
||||
} else {
|
||||
get().register(graphiteName, labeledMetric);
|
||||
}
|
||||
return labeledMetric;
|
||||
}
|
||||
|
||||
public static void unregister(NBLabeledElement element) {
|
||||
final String graphiteName = element.getLabels().linearizeValues('.', "[activity]", "[space]", "[op]", "name");
|
||||
if (!get().getMetrics().containsKey(graphiteName)) {
|
||||
logger.warn("Removing non-extant metric by name: '"+ graphiteName + "'");
|
||||
}
|
||||
get().remove(graphiteName);
|
||||
}
|
||||
|
||||
|
||||
private static MetricRegistry get() {
|
||||
if (null != ActivityMetrics.registry) {
|
||||
return registry;
|
||||
}
|
||||
synchronized (ActivityMetrics.class) {
|
||||
if (null == ActivityMetrics.registry) {
|
||||
registry = lookupRegistry();
|
||||
}
|
||||
}
|
||||
return registry;
|
||||
}
|
||||
|
||||
|
||||
private static MetricRegistry lookupRegistry() {
|
||||
ServiceLoader<MetricRegistryService> metricRegistryServices =
|
||||
ServiceLoader.load(MetricRegistryService.class);
|
||||
List<MetricRegistryService> mrss = new ArrayList<>();
|
||||
metricRegistryServices.iterator().forEachRemaining(mrss::add);
|
||||
|
||||
if (1 == mrss.size()) {
|
||||
return mrss.get(0).getMetricRegistry();
|
||||
}
|
||||
final String infoMsg = "Unable to load a dynamic MetricRegistry via ServiceLoader, using the default.";
|
||||
logger.info(infoMsg);
|
||||
return new MetricRegistry();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static MetricRegistry getMetricRegistry() {
|
||||
return get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a histogram interval logger to matching metrics in this JVM instance.
|
||||
*
|
||||
* @param sessionName
|
||||
* The name for the session to be annotated in the histogram log
|
||||
* @param pattern
|
||||
* A regular expression pattern to filter out metric names for logging
|
||||
* @param filename
|
||||
* A file to log the histogram data in
|
||||
* @param interval
|
||||
* How many seconds to wait between writing each interval histogram
|
||||
*/
|
||||
public static void addHistoLogger(String sessionName, String pattern, String filename, String interval) {
|
||||
if (filename.contains("_SESSION_")) {
|
||||
filename = filename.replace("_SESSION_", sessionName);
|
||||
}
|
||||
Pattern compiledPattern = Pattern.compile(pattern);
|
||||
File logfile = new File(filename);
|
||||
long intervalMillis = Unit.msFor(interval).orElseThrow(() -> new RuntimeException("Unable to parse interval spec:'" + interval + '\''));
|
||||
|
||||
HistoIntervalLogger histoIntervalLogger =
|
||||
new HistoIntervalLogger(sessionName, logfile, compiledPattern, intervalMillis);
|
||||
logger.debug(() -> "attaching " + histoIntervalLogger + " to the metrics registry.");
|
||||
get().addListener(histoIntervalLogger);
|
||||
metricsCloseables.add(histoIntervalLogger);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a histogram stats logger to matching metrics in this JVM instance.
|
||||
*
|
||||
* @param sessionName
|
||||
* The name for the session to be annotated in the histogram log
|
||||
* @param pattern
|
||||
* A regular expression pattern to filter out metric names for logging
|
||||
* @param filename
|
||||
* A file to log the histogram data in
|
||||
* @param interval
|
||||
* How many seconds to wait between writing each interval histogram
|
||||
*/
|
||||
public static void addStatsLogger(String sessionName, String pattern, String filename, String interval) {
|
||||
if (filename.contains("_SESSION_")) {
|
||||
filename = filename.replace("_SESSION_", sessionName);
|
||||
}
|
||||
Pattern compiledPattern = Pattern.compile(pattern);
|
||||
File logfile = new File(filename);
|
||||
long intervalMillis = Unit.msFor(interval).orElseThrow(() -> new RuntimeException("Unable to parse interval spec:" + interval + '\''));
|
||||
|
||||
HistoStatsLogger histoStatsLogger =
|
||||
new HistoStatsLogger(sessionName, logfile, compiledPattern, intervalMillis, TimeUnit.NANOSECONDS);
|
||||
logger.debug(() -> "attaching " + histoStatsLogger + " to the metrics registry.");
|
||||
get().addListener(histoStatsLogger);
|
||||
metricsCloseables.add(histoStatsLogger);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a classic histogram in addition to the default implementation in this runtime. This is a way to
|
||||
* get a view to both the enhanced histogram implementation as well as the classic implementation in the
|
||||
* same scenario.
|
||||
*
|
||||
* @param sessionName
|
||||
* The name of the session to be annotated in the classic histogram
|
||||
* @param pattern
|
||||
* A regular expression pattern to filter out metric names for inclusion
|
||||
* @param prefix
|
||||
* The name prefix to add to the classic histograms so that they fit into the existing metrics namespace
|
||||
* @param interval
|
||||
* How frequently to update the histogram
|
||||
*/
|
||||
public static void addClassicHistos(String sessionName, String pattern, String prefix, String interval) {
|
||||
Pattern compiledPattern = Pattern.compile(pattern);
|
||||
long intervalMillis = Unit.msFor(interval).orElseThrow(() -> new RuntimeException("Unable to parse interval spec:" + interval + '\''));
|
||||
|
||||
ClassicHistoListener classicHistoListener =
|
||||
new ClassicHistoListener(get(), sessionName, prefix, compiledPattern, interval, TimeUnit.NANOSECONDS);
|
||||
logger.debug(() -> "attaching histo listener " + classicHistoListener + " to the metrics registry.");
|
||||
get().addListener(classicHistoListener);
|
||||
|
||||
ClassicTimerListener classicTimerListener =
|
||||
new ClassicTimerListener(get(), sessionName, prefix, compiledPattern, interval, TimeUnit.NANOSECONDS);
|
||||
logger.debug(() -> "attaching timer listener " + classicTimerListener + " to the metrics registry.");
|
||||
get().addListener(classicTimerListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* This should be called at the end of a process, so that open intervals can be finished, logs closed properly,
|
||||
* etc.
|
||||
*
|
||||
* @param showChart
|
||||
* whether to chart metrics on console
|
||||
*/
|
||||
public static void closeMetrics() {
|
||||
logger.trace("Closing all registered metrics closable objects.");
|
||||
for (MetricsCloseable metricsCloseable : metricsCloseables) {
|
||||
logger.trace(() -> "closing metrics closeable: " + metricsCloseable);
|
||||
metricsCloseable.closeMetrics();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setLabelValidator(String annotateLabelSpec) {
|
||||
labelValidator = new NBLabelsFilter(annotateLabelSpec);
|
||||
labelFilter = new NBLabelsFilter(annotateLabelSpec);
|
||||
}
|
||||
|
||||
private interface MetricProvider {
|
||||
Metric getMetric();
|
||||
}
|
||||
|
||||
public static void reportTo(PrintStream out) {
|
||||
out.println("==================== BEGIN-METRIC-LOG ====================");
|
||||
ConsoleReporter consoleReporter = ConsoleReporter.forRegistry(ActivityMetrics.getMetricRegistry())
|
||||
.convertDurationsTo(TimeUnit.MICROSECONDS)
|
||||
.convertRatesTo(TimeUnit.SECONDS)
|
||||
.filter(MetricFilter.ALL)
|
||||
.outputTo(out)
|
||||
.build();
|
||||
consoleReporter.report();
|
||||
out.println("==================== END-METRIC-LOG ====================");
|
||||
}
|
||||
|
||||
public static void mountSubRegistry(String mountPrefix, MetricRegistry subRegistry) {
|
||||
new MetricsRegistryMount(getMetricRegistry(), subRegistry, mountPrefix);
|
||||
}
|
||||
|
||||
public static void removeActivityMetrics(NBNamedElement named) {
|
||||
get().getMetrics().keySet().stream().filter(s -> s.startsWith(named.getName() + '.'))
|
||||
.forEach(get()::remove);
|
||||
}
|
||||
|
||||
|
||||
public static String sanitize(String word) {
|
||||
String sanitized = word;
|
||||
sanitized = sanitized.replaceAll("\\.", "__");
|
||||
sanitized = sanitized.replaceAll("-", "_");
|
||||
sanitized = sanitized.replaceAll("[^a-zA-Z0-9_]+", "");
|
||||
|
||||
if (!word.equals(sanitized)) {
|
||||
logger.warn("The identifier or value '" + word + "' was sanitized to '" + sanitized + "' to be compatible with monitoring systems. You should probably change this to make diagnostics easier.");
|
||||
}
|
||||
return sanitized;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,7 +18,6 @@ package io.nosqlbench.api.engine.metrics.wrappers;
|
||||
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.labels.NBLabels;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.api.engine.metrics.DoubleSummaryGauge;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package io.nosqlbench.api.labels;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
@@ -23,9 +25,11 @@ import java.util.function.Function;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class MapLabels implements NBLabels {
|
||||
|
||||
private final static Logger logger = LogManager.getLogger(MapLabels.class);
|
||||
private final Map<String,String> labels;
|
||||
|
||||
public MapLabels(final Map<String, String> labels, String... instanceFields) {
|
||||
public MapLabels(final Map<String, String> labels) {
|
||||
verifyValidNamesAndValues(labels);
|
||||
// verifyValidValues(labels);
|
||||
this.labels = Collections.unmodifiableMap(labels);
|
||||
@@ -137,6 +141,19 @@ public class MapLabels implements NBLabels {
|
||||
|
||||
}
|
||||
|
||||
public static String sanitize(String word) {
|
||||
String sanitized = word;
|
||||
sanitized = sanitized.replaceAll("\\.", "__");
|
||||
sanitized = sanitized.replaceAll("-", "_");
|
||||
sanitized = sanitized.replaceAll("[^a-zA-Z0-9_]+", "");
|
||||
|
||||
if (!word.equals(sanitized)) {
|
||||
logger.warn("The identifier or value '" + word + "' was sanitized to '" + sanitized + "' to be compatible with monitoring systems. You should probably change this to make diagnostics easier.");
|
||||
}
|
||||
return sanitized;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MapLabels and(final Object... labelsAndValues) {
|
||||
final Map<String,String> childLabels = getStringStringMap(labelsAndValues);
|
||||
|
||||
@@ -176,4 +176,5 @@ public interface NBLabels {
|
||||
* @return a String
|
||||
*/
|
||||
String linearizeAsMetrics();
|
||||
|
||||
}
|
||||
|
||||
@@ -40,6 +40,9 @@ public class NBBuilders {
|
||||
this.base = base;
|
||||
}
|
||||
|
||||
public NBMetricTimer timer(String metricFamilyName) {
|
||||
return timer(metricFamilyName,4);
|
||||
}
|
||||
public NBMetricTimer timer(String metricFamilyName, int hdrdigits) {
|
||||
NBLabels labels = base.getLabels().and("name", metricFamilyName);
|
||||
NBMetricTimer timer = new NBMetricTimer(labels, new DeltaHdrHistogramReservoir(labels, hdrdigits));
|
||||
@@ -81,6 +84,9 @@ public class NBBuilders {
|
||||
return anyGauge;
|
||||
}
|
||||
|
||||
public NBMetricHistogram histogram(String metricFamilyName) {
|
||||
return histogram(metricFamilyName,4);
|
||||
}
|
||||
public NBMetricHistogram histogram(String metricFamilyName, int hdrdigits) {
|
||||
NBLabels labels = base.getLabels().and("name", metricFamilyName);
|
||||
NBMetricHistogram histogram = new NBMetricHistogram(labels, new DeltaHdrHistogramReservoir(labels, hdrdigits));
|
||||
|
||||
@@ -18,8 +18,6 @@ package io.nosqlbench.engine.core.script;
|
||||
|
||||
import com.codahale.metrics.Histogram;
|
||||
import io.nosqlbench.api.config.standard.TestComponent;
|
||||
import io.nosqlbench.api.labels.NBLabeledElement;
|
||||
import io.nosqlbench.api.engine.metrics.ActivityMetrics;
|
||||
import io.nosqlbench.components.NBComponent;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -33,7 +31,8 @@ public class MetricsIntegrationTest {
|
||||
public void testHistogramLogger() {
|
||||
NBComponent parent = new TestComponent("metricstest","metricstest","alias","foo","driver","diag","op","noop");
|
||||
final Histogram testhistogram = parent.create().histogram("testhistogram", 3);
|
||||
ActivityMetrics.addHistoLogger("testsession", ".*","testhisto.log","1s");
|
||||
// TODO: metrics
|
||||
// ActivityMetrics.addHistoLogger("testsession", ".*","testhisto.log","1s");
|
||||
testhistogram.update(400);
|
||||
testhistogram.getSnapshot();
|
||||
final File logfile = new File("testhisto.log");
|
||||
|
||||
Reference in New Issue
Block a user