Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions docs/usage/client-monitoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ Lodestar provides CLI options to configure monitoring on both the beacon node an
### Remote endpoint URL

Client monitoring can be enabled by setting the `--monitoring.endpoint` flag to a remote service endpoint URL.
As monitoring relies on metrics data, it is required that metrics are also enabled by supplying the `--metrics` flag.

```bash
lodestar beacon --monitoring.endpoint "https://beaconcha.in/api/v1/client/metrics?apikey={apikey}&machine={machineName}" --metrics
lodestar beacon --monitoring.endpoint "https://beaconcha.in/api/v1/client/metrics?apikey={apikey}&machine={machineName}"
```

In case of *beaconcha.in*, the API key can be found in your [account settings](https://beaconcha.in/user/settings#api).
Expand Down
16 changes: 9 additions & 7 deletions packages/beacon-node/src/node/nodejs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ export class BeaconNode {
await db.pruneHotDb();

let metrics = null;
if (opts.metrics.enabled) {
if (
opts.metrics.enabled ||
// monitoring relies on metrics data
opts.monitoring.endpoint
) {
metrics = createMetrics(
opts.metrics,
config,
Expand All @@ -179,11 +183,8 @@ export class BeaconNode {

let monitoring = null;
if (opts.monitoring.endpoint) {
if (metrics == null) {
throw new Error("Metrics must be enabled to use monitoring");
}
monitoring = new MonitoringService("beacon", opts.monitoring, {
register: metrics.register,
register: (metrics as Metrics).register,
logger: logger.child({module: LoggerModule.monitoring}),
});
monitoring.start();
Expand Down Expand Up @@ -261,9 +262,10 @@ export class BeaconNode {
metrics,
});

const metricsServer = metrics
// only start server if metrics are explicitly enabled
const metricsServer = opts.metrics.enabled
? new HttpMetricsServer(opts.metrics, {
register: metrics.register,
register: (metrics as Metrics).register,
getOtherMetrics: async (): Promise<string> => {
return network.metrics();
},
Expand Down
23 changes: 11 additions & 12 deletions packages/cli/src/cmds/validator/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ export async function validatorHandler(args: IValidatorCliArgs & GlobalArgs): Pr

const slashingProtection = new SlashingProtection(dbOps);

// Create metrics registry if metrics are enabled
// Create metrics registry if metrics are enabled or monitoring endpoint is configured
// Send version and network data for static registries

const register = args["metrics"] ? new RegistryMetricCreator() : null;
const register = args["metrics"] || args["monitoring.endpoint"] ? new RegistryMetricCreator() : null;
const metrics = register && getMetrics((register as unknown) as MetricsRegister, {version, commit, network});

// Start metrics server if metrics are enabled.
Expand All @@ -120,19 +120,18 @@ export async function validatorHandler(args: IValidatorCliArgs & GlobalArgs): Pr
if (metrics) {
collectNodeJSMetrics(register);

const port = args["metrics.port"] ?? validatorMetricsDefaultOptions.port;
const address = args["metrics.address"] ?? validatorMetricsDefaultOptions.address;
const metricsServer = new HttpMetricsServer({port, address}, {register, logger});
// only start server if metrics are explicitly enabled
if (args["metrics"]) {
const port = args["metrics.port"] ?? validatorMetricsDefaultOptions.port;
const address = args["metrics.address"] ?? validatorMetricsDefaultOptions.address;
const metricsServer = new HttpMetricsServer({port, address}, {register, logger});

onGracefulShutdownCbs.push(() => metricsServer.stop());
await metricsServer.start();
onGracefulShutdownCbs.push(() => metricsServer.stop());
await metricsServer.start();
}
}

if (args["monitoring.endpoint"]) {
if (register == null) {
throw new Error("Metrics must be enabled to use monitoring");
}

const {interval, initialDelay, requestTimeout, collectSystemStats} = validatorMonitoringDefaultOptions;

const monitoring = new MonitoringService(
Expand All @@ -144,7 +143,7 @@ export async function validatorHandler(args: IValidatorCliArgs & GlobalArgs): Pr
requestTimeout: args["monitoring.requestTimeout"] ?? requestTimeout,
collectSystemStats: args["monitoring.collectSystemStats"] ?? collectSystemStats,
},
{register, logger}
{register: register as RegistryMetricCreator, logger}
);

onGracefulShutdownCbs.push(() => monitoring.stop());
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cmds/validator/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ export const validatorOptions: CliCommandOptions<IValidatorCliArgs> = {
"monitoring.endpoint": {
type: "string",
description:
"Enables monitoring service for sending clients stats to the specified endpoint of a remote service (e.g. beaconcha.in). It is required that metrics are also enabled by supplying the --metrics flag.",
"Enables monitoring service for sending clients stats to the specified endpoint of a remote service (e.g. beaconcha.in)",
group: "monitoring",
},

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/options/beaconNodeOptions/monitoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const options: CliCommandOptions<MonitoringArgs> = {
"monitoring.endpoint": {
type: "string",
description:
"Enables monitoring service for sending clients stats to the specified endpoint of a remote service (e.g. beaconcha.in). It is required that metrics are also enabled by supplying the --metrics flag.",
"Enables monitoring service for sending clients stats to the specified endpoint of a remote service (e.g. beaconcha.in)",
group: "monitoring",
},

Expand Down