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

Code before:
			out_events_dht_count: register(Gauge::new(
				"sub_libp2p_out_events_dht_count",
				"Number of DHT events currently pending in the channels that broadcast network events",
			)?, registry)?,
			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_notifications_closed_count: register(GaugeVec::new(
				Opts::new(
					"sub_libp2p_out_events_notifications_closed_count",
					"Number of notification substreams opened events pending in the channels that broadcast network events"
				),
				&["protocol"]
			)?, registry)?,
			out_events_notifications_opened_count: register(GaugeVec::new(
				Opts::new(
					"sub_libp2p_out_events_notifications_opened_count",
					"Number of notification substreams opened events pending in the channels that broadcast network events"
				),
				&["protocol"]
			)?, 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)?,
		})
	}
}

fn increase_metrics(metrics: &Metrics, event: &Event, num: u64) {
	match event {
		Event::Dht(_) => metrics.out_events_dht_count.inc(),
		Event::NotificationStreamOpened { engine_id, .. } => {
			metrics.out_events_notifications_opened_count
				.with_label_values(&[&engine_id_to_string(engine_id)])
				.add(num);
		},
		Event::NotificationStreamClosed { engine_id, .. } => {
			metrics.out_events_notifications_closed_count
				.with_label_values(&[&engine_id_to_string(engine_id)])
				.add(num);
		},
		Event::NotificationsReceived { messages, .. } => {
			for (engine_id, message) in messages {
				metrics.out_events_notifications_sizes
					.with_label_values(&[&engine_id_to_string(engine_id)])
					.add(num.saturating_mul(u64::try_from(message.len()).unwrap_or(u64::max_value())));

Review comment (refactor):
```suggestion
					"Total size of notification events pending in the channels"
```

As these are already duplicated at this point, they are not broadcasted anymore, but  from now on unicasted.

Code after:
					"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);
			},
			Event::NotificationStreamClosed { engine_id, .. } => {
				self.events_total
					.with_label_values(&[&format!("notif-closed-{:?}", engine_id), "sent"])
					.inc_by(num);
			},
			Event::NotificationsReceived { messages, .. } => {
				for (engine_id, message) in messages {
					self.events_total
						.with_label_values(&[&format!("notif-{:?}", engine_id), "sent"])
						.inc_by(num);
					self.notifications_sizes
						.with_label_values(&[&engine_id_to_string(engine_id), "sent"])
						.inc_by(num.saturating_mul(u64::try_from(message.len()).unwrap_or(u64::max_value())));
				}
			},
		}
	}

	fn event_out(&self, event: &Event) {