Repository: paritytech/substrate
File: client/network/src/service/out_events.rs (Rust)

Code before:
impl fmt::Debug for OutChannels {
	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
		f.debug_struct("OutChannels")
			.field("num_channels", &self.event_streams.len())
			.finish()
	}
}

struct Metrics {
	// This list is ordered alphabetically
	out_events_num_channels: Gauge<U64>,
	out_events_in: CounterVec<U64>,
	out_events_notifications_sizes: GaugeVec<U64>,
	out_events_out: CounterVec<U64>,
}

impl Metrics {
	fn register(registry: &Registry) -> Result<Self, PrometheusError> {
		Ok(Self {
			out_events_num_channels: register(Gauge::new(
				"sub_libp2p_out_events_num_channels",
				"Number of internal active channels that broadcast network events",
			)?, registry)?,
			out_events_in: register(CounterVec::new(
				Opts::new(
					"sub_libp2p_out_events_notifications_opened_count",
					"Number of events pending in the channels that broadcast network events"
				),
				&["event_name"]
			)?, registry)?,
			out_events_notifications_sizes: register(GaugeVec::new(
				Opts::new(
					"sub_libp2p_out_events_notifications_sizes",
					"Total size of notification events pending in the channels that broadcast network events"
				),
				&["protocol"]
			)?, registry)?,
			out_events_out: register(CounterVec::new(
				Opts::new(
					"sub_libp2p_out_events_notifications_opened_count",
					"Number of events pending in the channels that broadcast network events"
				),
				&["event_name"]
			)?, registry)?,
		})
	}

	fn event_in(&self, event: &Event, num: u64) {
		match event {
			Event::Dht(_) => {
				self.out_events_in

Review comment (suggestion):
I think this metric name is outdated, right? Shouldnt it be something like 
```suggestion
					"sub_libp2p_out_events_notifications_count",
```

Code after:
	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
		f.debug_struct("OutChannels")
			.field("num_channels", &self.event_streams.len())
			.finish()
	}
}

struct Metrics {
	// This list is ordered alphabetically
	events_total: CounterVec<U64>,
	notifications_sizes: CounterVec<U64>,
	num_channels: Gauge<U64>,
}

impl Metrics {
	fn register(registry: &Registry) -> Result<Self, PrometheusError> {
		Ok(Self {
			events_total: register(CounterVec::new(
				Opts::new(
					"sub_libp2p_out_events_events_total",
					"Number of broadcast network events that have been sent or received across all \
					 channels"
				),
				&["event_name", "action"]
			)?, registry)?,
			notifications_sizes: register(CounterVec::new(
				Opts::new(
					"sub_libp2p_out_events_notifications_sizes",
					"Size of notification events that have been sent or received across all \
					 channels"
				),
				&["protocol", "action"]
			)?, registry)?,
			num_channels: register(Gauge::new(
				"sub_libp2p_out_events_num_channels",
				"Number of internal active channels that broadcast network events",
			)?, registry)?,
		})
	}

	fn event_in(&self, event: &Event, num: u64) {
		match event {
			Event::Dht(_) => {
				self.events_total
					.with_label_values(&["dht", "sent"])
					.inc_by(num);
			}
			Event::NotificationStreamOpened { engine_id, .. } => {
				self.events_total
					.with_label_values(&[&format!("notif-open-{:?}", engine_id), "sent"])
					.inc_by(num);