Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion chirpstack/src/downlink/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tracing::{debug, span, trace, warn, Instrument, Level};
use crate::api::backend::get_async_receiver;
use crate::api::helpers::{FromProto, ToProto};
use crate::backend::roaming;
use crate::downlink::{classb, error::Error, helpers, tx_ack};
use crate::downlink::{classb, error::Error, helpers, record_downlink_mac_commands, tx_ack};
use crate::gpstime::{ToDateTime, ToGpsTime};
use crate::storage;
use crate::storage::{
Expand Down Expand Up @@ -1038,6 +1038,8 @@ impl Data {
.await
.context("Send downlink frame")?;

record_downlink_mac_commands(self.mac_commands.clone());

Ok(())
}

Expand Down
32 changes: 32 additions & 0 deletions chirpstack/src/downlink/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
use std::sync::LazyLock;
use prometheus_client::encoding::EncodeLabelSet;
use prometheus_client::metrics::counter::Counter;
use prometheus_client::metrics::family::Family;
use tracing::info;
use crate::monitoring::prometheus;

pub mod classb;
pub mod data;
Expand All @@ -11,6 +16,21 @@ pub mod roaming;
pub mod scheduler;
pub mod tx_ack;

#[derive(Clone, Hash, PartialEq, Eq, EncodeLabelSet, Debug)]
struct DownlinkMacCommandLabels {
mac_command: String,
}

static DOWNLINK_MAC_COMMAND_COUNTER: LazyLock<Family<DownlinkMacCommandLabels, Counter>> = LazyLock::new(|| {
let counter = Family::<DownlinkMacCommandLabels, Counter>::default();
prometheus::register(
"downlink_mac_command_count",
"Number of sent mac commands in downlinks",
counter.clone(),
);
counter
});

pub async fn setup() {
info!("Setting up Class-B/C scheduler loop");
tokio::spawn(async move {
Expand All @@ -22,3 +42,15 @@ pub async fn setup() {
scheduler::multicast_group_queue_scheduler_loop().await;
});
}

pub fn record_downlink_mac_commands(mac_command_sets: Vec<lrwn::MACCommandSet>) {
mac_command_sets.iter().for_each(|mac_command_set| {
mac_command_set.iter().for_each(|mac_command| {
DOWNLINK_MAC_COMMAND_COUNTER
.get_or_create(&DownlinkMacCommandLabels {
mac_command: mac_command.to_string(),
})
.inc();
})
})
}
24 changes: 24 additions & 0 deletions chirpstack/src/uplink/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ struct UplinkLabels {
m_type: String,
}

#[derive(Clone, Hash, PartialEq, Eq, EncodeLabelSet, Debug)]
struct UplinkMacCommandLabels {
mac_command: String,
}

static UPLINK_COUNTER: LazyLock<Family<UplinkLabels, Counter>> = LazyLock::new(|| {
let counter = Family::<UplinkLabels, Counter>::default();
prometheus::register(
Expand All @@ -51,6 +56,15 @@ static UPLINK_COUNTER: LazyLock<Family<UplinkLabels, Counter>> = LazyLock::new(|
);
counter
});
static UPLINK_MAC_COMMAND_COUNTER: LazyLock<Family<UplinkMacCommandLabels, Counter>> = LazyLock::new(|| {
let counter = Family::<UplinkMacCommandLabels, Counter>::default();
prometheus::register(
"uplink_mac_command_count",
"Number of received mac commands in uplinks (after deduplication)",
counter.clone(),
);
counter
});
static DEDUPLICATE_LOCKED_COUNTER: LazyLock<Counter> = LazyLock::new(|| {
let counter = Counter::default();
prometheus::register(
Expand Down Expand Up @@ -328,6 +342,16 @@ pub async fn handle_uplink(
})
.inc();

if let lrwn::Payload::MACPayload(pl) = &uplink.phy_payload.payload {
pl.fhdr.f_opts.iter().for_each(|mac_command| {
UPLINK_MAC_COMMAND_COUNTER
.get_or_create(&UplinkMacCommandLabels {
mac_command: mac_command.to_string(),
})
.inc();
})
}

uplink.dr = helpers::get_uplink_dr(&uplink.region_config_id, &uplink.tx_info)?;
uplink.ch = helpers::get_uplink_ch(
&uplink.region_config_id,
Expand Down
6 changes: 6 additions & 0 deletions lrwn/src/maccommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ pub enum MACCommand {
Raw(Vec<u8>),
}

impl fmt::Display for MACCommand {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self)
}
}

impl MACCommand {
pub fn cid(&self) -> CID {
match self {
Expand Down