Skip to content

Commit

Permalink
Add receiver for Grafana (#4211)
Browse files Browse the repository at this point in the history
  • Loading branch information
seerscode authored and gavofyork committed Nov 26, 2019
1 parent 53a4821 commit e1a911c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions substrate/Cargo.lock

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

2 changes: 2 additions & 0 deletions substrate/client/cli/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ arg_enum! {
pub enum TracingReceiver {
Log,
Telemetry,
Grafana,
}
}

Expand All @@ -273,6 +274,7 @@ impl Into<substrate_tracing::TracingReceiver> for TracingReceiver {
match self {
TracingReceiver::Log => substrate_tracing::TracingReceiver::Log,
TracingReceiver::Telemetry => substrate_tracing::TracingReceiver::Telemetry,
TracingReceiver::Grafana => substrate_tracing::TracingReceiver::Grafana,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions substrate/client/tracing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ parking_lot = "0.9.0"
tracing-core = "0.1.7"

substrate-telemetry = { path = "../telemetry" }
grafana-data-source = { path = "../grafana-data-source" }

[dev-dependencies]
tracing = "0.1.10"
12 changes: 10 additions & 2 deletions substrate/client/tracing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use parking_lot::Mutex;
use tracing_core::{event::Event, Level, metadata::Metadata, span::{Attributes, Id, Record}, subscriber::Subscriber};

use substrate_telemetry::{telemetry, SUBSTRATE_INFO};
use grafana_data_source::{self, record_metrics};

/// Used to configure how to receive the metrics
#[derive(Debug, Clone)]
Expand All @@ -47,6 +48,8 @@ pub enum TracingReceiver {
Log,
/// Output to telemetry
Telemetry,
/// Output to Grafana,
Grafana,
}

impl Default for TracingReceiver {
Expand All @@ -59,7 +62,7 @@ impl Default for TracingReceiver {
struct SpanDatum {
id: u64,
name: &'static str,
target: String,
target: &'static str,
level: Level,
line: u32,
start_time: Instant,
Expand Down Expand Up @@ -124,7 +127,7 @@ impl Subscriber for ProfilingSubscriber {
let span_datum = SpanDatum {
id: id,
name: attrs.metadata().name(),
target: attrs.metadata().target().to_string(),
target: attrs.metadata().target(),
level: attrs.metadata().level().clone(),
line: attrs.metadata().line().unwrap_or(0),
start_time: Instant::now(),
Expand Down Expand Up @@ -172,6 +175,7 @@ impl ProfilingSubscriber {
match self.receiver {
TracingReceiver::Log => print_log(span_datum),
TracingReceiver::Telemetry => send_telemetry(span_datum),
TracingReceiver::Grafana => send_grafana(span_datum),
}
}
}
Expand All @@ -196,3 +200,7 @@ fn send_telemetry(span_datum: SpanDatum) {
"time" => span_datum.overall_time.as_nanos(),
);
}

fn send_grafana(span_datum: SpanDatum) {
record_metrics!(span_datum.target => span_datum.overall_time.as_nanos());
}

0 comments on commit e1a911c

Please sign in to comment.