Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metrics counters for up/downlinks and beacons #404

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
31 changes: 30 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ beacon = { package = "beacon", path = "beacon" }
exponential-backoff = {git = "https://github.com/yoshuawuyts/exponential-backoff", branch = "master"}
semtech-udp = { version = ">=0.10.7", default-features=false, features=["server"] }
helium-crypto = "0.6"
metrics = {version = "0", default-features = false}

[features]
default = [ "ecc608" ]
Expand Down
30 changes: 25 additions & 5 deletions src/gateway.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use crate::{
beaconer, packet, packet_router, region_watcher, sync, PacketDown, PacketUp, RegionParams,
Result, Settings,
beaconer,
metrics::{
BEACON_FAILED, BEACON_TRANSMITTED, BEACON_TRANSMITTED_ADJUSTED, DOWNLINK_FAILED,
DOWNLINK_TRANSMITTED, DOWNLINK_TRANSMITTED_ADJUSTED,
},
packet, packet_router, region_watcher, sync, PacketDown, PacketUp, RegionParams, Result,
Settings,
};
use beacon::Beacon;
use lorawan::PHYPayload;
Expand Down Expand Up @@ -181,6 +186,7 @@ impl Gateway {
Ok(tx_power) => tx_power,
Err(err) => {
warn!(%err, "beacon transmit");
metrics::increment_counter!(BEACON_FAILED);
responder.send(Err(err));
return;
}
Expand All @@ -190,6 +196,7 @@ impl Gateway {
Ok(packet) => packet,
Err(err) => {
warn!(%err, "failed to construct beacon pull resp");
metrics::increment_counter!(BEACON_FAILED);
responder.send(Err(err));
return;
}
Expand All @@ -207,6 +214,7 @@ impl Gateway {
?tmst,
"beacon transmitted"
);
metrics::increment_counter!(BEACON_TRANSMITTED);
responder.send(Ok(BeaconResp {
powe: tx_power as i32,
tmst: tmst.unwrap_or(0),
Expand All @@ -221,6 +229,7 @@ impl Gateway {
match power_used {
None => {
warn!("packet transmitted with adjusted power, but packet forwarder does not indicate power used.");
metrics::increment_counter!(BEACON_TRANSMITTED_ADJUSTED);
responder.send(Err(GatewayError::NoBeaconTxPower.into()));
}
Some(actual_power) => {
Expand All @@ -230,6 +239,7 @@ impl Gateway {
?tmst,
"beacon transmitted with adjusted power output",
);
metrics::increment_counter!(BEACON_TRANSMITTED_ADJUSTED);
responder.send(Ok(BeaconResp {
powe: actual_power,
tmst: tmst.unwrap_or(0),
Expand All @@ -239,6 +249,7 @@ impl Gateway {
tmst
} else {
warn!(beacon_id, %err, "failed to transmit beacon");
metrics::increment_counter!(BEACON_FAILED);
responder.send(Err(GatewayError::BeaconTxFailure.into()));
None
}
Expand All @@ -252,6 +263,7 @@ impl Gateway {
Ok(tx_power) => tx_power,
Err(err) => {
warn!(%err, "downlink transmit");
metrics::increment_counter!(DOWNLINK_FAILED);
return;
}
};
Expand Down Expand Up @@ -280,19 +292,27 @@ impl Gateway {
match downlink_rx2.dispatch(Some(DOWNLINK_TIMEOUT)).await {
Err(SemtechError::Ack(TxAckErr::AdjustedTransmitPower(_, _))) => {
warn!("rx2 downlink sent with adjusted transmit power");
metrics::increment_counter!(DOWNLINK_TRANSMITTED_ADJUSTED, "window" => "rx2")
}
Err(err) => {
warn!(%err, "ignoring rx2 downlink error");
metrics::increment_counter!(DOWNLINK_FAILED, "window" => "rx2");
}
Ok(_) => {
metrics::increment_counter!(DOWNLINK_TRANSMITTED, "window" => "rx2")
}
Err(err) => warn!(%err, "ignoring rx2 downlink error"),
_ => (),
}
}
}
Err(SemtechError::Ack(TxAckErr::AdjustedTransmitPower(_, _))) => {
warn!("rx1 downlink sent with adjusted transmit power");
metrics::increment_counter!(DOWNLINK_TRANSMITTED_ADJUSTED, "window" => "rx1")
}
Err(err) => {
warn!(%err, "ignoring rx1 downlink error");
metrics::increment_counter!(DOWNLINK_FAILED, "window" => "rx1");
}
Ok(_) => (),
Ok(_) => metrics::increment_counter!(DOWNLINK_TRANSMITTED, "window" => "rx1"),
}
}
});
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod keypair;
pub mod message_cache;
pub mod packet;

pub mod metrics;
pub mod packet_router;
pub mod region_watcher;
pub mod server;
Expand Down
12 changes: 12 additions & 0 deletions src/metrics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pub const UPLINK_QUEUED: &str = "uplink_queued";
pub const UPLINK_DELIVERED: &str = "uplink_delivered";
pub const UPLINK_FAILED: &str = "uplink_failed";
pub const UPLINK_DISCARDED: &str = "uplink_discarded";

pub const DOWNLINK_TRANSMITTED: &str = "downlink_transmitted";
pub const DOWNLINK_TRANSMITTED_ADJUSTED: &str = "downlink_transmitted_adjusted";
pub const DOWNLINK_FAILED: &str = "downlink_failed";

pub const BEACON_TRANSMITTED: &str = "beacon_transmitted";
pub const BEACON_TRANSMITTED_ADJUSTED: &str = "beacon_transmitted_adjusted";
pub const BEACON_FAILED: &str = "beacon_failed";
11 changes: 9 additions & 2 deletions src/packet_router/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
gateway,
message_cache::{CacheMessage, MessageCache},
metrics::{UPLINK_DELIVERED, UPLINK_DISCARDED, UPLINK_FAILED, UPLINK_QUEUED},
region_watcher,
service::packet_router::PacketRouterService,
sync, Base64, Keypair, MsgSign, PacketUp, RegionParams, Result, Settings,
Expand Down Expand Up @@ -159,6 +160,7 @@ impl PacketRouter {

async fn handle_uplink(&mut self, uplink: PacketUp, received: StdInstant) {
self.store.push_back(uplink, received);
metrics::increment_counter!(UPLINK_QUEUED);
self.send_waiting_packets().await;
}

Expand All @@ -170,9 +172,14 @@ impl PacketRouter {
while let (removed, Some(packet)) = self.store.pop_front(STORE_GC_INTERVAL) {
if removed > 0 {
info!("discarded {removed} queued packets");
metrics::counter!(UPLINK_DISCARDED, removed as u64);
}
if let Err(err) = self.send_packet(packet).await {
warn!(%err, "failed to send uplink")
match self.send_packet(packet).await {
Ok(_) => metrics::increment_counter!(UPLINK_DELIVERED),
Err(err) => {
warn!(%err, "failed to send uplink");
metrics::increment_counter!(UPLINK_FAILED);
}
}
}
}
Expand Down