Metrics export for import command. (#509)

For the import command pay attention to the --metrics-enabled and
--metrics-listen CLI flags and run the metrics server if requested
Danno Ferrin 6 years ago committed by GitHub
parent 2c5f49dfef
commit e06c685f4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      pantheon/src/main/java/tech/pegasys/pantheon/cli/ImportSubCommand.java
  2. 6
      pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java

@ -14,12 +14,16 @@ package tech.pegasys.pantheon.cli;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration;
import tech.pegasys.pantheon.metrics.prometheus.MetricsHttpService;
import tech.pegasys.pantheon.util.BlockImporter; import tech.pegasys.pantheon.util.BlockImporter;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Optional;
import io.vertx.core.Vertx;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import picocli.CommandLine; import picocli.CommandLine;
@ -55,7 +59,16 @@ class ImportSubCommand implements Runnable {
checkNotNull(parentCommand); checkNotNull(parentCommand);
checkNotNull(blockImporter); checkNotNull(blockImporter);
Optional<MetricsHttpService> metricsHttpService = Optional.empty();
try { try {
final MetricsConfiguration metricsConfiguration = parentCommand.metricsConfiguration();
if (metricsConfiguration.isEnabled()) {
metricsHttpService =
Optional.of(
new MetricsHttpService(
Vertx.vertx(), metricsConfiguration, parentCommand.getMetricsSystem()));
metricsHttpService.ifPresent(MetricsHttpService::start);
}
blockImporter.importBlockchain(blocksImportPath, parentCommand.buildController()); blockImporter.importBlockchain(blocksImportPath, parentCommand.buildController());
} catch (final FileNotFoundException e) { } catch (final FileNotFoundException e) {
throw new ExecutionException( throw new ExecutionException(
@ -63,6 +76,8 @@ class ImportSubCommand implements Runnable {
} catch (final IOException e) { } catch (final IOException e) {
throw new ExecutionException( throw new ExecutionException(
new CommandLine(this), "Unable to import blocks from " + blocksImportPath, e); new CommandLine(this), "Unable to import blocks from " + blocksImportPath, e);
} finally {
metricsHttpService.ifPresent(MetricsHttpService::stop);
} }
} }
} }

@ -595,7 +595,7 @@ public class PantheonCommand implements DefaultCommandValues, Runnable {
return webSocketConfiguration; return webSocketConfiguration;
} }
private MetricsConfiguration metricsConfiguration() { MetricsConfiguration metricsConfiguration() {
final MetricsConfiguration metricsConfiguration = MetricsConfiguration.createDefault(); final MetricsConfiguration metricsConfiguration = MetricsConfiguration.createDefault();
metricsConfiguration.setEnabled(isMetricsEnabled); metricsConfiguration.setEnabled(isMetricsEnabled);
metricsConfiguration.setHost(metricsHostAndPort.getHost()); metricsConfiguration.setHost(metricsHostAndPort.getHost());
@ -737,4 +737,8 @@ public class PantheonCommand implements DefaultCommandValues, Runnable {
private boolean isFullInstantiation() { private boolean isFullInstantiation() {
return !isDocker; return !isDocker;
} }
public MetricsSystem getMetricsSystem() {
return metricsSystem;
}
} }

Loading…
Cancel
Save