Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Metrics export for import command. (#509)
Browse files Browse the repository at this point in the history
For the import command pay attention to the --metrics-enabled and
--metrics-listen CLI flags and run the metrics server if requested
  • Loading branch information
shemnon authored Jan 4, 2019
1 parent 2c5f49d commit e06c685
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@

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;
Expand Down Expand Up @@ -55,14 +59,25 @@ public void run() {
checkNotNull(parentCommand);
checkNotNull(blockImporter);

Optional<MetricsHttpService> 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(
new CommandLine(this), "Could not find file to import: " + blocksImportPath);
} catch (final IOException e) {
throw new ExecutionException(
new CommandLine(this), "Unable to import blocks from " + blocksImportPath, e);
} finally {
metricsHttpService.ifPresent(MetricsHttpService::stop);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ private WebSocketConfiguration webSocketConfiguration() {
return webSocketConfiguration;
}

private MetricsConfiguration metricsConfiguration() {
MetricsConfiguration metricsConfiguration() {
final MetricsConfiguration metricsConfiguration = MetricsConfiguration.createDefault();
metricsConfiguration.setEnabled(isMetricsEnabled);
metricsConfiguration.setHost(metricsHostAndPort.getHost());
Expand Down Expand Up @@ -737,4 +737,8 @@ private Path dataDir() {
private boolean isFullInstantiation() {
return !isDocker;
}

public MetricsSystem getMetricsSystem() {
return metricsSystem;
}
}

0 comments on commit e06c685

Please sign in to comment.