Skip to content

Commit

Permalink
metrics: add packet counter for the upper mac
Browse files Browse the repository at this point in the history
  • Loading branch information
marenz2569 committed Jun 15, 2024
1 parent daeae89 commit a76dd8a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
5 changes: 1 addition & 4 deletions include/l2/slot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,7 @@ class Slots {
public:
Slots() = delete;

Slots(const Slots& other)
: burst_type_(other.burst_type_)
, slot_type_(other.slot_type_)
, slots_(other.slots_){};
Slots(const Slots& other) = default;

/// constructor for one subslot or a full slot
Slots(BurstType burst_type, SlotsType slot_type, Slot&& slot);
Expand Down
31 changes: 30 additions & 1 deletion include/l2/upper_mac.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ class UpperMacPrometheusCounters {
/// The counter for received StealingChannel with decoding errors
prometheus::Counter& stealing_channel_received_count_decoding_error_;

/// The family of counters for all received upper mac packets
prometheus::Family<prometheus::Counter>& packet_count_family_;
/// The counters for all received c-plane signalling packets
prometheus::Counter& c_plane_signalling_packet_count_;
/// The counters for all received u-plane signalling packets
prometheus::Counter& u_plane_signalling_packet_count_;
/// The counters for all received u-plane traffic packets
prometheus::Counter& u_plane_traffic_packet_count_;
/// The counters for all received broadcast packets
prometheus::Counter& broadcast_packet_count_;

// NOLINTEND(cppcoreguidelines-avoid-const-or-ref-data-members)

public:
Expand Down Expand Up @@ -97,7 +108,12 @@ class UpperMacPrometheusCounters {
, signalling_channel_full_received_count_decoding_error_(slot_error_count_family_.Add(
{{"logical_channel", "SignallingChannelFull"}, {"error_type", "Decode Error"}}))
, stealing_channel_received_count_decoding_error_(
slot_error_count_family_.Add({{"logical_channel", "StealingChannel"}, {"error_type", "Decode Error"}})){};
slot_error_count_family_.Add({{"logical_channel", "StealingChannel"}, {"error_type", "Decode Error"}}))
, packet_count_family_(prometheus_exporter_->upper_mac_packet_count())
, c_plane_signalling_packet_count_(packet_count_family_.Add({{"packet_type", "C-Plane Signalling"}}))
, u_plane_signalling_packet_count_(packet_count_family_.Add({{"packet_type", "U-Plane Signalling"}}))
, u_plane_traffic_packet_count_(packet_count_family_.Add({{"packet_type", "U-Plane Traffic"}}))
, broadcast_packet_count_(packet_count_family_.Add({{"packet_type", "Broadcast"}})){};

/// This function is called for every slot once it is passed up from the lower MAC
/// \param slot the content of the slot
Expand Down Expand Up @@ -160,6 +176,19 @@ class UpperMacPrometheusCounters {
break;
}
}

/// This function is called for all decoded packets in the upper mac
/// \param packets the datastructure that contains all the successfully decoded packets
auto increment_packet_counters(const UpperMacPackets& packets) -> void {
c_plane_signalling_packet_count_.Increment(static_cast<double>(packets.c_plane_signalling_packets_.size()));
u_plane_signalling_packet_count_.Increment(static_cast<double>(packets.u_plane_signalling_packet_.size()));
if (packets.u_plane_traffic_packet_) {
u_plane_traffic_packet_count_.Increment();
}
if (packets.broadcast_packet_) {
broadcast_packet_count_.Increment();
}
}
};

class UpperMac {
Expand Down
3 changes: 3 additions & 0 deletions include/prometheus.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class PrometheusExporter {
auto upper_mac_total_slot_count() noexcept -> prometheus::Family<prometheus::Counter>&;
/// The family of counters for all received slots with errors
auto upper_mac_slot_error_count() noexcept -> prometheus::Family<prometheus::Counter>&;

/// The family of counters for all received upper mac packets
auto upper_mac_packet_count() noexcept -> prometheus::Family<prometheus::Counter>&;
};

#endif // PROMETHEUS_H
5 changes: 5 additions & 0 deletions src/l2/upper_mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,9 @@ auto UpperMac::processPackets(UpperMacPackets&& packets,
logical_link_control_->process(packet.address_, data);
}
}

/// increment the packet counter
if (metrics_) {
metrics_->increment_packet_counters(packets);
}
}
8 changes: 8 additions & 0 deletions src/prometheus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,12 @@ auto PrometheusExporter::upper_mac_slot_error_count() noexcept -> prometheus::Fa
.Help("Incrementing counter of the number of received slots in the upper MAC with errors.")
.Labels({{"name", prometheus_name_}})
.Register(*registry_);
}

auto PrometheusExporter::upper_mac_packet_count() noexcept -> prometheus::Family<prometheus::Counter>& {
return prometheus::BuildCounter()
.Name("upper_mac_packet_count")
.Help("Incrementing counter of the number of received packets in the upper MAC.")
.Labels({{"name", prometheus_name_}})
.Register(*registry_);
}

0 comments on commit a76dd8a

Please sign in to comment.