2020-09-29 03:46:54 +00:00
|
|
|
use crate::Context;
|
2020-08-24 03:06:10 +00:00
|
|
|
use beacon_chain::BeaconChainTypes;
|
2019-11-25 04:48:24 +00:00
|
|
|
use lighthouse_metrics::{Encoder, TextEncoder};
|
2022-02-10 04:12:03 +00:00
|
|
|
use lighthouse_network::prometheus_client::encoding::text::encode;
|
2021-05-28 05:59:45 +00:00
|
|
|
use malloc_utils::scrape_allocator_metrics;
|
2019-08-19 11:02:34 +00:00
|
|
|
|
|
|
|
pub use lighthouse_metrics::*;
|
|
|
|
|
2020-09-29 03:46:54 +00:00
|
|
|
pub fn gather_prometheus_metrics<T: BeaconChainTypes>(
|
|
|
|
ctx: &Context<T>,
|
|
|
|
) -> std::result::Result<String, String> {
|
2019-08-19 11:02:34 +00:00
|
|
|
let mut buffer = vec![];
|
|
|
|
let encoder = TextEncoder::new();
|
|
|
|
|
|
|
|
// There are two categories of metrics:
|
|
|
|
//
|
|
|
|
// - Dynamically updated: things like histograms and event counters that are updated on the
|
|
|
|
// fly.
|
|
|
|
// - Statically updated: things which are only updated at the time of the scrape (used where we
|
|
|
|
// can avoid cluttering up code with metrics calls).
|
|
|
|
//
|
|
|
|
// The `lighthouse_metrics` crate has a `DEFAULT_REGISTRY` global singleton (via `lazy_static`)
|
|
|
|
// which keeps the state of all the metrics. Dynamically updated things will already be
|
|
|
|
// up-to-date in the registry (because they update themselves) however statically updated
|
|
|
|
// things need to be "scraped".
|
|
|
|
//
|
|
|
|
// We proceed by, first updating all the static metrics using `scrape_for_metrics(..)`. Then,
|
|
|
|
// using `lighthouse_metrics::gather(..)` to collect the global `DEFAULT_REGISTRY` metrics into
|
|
|
|
// a string that can be returned via HTTP.
|
|
|
|
|
2020-09-29 03:46:54 +00:00
|
|
|
if let Some(beacon_chain) = ctx.chain.as_ref() {
|
|
|
|
slot_clock::scrape_for_metrics::<T::EthSpec, T::SlotClock>(&beacon_chain.slot_clock);
|
|
|
|
beacon_chain::scrape_for_metrics(beacon_chain);
|
|
|
|
}
|
|
|
|
|
|
|
|
if let (Some(db_path), Some(freezer_db_path)) =
|
|
|
|
(ctx.db_path.as_ref(), ctx.freezer_db_path.as_ref())
|
|
|
|
{
|
|
|
|
store::scrape_for_metrics(db_path, freezer_db_path);
|
|
|
|
}
|
|
|
|
|
Rename eth2_libp2p to lighthouse_network (#2702)
## Description
The `eth2_libp2p` crate was originally named and designed to incorporate a simple libp2p integration into lighthouse. Since its origins the crates purpose has expanded dramatically. It now houses a lot more sophistication that is specific to lighthouse and no longer just a libp2p integration.
As of this writing it currently houses the following high-level lighthouse-specific logic:
- Lighthouse's implementation of the eth2 RPC protocol and specific encodings/decodings
- Integration and handling of ENRs with respect to libp2p and eth2
- Lighthouse's discovery logic, its integration with discv5 and logic about searching and handling peers.
- Lighthouse's peer manager - This is a large module handling various aspects of Lighthouse's network, such as peer scoring, handling pings and metadata, connection maintenance and recording, etc.
- Lighthouse's peer database - This is a collection of information stored for each individual peer which is specific to lighthouse. We store connection state, sync state, last seen ips and scores etc. The data stored for each peer is designed for various elements of the lighthouse code base such as syncing and the http api.
- Gossipsub scoring - This stores a collection of gossipsub 1.1 scoring mechanisms that are continuously analyssed and updated based on the ethereum 2 networks and how Lighthouse performs on these networks.
- Lighthouse specific types for managing gossipsub topics, sync status and ENR fields
- Lighthouse's network HTTP API metrics - A collection of metrics for lighthouse network monitoring
- Lighthouse's custom configuration of all networking protocols, RPC, gossipsub, discovery, identify and libp2p.
Therefore it makes sense to rename the crate to be more akin to its current purposes, simply that it manages the majority of Lighthouse's network stack. This PR renames this crate to `lighthouse_network`
Co-authored-by: Paul Hauner <paul@paulhauner.com>
2021-10-19 00:30:39 +00:00
|
|
|
lighthouse_network::scrape_discovery_metrics();
|
2019-08-19 11:02:34 +00:00
|
|
|
|
2020-11-26 01:10:51 +00:00
|
|
|
warp_utils::metrics::scrape_health_metrics();
|
2020-05-28 01:24:24 +00:00
|
|
|
|
2021-05-28 05:59:45 +00:00
|
|
|
// It's important to ensure these metrics are explicitly enabled in the case that users aren't
|
|
|
|
// using glibc and this function causes panics.
|
|
|
|
if ctx.config.allocator_metrics_enabled {
|
|
|
|
scrape_allocator_metrics();
|
|
|
|
}
|
|
|
|
|
2019-08-19 11:02:34 +00:00
|
|
|
encoder
|
|
|
|
.encode(&lighthouse_metrics::gather(), &mut buffer)
|
|
|
|
.unwrap();
|
2021-12-22 06:17:14 +00:00
|
|
|
// encode gossipsub metrics also if they exist
|
|
|
|
if let Some(registry) = ctx.gossipsub_registry.as_ref() {
|
|
|
|
if let Ok(registry_locked) = registry.lock() {
|
|
|
|
let _ = encode(&mut buffer, ®istry_locked);
|
|
|
|
}
|
|
|
|
}
|
2019-08-19 11:02:34 +00:00
|
|
|
|
2020-09-29 03:46:54 +00:00
|
|
|
String::from_utf8(buffer).map_err(|e| format!("Failed to encode prometheus info: {:?}", e))
|
2019-08-19 11:02:34 +00:00
|
|
|
}
|