diff --git a/orb-connd/src/connectivity_daemon.rs b/orb-connd/src/connectivity_daemon.rs index 9c001a93..e463a630 100644 --- a/orb-connd/src/connectivity_daemon.rs +++ b/orb-connd/src/connectivity_daemon.rs @@ -6,7 +6,7 @@ use crate::service::{self, ConndService, ProfileStorage}; use crate::systemd::Systemd; use crate::{modem, reporters, OrbCapabilities}; use color_eyre::eyre::{Context, Result}; -use orb_dogd::MetricEmitter; +use orb_dogd::{MetricEmitter, NO_TAGS}; use orb_info::orb_os_release::OrbOsRelease; use speare::mini::{self, OnErr}; use speare::Backoff; @@ -99,6 +99,8 @@ pub async fn program( .await?; if let OrbCapabilities::CellularAndWifi = cap { + let _ = statsd_client.gauge("orb.platform.connd.lte_capable", 1.0, NO_TAGS); + speare .task_with() .args(modem::Args { diff --git a/orb-connd/src/reporters/active_connections.rs b/orb-connd/src/reporters/active_connections.rs index a3daddc5..80156143 100644 --- a/orb-connd/src/reporters/active_connections.rs +++ b/orb-connd/src/reporters/active_connections.rs @@ -5,23 +5,29 @@ use color_eyre::eyre::{bail, eyre, Context, ContextCompat}; use color_eyre::Result; use futures::StreamExt; use oes::NetworkInterface; +use orb_dogd::MetricEmitter; use speare::mini; use std::collections::hash_map::Entry; use std::collections::HashMap; use std::path::{Path, PathBuf}; +use std::sync::Arc; use std::time::Duration; use tokio::{fs, time}; use tracing::{error, info, warn}; -pub struct Args { +pub struct Args { pub nm: NetworkManager, pub resolved: Resolved, pub zsender: zenorb::Sender, pub procfs: PathBuf, pub sysfs: PathBuf, + pub metrics: Arc, } -pub async fn report(ctx: mini::Ctx) -> Result<()> { +pub async fn report(ctx: mini::Ctx>) -> Result<()> +where + M: MetricEmitter, +{ info!("starting active connections reporter"); async { @@ -56,6 +62,8 @@ pub async fn report(ctx: mini::Ctx) -> Result<()> { .await .wrap_err("building active connections report")?; + emit_metrics(&report, ctx.metrics.as_ref()); + publish_report(&ctx, report) .await .wrap_err("publishing active connections report")?; @@ -99,6 +107,8 @@ pub async fn report(ctx: mini::Ctx) -> Result<()> { .await .wrap_err("building active connections report")?; + emit_metrics(&report, ctx.metrics.as_ref()); + publish_report(&ctx, report) .await .wrap_err("publishing active connections report")?; @@ -113,12 +123,15 @@ pub async fn report(ctx: mini::Ctx) -> Result<()> { } /// build report based on NM inputs and system inspection -async fn build_report( +async fn build_report( primary: &Option, connection_state: ConnectionState, active_conns: &Vec, - ctx: &mini::Ctx, -) -> Result { + ctx: &mini::Ctx>, +) -> Result +where + M: MetricEmitter, +{ let connectivity_uri = ctx.nm.connectivity_check_uri().await?; let hostname = hostname_from_uri(&connectivity_uri).map(str::to_string); let mut connections = Vec::new(); @@ -197,10 +210,27 @@ struct Connection { http_check: Result, } -async fn publish_report( - ctx: &mini::Ctx, +fn emit_metrics(report: &ActiveConnections, metrics: &impl MetricEmitter) { + for c in &report.connections { + if c.primary { + let _ = metrics.gauge( + "orb.platform.connd.primary_conn", + 1.0, + [format!("kind:{}", c.iface)], + ); + + return; + } + } +} + +async fn publish_report( + ctx: &mini::Ctx>, report: ActiveConnections, -) -> Result<()> { +) -> Result<()> +where + M: MetricEmitter, +{ info!("{report:#?}"); let report: oes::ActiveConnections = report.try_into()?; diff --git a/orb-connd/src/reporters/mod.rs b/orb-connd/src/reporters/mod.rs index 7ba61021..a15f626b 100644 --- a/orb-connd/src/reporters/mod.rs +++ b/orb-connd/src/reporters/mod.rs @@ -71,6 +71,7 @@ pub async fn spawn( zsender, sysfs, procfs, + metrics: statsd.clone(), }) .on_err(static_backoff(15)) .spawn(active_connections::report)?;