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

Expose metrics to prometheus #506

Merged
merged 4 commits into from
Jan 4, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration;
import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration;
import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration;
import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration;
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.PantheonWeb3j;
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction;
Expand Down Expand Up @@ -69,6 +70,7 @@ public class PantheonNode implements Node, NodeConfiguration, RunnableNode, Auto
private final MiningParameters miningParameters;
private final JsonRpcConfiguration jsonRpcConfiguration;
private final WebSocketConfiguration webSocketConfiguration;
private final MetricsConfiguration metricsConfiguration;
private final PermissioningConfiguration permissioningConfiguration;
private final GenesisConfigProvider genesisConfigProvider;
private final boolean devMode;
Expand All @@ -82,6 +84,7 @@ public PantheonNode(
final MiningParameters miningParameters,
final JsonRpcConfiguration jsonRpcConfiguration,
final WebSocketConfiguration webSocketConfiguration,
final MetricsConfiguration metricsConfiguration,
final PermissioningConfiguration permissioningConfiguration,
final boolean devMode,
final GenesisConfigProvider genesisConfigProvider,
Expand All @@ -94,6 +97,7 @@ public PantheonNode(
this.miningParameters = miningParameters;
this.jsonRpcConfiguration = jsonRpcConfiguration;
this.webSocketConfiguration = webSocketConfiguration;
this.metricsConfiguration = metricsConfiguration;
this.permissioningConfiguration = permissioningConfiguration;
this.genesisConfigProvider = genesisConfigProvider;
this.devMode = devMode;
Expand Down Expand Up @@ -289,6 +293,10 @@ Optional<String> wsRpcListenAddress() {
webSocketConfiguration().getHost() + ":" + webSocketConfiguration().getPort());
}

MetricsConfiguration metricsConfiguration() {
return metricsConfiguration;
}

int p2pPort() {
return p2pPort;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public void startNode(final PantheonNode node) {
.dataDir(node.homeDirectory())
.bannedNodeIds(Collections.emptySet())
.metricsSystem(noOpMetricsSystem)
.metricsConfiguration(node.metricsConfiguration())
.permissioningConfiguration(node.getPermissioningConfiguration())
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration;
import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration;
import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration;
import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.GenesisConfigProvider;

class PantheonFactoryConfiguration {
Expand All @@ -24,6 +25,7 @@ class PantheonFactoryConfiguration {
private final MiningParameters miningParameters;
private final JsonRpcConfiguration jsonRpcConfiguration;
private final WebSocketConfiguration webSocketConfiguration;
private final MetricsConfiguration metricsConfiguration;
private final PermissioningConfiguration permissioningConfiguration;
private final boolean devMode;
private final GenesisConfigProvider genesisConfigProvider;
Expand All @@ -33,13 +35,15 @@ class PantheonFactoryConfiguration {
final MiningParameters miningParameters,
final JsonRpcConfiguration jsonRpcConfiguration,
final WebSocketConfiguration webSocketConfiguration,
final MetricsConfiguration metricsConfiguration,
final PermissioningConfiguration permissioningConfiguration,
final boolean devMode,
final GenesisConfigProvider genesisConfigProvider) {
this.name = name;
this.miningParameters = miningParameters;
this.jsonRpcConfiguration = jsonRpcConfiguration;
this.webSocketConfiguration = webSocketConfiguration;
this.metricsConfiguration = metricsConfiguration;
this.permissioningConfiguration = permissioningConfiguration;
this.devMode = devMode;
this.genesisConfigProvider = genesisConfigProvider;
Expand All @@ -61,6 +65,10 @@ public WebSocketConfiguration getWebSocketConfiguration() {
return webSocketConfiguration;
}

public MetricsConfiguration getMetricsConfiguration() {
return metricsConfiguration;
}

public PermissioningConfiguration getPermissioningConfiguration() {
return permissioningConfiguration;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration;
import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration;
import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration;
import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.GenesisConfigProvider;

import java.util.Optional;
Expand All @@ -30,6 +31,7 @@ public class PantheonFactoryConfigurationBuilder {
new MiningParametersTestBuilder().enabled(false).build();
private JsonRpcConfiguration jsonRpcConfiguration = JsonRpcConfiguration.createDefault();
private WebSocketConfiguration webSocketConfiguration = WebSocketConfiguration.createDefault();
private MetricsConfiguration metricsConfiguration = MetricsConfiguration.createDefault();
private PermissioningConfiguration permissioningConfiguration =
PermissioningConfiguration.createDefault();
private boolean devMode = true;
Expand Down Expand Up @@ -73,6 +75,12 @@ public PantheonFactoryConfigurationBuilder setWebSocketConfiguration(
return this;
}

public PantheonFactoryConfigurationBuilder setMetricsConfiguration(
final MetricsConfiguration metricsConfiguration) {
this.metricsConfiguration = metricsConfiguration;
return this;
}

public PantheonFactoryConfigurationBuilder webSocketEnabled() {
final WebSocketConfiguration config = WebSocketConfiguration.createDefault();
config.setEnabled(true);
Expand Down Expand Up @@ -105,6 +113,7 @@ public PantheonFactoryConfiguration build() {
miningParameters,
jsonRpcConfiguration,
webSocketConfiguration,
metricsConfiguration,
permissioningConfiguration,
devMode,
genesisConfigProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ private PantheonNode create(final PantheonFactoryConfiguration config) throws IO
config.getMiningParameters(),
config.getJsonRpcConfiguration(),
config.getWebSocketConfiguration(),
config.getMetricsConfiguration(),
config.getPermissioningConfiguration(),
config.isDevMode(),
config.getGenesisConfigProvider(),
Expand Down
1 change: 1 addition & 0 deletions gradle/versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencyManagement {
dependency 'io.pkts:pkts-core:3.0.3'

dependency "io.prometheus:simpleclient:0.5.0"
dependency "io.prometheus:simpleclient_common:0.5.0"
dependency "io.prometheus:simpleclient_hotspot:0.5.0"

dependency 'io.reactivex.rxjava2:rxjava:2.2.2'
Expand Down
10 changes: 8 additions & 2 deletions metrics/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,21 @@ jar {
}

dependencies {
implementation project(':util')

implementation 'com.google.guava:guava'
implementation 'org.apache.logging.log4j:log4j-api'
implementation 'io.prometheus:simpleclient'
implementation 'io.prometheus:simpleclient_common'
implementation 'io.prometheus:simpleclient_hotspot'
implementation 'io.vertx:vertx-core'
implementation 'io.vertx:vertx-web'
implementation 'org.apache.logging.log4j:log4j-api'

runtime 'org.apache.logging.log4j:log4j-core'

// test dependencies.
testImplementation 'junit:junit'
testImplementation "org.mockito:mockito-core"
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.mockito:mockito-core'
testImplementation 'com.squareup.okhttp3:okhttp'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Copyright 2019 ConsenSys AG.
*
* 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 tech.pegasys.pantheon.metrics.prometheus;

import java.util.Collection;
import java.util.Collections;
import java.util.Objects;

import com.google.common.collect.Lists;

public class MetricsConfiguration {
private static final String DEFAULT_METRICS_HOST = "127.0.0.1";
public static final int DEFAULT_METRICS_PORT = 9545;

private boolean enabled;
private int port;
private String host;
private Collection<String> hostsWhitelist = Collections.singletonList("localhost");

public static MetricsConfiguration createDefault() {
final MetricsConfiguration metricsConfiguration = new MetricsConfiguration();
metricsConfiguration.setEnabled(false);
metricsConfiguration.setPort(DEFAULT_METRICS_PORT);
metricsConfiguration.setHost(DEFAULT_METRICS_HOST);

return metricsConfiguration;
}

private MetricsConfiguration() {}

public boolean isEnabled() {
return enabled;
}

public void setEnabled(final boolean enabled) {
this.enabled = enabled;
}

public int getPort() {
return port;
}

public void setPort(final int port) {
this.port = port;
}

public String getHost() {
return host;
}

public void setHost(final String host) {
this.host = host;
}

Collection<String> getHostsWhitelist() {
return Collections.unmodifiableCollection(this.hostsWhitelist);
}

public void setHostsWhitelist(final Collection<String> hostsWhitelist) {
this.hostsWhitelist = hostsWhitelist;
}

@Override
public String toString() {
return "MetricsConfiguration{"
+ "enabled="
+ enabled
+ ", port="
+ port
+ ", host='"
+ host
+ '\''
+ ", hostsWhitelist="
+ hostsWhitelist
+ '}';
}

@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final MetricsConfiguration that = (MetricsConfiguration) o;
return enabled == that.enabled
&& port == that.port
&& Objects.equals(host, that.host)
&& com.google.common.base.Objects.equal(
Lists.newArrayList(hostsWhitelist), Lists.newArrayList(that.hostsWhitelist));
}

@Override
public int hashCode() {
return Objects.hash(enabled, port, host, hostsWhitelist);
}
}
Loading