diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/ImportSubCommand.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/ImportSubCommand.java index e5c4195001..264afbb900 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/ImportSubCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/ImportSubCommand.java @@ -14,12 +14,16 @@ package tech.pegasys.pantheon.cli; 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 java.io.FileNotFoundException; import java.io.IOException; 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.Logger; import picocli.CommandLine; @@ -55,7 +59,16 @@ class ImportSubCommand implements Runnable { checkNotNull(parentCommand); checkNotNull(blockImporter); + Optional metricsHttpService = Optional.empty(); 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()); } catch (final FileNotFoundException e) { throw new ExecutionException( @@ -63,6 +76,8 @@ class ImportSubCommand implements Runnable { } catch (final IOException e) { throw new ExecutionException( new CommandLine(this), "Unable to import blocks from " + blocksImportPath, e); + } finally { + metricsHttpService.ifPresent(MetricsHttpService::stop); } } } diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java index 5540eb2cfc..533ea44730 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -595,7 +595,7 @@ public class PantheonCommand implements DefaultCommandValues, Runnable { return webSocketConfiguration; } - private MetricsConfiguration metricsConfiguration() { + MetricsConfiguration metricsConfiguration() { final MetricsConfiguration metricsConfiguration = MetricsConfiguration.createDefault(); metricsConfiguration.setEnabled(isMetricsEnabled); metricsConfiguration.setHost(metricsHostAndPort.getHost()); @@ -737,4 +737,8 @@ public class PantheonCommand implements DefaultCommandValues, Runnable { private boolean isFullInstantiation() { return !isDocker; } + + public MetricsSystem getMetricsSystem() { + return metricsSystem; + } }