This repository has been archived by the owner on Aug 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added kruonis subscription, db_connections_total metric report
- Loading branch information
Showing
4 changed files
with
128 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use async_std::stream; | ||
use async_trait::async_trait; | ||
use chrono::{serde::ts_seconds, DateTime, Utc}; | ||
use serde_derive::{Deserialize, Serialize}; | ||
use svc_agent::mqtt::{ | ||
IncomingEventProperties, IntoPublishableDump, OutgoingEvent, ShortTermTimingProperties, | ||
}; | ||
|
||
use crate::app::context::Context; | ||
use crate::app::endpoint::prelude::*; | ||
use crate::config::TelemetryConfig; | ||
|
||
#[derive(Debug, Deserialize)] | ||
pub(crate) struct PullPayload {} | ||
|
||
#[derive(Serialize, Debug)] | ||
pub(crate) struct MetricValue { | ||
value: u64, | ||
#[serde(with = "ts_seconds")] | ||
timestamp: DateTime<Utc>, | ||
} | ||
|
||
#[derive(Serialize, Debug)] | ||
#[serde(tag = "metric")] | ||
pub(crate) enum Metric { | ||
//IncomingQueue(MetricValue), | ||
//OutgoingQueue(MetricValue), | ||
#[serde(rename(serialize = "apps.conference.db_connections_total"))] | ||
DbConnections(MetricValue), | ||
} | ||
|
||
pub(crate) struct PullHandler; | ||
|
||
#[async_trait] | ||
impl EventHandler for PullHandler { | ||
type Payload = PullPayload; | ||
|
||
async fn handle<C: Context>( | ||
context: &C, | ||
_payload: Self::Payload, | ||
evp: &IncomingEventProperties, | ||
start_timestamp: DateTime<Utc>, | ||
) -> Result { | ||
match context.config().telemetry { | ||
TelemetryConfig { | ||
id: Some(ref account_id), | ||
} => { | ||
let outgoing_event_payload = vec![Metric::DbConnections(MetricValue { | ||
value: context.db().state().connections as u64, | ||
timestamp: Utc::now(), | ||
})]; | ||
|
||
let short_term_timing = ShortTermTimingProperties::until_now(start_timestamp); | ||
let props = evp.to_event("metric.create", short_term_timing); | ||
let outgoing_event = | ||
OutgoingEvent::multicast(outgoing_event_payload, props, account_id); | ||
let boxed_event = Box::new(outgoing_event) as Box<dyn IntoPublishableDump + Send>; | ||
Ok(Box::new(stream::once(boxed_event))) | ||
} | ||
|
||
_ => Ok(Box::new(stream::empty())), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters