Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
added connected agents load for each backend
Browse files Browse the repository at this point in the history
  • Loading branch information
khodzha committed Oct 20, 2020
1 parent eb42611 commit ba0567d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
17 changes: 15 additions & 2 deletions src/app/metrics/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,26 @@ fn append_janus_stats(
let backend_load = crate::db::janus_backend::reserve_load_for_each_backend(&conn)
.context("Failed to get janus backends reserve load")?
.into_iter()
.map(|load_row| {
.fold(vec![], |mut v, load_row| {
let tags = Tags::build_janus_tags(
crate::APP_VERSION,
context.agent_id(),
&load_row.backend_id,
);
Metric::new(MetricKey::JanusBackendReserveLoad, load_row.load, now, tags)

v.push(Metric::new(
MetricKey::JanusBackendReserveLoad,
load_row.load,
now,
tags.clone(),
));
v.push(Metric::new(
MetricKey::JanusBackendAgentLoad,
load_row.taken,
now,
tags,
));
v
});

metrics.extend(backend_load);
Expand Down
8 changes: 7 additions & 1 deletion src/app/metrics/metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,10 @@ pub(crate) enum MetricKey {
JanusBackendTotalCapacity,
#[serde(rename(serialize = "apps.conference.connected_agents_total"))]
ConnectedAgentsCount,
#[serde(rename(serialize = "apps.conference.janus_backend_reserve_load"))]
#[serde(rename(serialize = "apps.conference.janus_backend_reserve_load_total"))]
JanusBackendReserveLoad,
#[serde(rename(serialize = "apps.conference.janus_backend_agent_load_total"))]
JanusBackendAgentLoad,
#[serde(serialize_with = "serialize_dynamic_metric")]
Dynamic(String),
}
Expand Down Expand Up @@ -176,6 +178,8 @@ pub(crate) enum MetricKey2 {
ConnectedAgentsCount,
#[serde(rename(serialize = "janus_backend_reserve_load_total"))]
JanusBackendReserveLoad,
#[serde(rename(serialize = "janus_backend_agent_load_total"))]
JanusBackendAgentLoad,
#[serde(serialize_with = "serialize_dynamic_metric2")]
Dynamic(String),
}
Expand All @@ -198,6 +202,7 @@ impl From<MetricKey> for MetricKey2 {
MetricKey::ConnectedAgentsCount => MetricKey2::ConnectedAgentsCount,
MetricKey::Dynamic(key) => MetricKey2::Dynamic(key),
MetricKey::JanusBackendReserveLoad => MetricKey2::JanusBackendReserveLoad,
MetricKey::JanusBackendAgentLoad => MetricKey2::JanusBackendAgentLoad,
}
}
}
Expand All @@ -219,6 +224,7 @@ impl std::fmt::Display for MetricKey2 {
MetricKey2::JanusBackendTotalCapacity => write!(f, "janus_backends_capacity_total"),
MetricKey2::ConnectedAgentsCount => write!(f, "connected_agents_total"),
MetricKey2::JanusBackendReserveLoad => write!(f, "janus_backend_reserve_load_total"),
MetricKey2::JanusBackendAgentLoad => write!(f, "janus_backend_agent_load_total"),
MetricKey2::Dynamic(key) => write!(f, "{}_total", key),
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/db/janus_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ pub(crate) struct ReserveLoadQueryLoad {
pub backend_id: AgentId,
#[sql_type = "diesel::sql_types::BigInt"]
pub load: i64,
#[sql_type = "diesel::sql_types::BigInt"]
pub taken: i64,
}

pub(crate) fn reserve_load_for_each_backend(
Expand Down Expand Up @@ -461,7 +463,8 @@ WITH
janus_backend_load AS (
SELECT
backend_id,
SUM(reserve) AS load
SUM(reserve) AS load,
SUM(taken) AS taken
FROM (
SELECT DISTINCT ON(backend_id, room_id)
rec.backend_id,
Expand All @@ -481,7 +484,8 @@ WITH
)
SELECT
jb.id AS backend_id,
COALESCE(jbl.load, 0) as load
COALESCE(jbl.load, 0) as load,
COALESCE(jbl.taken, 0) as taken
FROM janus_backend jb
LEFT OUTER JOIN janus_backend_load jbl
ON jb.id = jbl.backend_id;
Expand Down

0 comments on commit ba0567d

Please sign in to comment.