Skip to content

Commit 170db89

Browse files
committed
Merge branch 'main' into validator-manager-genserver-removal
2 parents 5721ccf + ae42589 commit 170db89

File tree

17 files changed

+2529
-4627
lines changed

17 files changed

+2529
-4627
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ kurtosis.setup.ethereum-package:
6666

6767
# 💻 kurtosis.setup.grafana: @ Copies the grafana dashboards to the ethereum-package folder under grafana-config
6868
kurtosis.setup.grafana:
69-
[ -d $(KURTOSIS_GRAFANA_DASHBOARDS_DIR)/lambdaconsensus ] || mkdir $(KURTOSIS_GRAFANA_DASHBOARDS_DIR)/lambdaconsensus
69+
[ -d $(KURTOSIS_GRAFANA_DASHBOARDS_DIR)/lambdaconsensus ] && \
70+
rm $(KURTOSIS_GRAFANA_DASHBOARDS_DIR)/lambdaconsensus/* || \
71+
mkdir $(KURTOSIS_GRAFANA_DASHBOARDS_DIR)/lambdaconsensus
7072
cp -r $(GRAFANA_DASHBOARDS_DIR)/* $(KURTOSIS_GRAFANA_DASHBOARDS_DIR)/lambdaconsensus
7173

7274
#💻 kurtosis.setup.lambdaconsensus: @ Builds the node Docker for the kurtosis environment

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ make kurtosis.purge
332332

333333
## Live Metrics
334334

335-
When running the node, metrics are available at [`http://localhost:9568/metrics`](http://localhost:9568/metrics) in Prometheus format.
335+
When running the node, use the `--metrics` flag to enable metrics at [`http://localhost:9568/metrics`](http://localhost:9568/metrics) in Prometheus format.
336336

337337
### Grafana
338338

config/config.exs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ config :lambda_ethereum_consensus, :fork, fork
2020
# Configure logging
2121
config :logger, level: :info, truncate: :infinity
2222

23-
config :lambda_ethereum_consensus, LambdaEthereumConsensus.Telemetry, enable: true
24-
2523
# Use Jason for JSON parsing in Phoenix
2624
config :phoenix, :json_library, Jason
2725

config/runtime.exs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ checkpoint_sync_url = Keyword.get(args, :checkpoint_sync_url)
4343
execution_endpoint = Keyword.get(args, :execution_endpoint, "http://localhost:8551")
4444
jwt_path = Keyword.get(args, :execution_jwt)
4545
testnet_dir = Keyword.get(args, :testnet_dir)
46-
enable_metrics = Keyword.get(args, :metrics, false)
47-
metrics_port = Keyword.get(args, :metrics_port, if(enable_metrics, do: 9568, else: nil))
46+
metrics_port = Keyword.get(args, :metrics_port, nil)
47+
enable_metrics = Keyword.get(args, :metrics, not is_nil(metrics_port))
4848
beacon_api_port = Keyword.get(args, :beacon_api_port, nil)
4949
enable_beacon_api = Keyword.get(args, :beacon_api, not is_nil(beacon_api_port))
5050
listen_addresses = Keyword.get_values(args, :listen_address)
@@ -188,9 +188,16 @@ block_time_ms =
188188

189189
# Metrics
190190

191-
config :lambda_ethereum_consensus, LambdaEthereumConsensus.Telemetry,
191+
config :lambda_ethereum_consensus, LambdaEthereumConsensus.PromEx,
192+
disabled: not enable_metrics,
193+
metrics_server: [
194+
port: metrics_port || 9568,
195+
auth_strategy: :none
196+
]
197+
198+
config :lambda_ethereum_consensus, LambdaEthereumConsensus.PromExPlugin,
192199
block_processing_buckets: [0.5, 1.0, 1.5, 2, 4, 6, 8] |> Enum.map(&(&1 * block_time_ms)),
193-
port: metrics_port
200+
poll_rate: 15_000
194201

195202
# Logging
196203

lib/beacon_api/endpoint.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ defmodule BeaconApi.Endpoint do
88
json_decoder: Phoenix.json_library()
99
)
1010

11-
plug(BeaconApi.MetricsExporter)
1211
plug(BeaconApi.Router)
1312
plug(Sentry.PlugContext)
1413
end

lib/beacon_api/metrics_exporter.ex

Lines changed: 0 additions & 4 deletions
This file was deleted.

lib/lambda_ethereum_consensus/application.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ defmodule LambdaEthereumConsensus.Application do
99

1010
@impl true
1111
def start(_type, _args) do
12-
BeaconApi.MetricsExporter.setup()
1312
# Configure sentry logger handler
1413
Logger.add_handlers(:lambda_ethereum_consensus)
1514
mode = get_operation_mode()
@@ -37,7 +36,6 @@ defmodule LambdaEthereumConsensus.Application do
3736
CheckpointStates.new()
3837

3938
[
40-
LambdaEthereumConsensus.Telemetry,
4139
LambdaEthereumConsensus.Store.Db,
4240
LambdaEthereumConsensus.Store.Blocks,
4341
LambdaEthereumConsensus.Store.BlockStates
@@ -48,6 +46,7 @@ defmodule LambdaEthereumConsensus.Application do
4846
get_children(:db) ++
4947
[
5048
BeaconApi.Endpoint,
49+
LambdaEthereumConsensus.PromEx,
5150
LambdaEthereumConsensus.Beacon.BeaconNode
5251
]
5352
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
defmodule LambdaEthereumConsensus.PromEx do
2+
@moduledoc """
3+
This module integrates the PromEx library. It sets up PromEx plugins and pre-built dashboards for the node.
4+
"""
5+
use PromEx, otp_app: :lambda_ethereum_consensus
6+
7+
@impl true
8+
def plugins() do
9+
[
10+
PromEx.Plugins.Beam,
11+
LambdaEthereumConsensus.PromExPlugin
12+
]
13+
end
14+
end
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
defmodule LambdaEthereumConsensus.PromExPlugin do
2+
@moduledoc """
3+
This module defines our custom PromEx plugin.
4+
It contains all our custom metrics that are displayed on the `node` dashboard.
5+
"""
6+
7+
alias LambdaEthereumConsensus.Store.Db
8+
use PromEx.Plugin
9+
10+
@impl true
11+
def event_metrics(_opts) do
12+
buckets =
13+
Application.get_env(:lambda_ethereum_consensus, __MODULE__)
14+
|> Keyword.fetch!(:block_processing_buckets)
15+
16+
[
17+
Event.build(:peer_metrics, [
18+
counter([:peers, :connection, :count], tags: [:result]),
19+
counter([:peers, :challenge, :count], tags: [:result]),
20+
counter([:network, :request, :count], tags: [:result, :type, :reason]),
21+
counter([:network, :pubsub_peers, :count], tags: [:result]),
22+
sum([:network, :pubsub_topic_active, :active], tags: [:topic]),
23+
counter([:network, :pubsub_topics_graft, :count], tags: [:topic]),
24+
counter([:network, :pubsub_topics_prune, :count], tags: [:topic]),
25+
counter([:network, :pubsub_topics_deliver_message, :count], tags: [:topic]),
26+
counter([:network, :pubsub_topics_duplicate_message, :count], tags: [:topic]),
27+
counter([:network, :pubsub_topics_reject_message, :count], tags: [:topic]),
28+
counter([:network, :pubsub_topics_un_deliverable_message, :count], tags: [:topic]),
29+
counter([:network, :pubsub_topics_validate_message, :count], tags: [:topic]),
30+
counter([:port, :message, :count], tags: [:function, :direction]),
31+
sum([:network, :request, :blocks], tags: [:result, :type, :reason])
32+
]),
33+
Event.build(:sync_metrics, [
34+
last_value([:sync, :store, :slot], []),
35+
last_value([:sync, :on_block, :slot], []),
36+
distribution([:sync, :on_block, :stop, :duration],
37+
reporter_options: [buckets: buckets],
38+
unit: {:native, :millisecond}
39+
),
40+
distribution([:sync, :on_block, :exception, :duration],
41+
reporter_options: [buckets: buckets],
42+
unit: {:native, :millisecond}
43+
)
44+
]),
45+
Event.build(:db_metrics, [
46+
last_value([:db, :latency, :stop, :duration],
47+
unit: {:native, :millisecond},
48+
tags: [:module, :action]
49+
),
50+
last_value([:db, :latency, :exception, :duration],
51+
unit: {:native, :millisecond},
52+
tags: [:module, :action]
53+
),
54+
counter([:db, :latency, :stop, :count],
55+
unit: {:native, :millisecond},
56+
tags: [:module, :action]
57+
)
58+
]),
59+
Event.build(:libp2pport_metrics, [
60+
last_value([:libp2pport, :handler, :stop, :duration],
61+
unit: {:native, :millisecond},
62+
tags: [:module, :action]
63+
),
64+
last_value([:libp2pport, :handler, :exception, :duration],
65+
unit: {:native, :millisecond},
66+
tags: [:module, :action]
67+
),
68+
counter([:libp2pport, :handler, :stop, :count],
69+
unit: {:native, :millisecond},
70+
tags: [:module, :action]
71+
)
72+
]),
73+
Event.build(:forkchoice_metrics, [
74+
last_value([:fork_choice, :latency, :stop, :duration],
75+
unit: {:native, :millisecond},
76+
tags: [:handler, :transition, :operation]
77+
),
78+
last_value([:fork_choice, :recompute_head, :stop, :duration],
79+
unit: {:native, :millisecond}
80+
),
81+
last_value([:fork_choice, :recompute_head, :exception, :duration],
82+
unit: {:native, :millisecond}
83+
)
84+
]),
85+
Event.build(:blocks_status, [
86+
last_value([:blocks, :status, :total],
87+
tags: [:id, :mainstat, :color, :title, :detail__root]
88+
),
89+
last_value([:blocks, :relationship, :total],
90+
tags: [:id, :source, :target]
91+
)
92+
])
93+
]
94+
end
95+
96+
@impl true
97+
def polling_metrics(_opts) do
98+
poll_rate =
99+
Application.get_env(:lambda_ethereum_consensus, __MODULE__)
100+
|> Keyword.fetch!(:poll_rate)
101+
102+
[
103+
Polling.build(:periodic_measurements, poll_rate, {__MODULE__, :periodic_measurements, []}, [
104+
last_value([:db, :size, :total], unit: :byte),
105+
last_value([:vm, :message_queue, :length], tags: [:process])
106+
])
107+
]
108+
end
109+
110+
def periodic_measurements() do
111+
message_queue_lengths()
112+
db_size()
113+
end
114+
115+
def db_size() do
116+
db_size = Db.size()
117+
:telemetry.execute([:db, :size], %{total: db_size})
118+
end
119+
120+
defp register_queue_length(name, len) do
121+
:telemetry.execute([:vm, :message_queue], %{length: len}, %{process: inspect(name)})
122+
end
123+
124+
def message_queue_lengths() do
125+
Process.list()
126+
|> Enum.each(fn pid ->
127+
case Process.info(pid, [:message_queue_len, :registered_name]) do
128+
[message_queue_len: len, registered_name: name] -> register_queue_length(name, len)
129+
[message_queue_len: len] -> register_queue_length(pid, len)
130+
_ -> nil
131+
end
132+
end)
133+
end
134+
end

0 commit comments

Comments
 (0)