docs/design/metrics.md
Reth exposes a number of metrics, which can be served from an HTTP endpoint by adding the --metrics flag.
A metric is a numeric representation of data measured over intervals of time. Metrics are malleable to statistical transformations such as sampling, aggregation and correlation, which make them suited to report the overall health of a system.
A trace is a representation of a series of causally related distributed events that encode information about the end-to-end request flow through a distributed system. Traces are used to identify the amount of work done at each layer in an application while preserving causality.
The main difference between metrics and traces is therefore that metrics are system-centric and traces are request-centric: metrics give you insight into how a particular system is doing, while traces help teams identify the path of requests through various services.
For most things, you likely want a metric, except for two scenarios:
To add metrics use the metrics crate.
There are three types of metrics:
Each metric is identified by a Key, which itself is composed of a KeyName and an arbitrary number of Labels.
The KeyName represents the actual metric name, and the labels are used to further drill down into the metric.
For example, a metric that represents stage progress would have a key name of stage_progress and a stage label that can be used to get the progress of individual stages.
There will only ever exist one description per metric KeyName; it is not possible to add a description for a label, or a KeyName/Label group.
The metrics crate provides three macros per metric variant: register_<metric>!, <metric>!, and describe_<metric>!. Prefer to use these where possible, since they generate the code necessary to register and update metrics under various conditions.
register_<metric>! macro simply creates the metric and returns a handle to it (e.g. a Counter). These metric structs are thread-safe and cheap to clone.<metric>! macro registers the metric if it does not exist, and updates its value.describe_<metric>! macro adds an end-user description for the metric.How the metrics are exposed to the end-user is determined by the CLI.
. to namespace metrics
reth1reth.p2p.connections for current connections and reth.p2p.connections.total for total connections. One of these metrics can be used to infer the other.The top-level namespace is added by the CLI using metrics_util::layers::PrefixLayer. ↩