register client system metrics in NBCLI

This commit is contained in:
ShaunakDas88 2023-10-04 16:44:47 -07:00
parent e7d876a8fb
commit 4502a5ec61

View File

@ -16,6 +16,8 @@
package io.nosqlbench.engine.cli; package io.nosqlbench.engine.cli;
import com.codahale.metrics.Gauge;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import io.nosqlbench.api.annotations.Annotation; import io.nosqlbench.api.annotations.Annotation;
@ -25,6 +27,7 @@ import io.nosqlbench.api.labels.NBLabels;
import io.nosqlbench.api.content.Content; import io.nosqlbench.api.content.Content;
import io.nosqlbench.api.content.NBIO; import io.nosqlbench.api.content.NBIO;
import io.nosqlbench.api.engine.metrics.ActivityMetrics; 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.BasicError;
import io.nosqlbench.api.logging.NBLogLevel; import io.nosqlbench.api.logging.NBLogLevel;
import io.nosqlbench.api.metadata.SessionNamer; import io.nosqlbench.api.metadata.SessionNamer;
@ -34,6 +37,12 @@ import io.nosqlbench.engine.api.activityapi.cyclelog.outputs.cyclelog.CycleLogDu
import io.nosqlbench.engine.api.activityapi.cyclelog.outputs.cyclelog.CycleLogImporterUtility; import io.nosqlbench.engine.api.activityapi.cyclelog.outputs.cyclelog.CycleLogImporterUtility;
import io.nosqlbench.engine.api.activityapi.input.InputType; import io.nosqlbench.engine.api.activityapi.input.InputType;
import io.nosqlbench.engine.api.activityapi.output.OutputType; import io.nosqlbench.engine.api.activityapi.output.OutputType;
import io.nosqlbench.engine.api.activityimpl.uniform.ClientSystemMetricChecker;
import io.nosqlbench.engine.api.activityimpl.uniform.DiskStatsReader;
import io.nosqlbench.engine.api.activityimpl.uniform.LoadAvgReader;
import io.nosqlbench.engine.api.activityimpl.uniform.MemInfoReader;
import io.nosqlbench.engine.api.activityimpl.uniform.NetDevReader;
import io.nosqlbench.engine.api.activityimpl.uniform.StatReader;
import io.nosqlbench.adapters.api.activityconfig.rawyaml.RawOpsLoader; import io.nosqlbench.adapters.api.activityconfig.rawyaml.RawOpsLoader;
import io.nosqlbench.engine.cli.NBCLIOptions.LoggerConfigData; import io.nosqlbench.engine.cli.NBCLIOptions.LoggerConfigData;
import io.nosqlbench.engine.cli.NBCLIOptions.Mode; import io.nosqlbench.engine.cli.NBCLIOptions.Mode;
@ -88,6 +97,8 @@ public class NBCLI implements Function<String[], Integer>, NBLabeledElement {
private String sessionCode; private String sessionCode;
private long sessionTime; private long sessionTime;
private ClientSystemMetricChecker clientMetricChecker;
public NBCLI(final String commandName) { public NBCLI(final String commandName) {
this.commandName = commandName; this.commandName = commandName;
} }
@ -405,6 +416,15 @@ public class NBCLI implements Function<String[], Integer>, NBLabeledElement {
final LoggerConfigData classicConfigs : options.getClassicHistoConfigs()) final LoggerConfigData classicConfigs : options.getClassicHistoConfigs())
ActivityMetrics.addClassicHistos(sessionName, classicConfigs.pattern, classicConfigs.file, classicConfigs.interval); ActivityMetrics.addClassicHistos(sessionName, classicConfigs.pattern, classicConfigs.file, classicConfigs.interval);
// client machine metrics; TODO: modify pollInterval
this.clientMetricChecker = new ClientSystemMetricChecker(10);
registerLoadAvgMetrics();
registerMemInfoMetrics();
registerDiskStatsMetrics();
registerNetworkInterfaceMetrics();
registerStatMetrics();
clientMetricChecker.start();
// intentionally not shown for warn-only // intentionally not shown for warn-only
NBCLI.logger.info(() -> "console logging level is " + options.getConsoleLogLevel()); NBCLI.logger.info(() -> "console logging level is " + options.getConsoleLogLevel());
@ -459,6 +479,7 @@ public class NBCLI implements Function<String[], Integer>, NBLabeledElement {
final ScenariosResults scenariosResults = scenariosExecutor.awaitAllResults(); final ScenariosResults scenariosResults = scenariosExecutor.awaitAllResults();
NBCLI.logger.debug(() -> "Total of " + scenariosResults.getSize() + " result object returned from ScenariosExecutor"); NBCLI.logger.debug(() -> "Total of " + scenariosResults.getSize() + " result object returned from ScenariosExecutor");
clientMetricChecker.shutdown();
ActivityMetrics.closeMetrics(options.wantsEnableChart()); ActivityMetrics.closeMetrics(options.wantsEnableChart());
scenariosResults.reportToLog(); scenariosResults.reportToLog();
ShutdownManager.shutdown(); ShutdownManager.shutdown();
@ -497,6 +518,110 @@ public class NBCLI implements Function<String[], Integer>, NBLabeledElement {
return metrics; return metrics;
} }
private void registerLoadAvgMetrics() {
Gauge<Double> loadAvgOneMinGauge = ActivityMetrics.register(
new NBFunctionGauge(this, () -> LoadAvgReader.getOneMinLoadAverage(), "loadavg_1min")
);
Gauge<Double> loadAvgFiveMinGauge = ActivityMetrics.register(
new NBFunctionGauge(this, () -> LoadAvgReader.getFiveMinLoadAverage(), "loadavg_5min")
);
Gauge<Double> loadAvgFifteenMinuteGauge = ActivityMetrics.register(
new NBFunctionGauge(this, () -> LoadAvgReader.getFifteenMinLoadAverage(), "loadavg_15min")
);
// add checking for CPU load averages; TODO: Modify thresholds
clientMetricChecker.addMetricToCheck("loadavg_5min", loadAvgFiveMinGauge, 50.0);
clientMetricChecker.addMetricToCheck("loadavg_1min", loadAvgOneMinGauge, 50.0);
clientMetricChecker.addMetricToCheck("loadavg_15min", loadAvgFifteenMinuteGauge, 50.0);
}
private void registerMemInfoMetrics() {
Gauge<Double> memTotalGauge = ActivityMetrics.register(
new NBFunctionGauge(this, () -> MemInfoReader.getMemTotalkB(), "mem_total")
);
Gauge<Double> memUsedGauge = ActivityMetrics.register(
new NBFunctionGauge(this, () -> MemInfoReader.getMemUsedkB(), "mem_used")
);
ActivityMetrics.register(
new NBFunctionGauge(this, () -> MemInfoReader.getMemFreekB(), "mem_free")
);
ActivityMetrics.register(
new NBFunctionGauge(this, () -> MemInfoReader.getMemAvailablekB(), "mem_available")
);
ActivityMetrics.register(
new NBFunctionGauge(this, () -> MemInfoReader.getMemCachedkB(), "mem_cached")
);
ActivityMetrics.register(
new NBFunctionGauge(this, () -> MemInfoReader.getMemBufferskB(), "mem_buffered")
);
// add checking for percent memory used at some given time; TODO: Modify percent threshold
clientMetricChecker.addRatioMetricToCheck(
"mem_used_percent", memUsedGauge, memTotalGauge, 90.0, false
);
ActivityMetrics.register(
new NBFunctionGauge(this, () -> MemInfoReader.getSwapTotalkB(), "swap_total")
);
ActivityMetrics.register(
new NBFunctionGauge(this, () -> MemInfoReader.getSwapFreekB(), "swap_free")
);
ActivityMetrics.register(
new NBFunctionGauge(this, () -> MemInfoReader.getSwapUsedkB(), "swap_used")
);
}
private void registerDiskStatsMetrics() {
for (String device: DiskStatsReader.getDevices()) {
ActivityMetrics.register(
new NBFunctionGauge(this, () -> DiskStatsReader.getTransactionsForDevice(device), device + "_transactions")
);
ActivityMetrics.register(
new NBFunctionGauge(this, () -> DiskStatsReader.getKbReadForDevice(device), device + "_kB_read")
);
ActivityMetrics.register(
new NBFunctionGauge(this, () -> DiskStatsReader.getKbWrittenForDevice(device), device + "_kB_written")
);
}
}
private void registerNetworkInterfaceMetrics() {
for (String interfaceName: NetDevReader.getInterfaces()) {
ActivityMetrics.register(
new NBFunctionGauge(this, () -> NetDevReader.getBytesReceived(interfaceName), interfaceName + "_rx_bytes")
);
ActivityMetrics.register(
new NBFunctionGauge(this, () -> NetDevReader.getPacketsReceived(interfaceName), interfaceName + "_rx_packets")
);
ActivityMetrics.register(
new NBFunctionGauge(this, () -> NetDevReader.getBytesTransmitted(interfaceName), interfaceName + "_tx_bytes")
);
ActivityMetrics.register(
new NBFunctionGauge(this, () -> NetDevReader.getPacketsTransmitted(interfaceName), interfaceName + "_tx_packets")
);
}
}
private void registerStatMetrics() {
Gauge<Double> cpuUserGauge = ActivityMetrics.register(
new NBFunctionGauge(this, () -> StatReader.getUserTime(), "cpu_user")
);
ActivityMetrics.register(
new NBFunctionGauge(this, () -> StatReader.getSystemTime(), "cpu_system")
);
ActivityMetrics.register(
new NBFunctionGauge(this, () -> StatReader.getIdleTime(), "cpu_idle")
);
ActivityMetrics.register(
new NBFunctionGauge(this, () -> StatReader.getIoWaitTime(), "cpu_iowait")
);
Gauge<Double> cpuTotalGauge = ActivityMetrics.register(
new NBFunctionGauge(this, () -> StatReader.getTotalTime(), "cpu_total")
);
// add checking for percent of time spent in user space; TODO: Modify percent threshold
clientMetricChecker.addRatioMetricToCheck(
"cpu_user_percent", cpuUserGauge, cpuTotalGauge, 50.0, true
);
}
@Override @Override
public NBLabels getLabels() { public NBLabels getLabels() {
return labels; return labels;