mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
Grafana integration (#3913)
* Very WIP * record_metrics macro works * Integrate into service * Licenses and documentation * Remove unused Debugs, make respond function clearer * Conform to line widths, fix service test * Switch to storing the timestamps as millis instead * Update core/grafana-data-source/src/lib.rs Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Transform timestamps to i64 in serialization * Fix license date * Binary sort to find selection range for metrics * Obey maxDataPoints * Run a cleaning future * Newlines at EOF * Update core/service/Cargo.toml Co-Authored-By: Pierre Krieger <pierre.krieger1708@gmail.com> * Update core/grafana-data-source/src/lib.rs Co-Authored-By: Pierre Krieger <pierre.krieger1708@gmail.com> * Fix indentation * Improve select_points * Made test more accurate * Inprogress * Use the same futures version as hyper for now * Error handling * Remove dependence on hyper's tokio feature * Added target_os flag * Update Cargo.toml Co-Authored-By: Pierre Krieger <pierre.krieger1708@gmail.com> * Simplify example * Remove compat wildcard * Updated lock file * Fix indentation 😉
This commit is contained in:
@@ -29,10 +29,11 @@ use codec::{Decode, Encode, IoReader};
|
||||
use consensus_common::import_queue::ImportQueue;
|
||||
use futures::{prelude::*, sync::mpsc};
|
||||
use futures03::{
|
||||
compat::Compat,
|
||||
compat::{Compat, Future01CompatExt},
|
||||
future::ready,
|
||||
FutureExt as _, TryFutureExt as _,
|
||||
StreamExt as _, TryStreamExt as _,
|
||||
future::{select, Either}
|
||||
};
|
||||
use keystore::{Store as Keystore};
|
||||
use log::{info, warn, error};
|
||||
@@ -53,6 +54,7 @@ use std::{
|
||||
use sysinfo::{get_current_pid, ProcessExt, System, SystemExt};
|
||||
use tel::{telemetry, SUBSTRATE_INFO};
|
||||
use transaction_pool::txpool::{self, ChainApi, Pool as TransactionPool};
|
||||
use grafana_data_source::{self, record_metrics};
|
||||
|
||||
/// Aggregator for the components required to build a service.
|
||||
///
|
||||
@@ -991,6 +993,17 @@ ServiceBuilder<
|
||||
"bandwidth_upload" => bandwidth_upload,
|
||||
"used_state_cache_size" => used_state_cache_size,
|
||||
);
|
||||
record_metrics!(
|
||||
"peers" => num_peers,
|
||||
"height" => best_number,
|
||||
"txcount" => txpool_status.ready,
|
||||
"cpu" => cpu_usage,
|
||||
"memory" => memory,
|
||||
"finalized_height" => finalized_number,
|
||||
"bandwidth_download" => bandwidth_download,
|
||||
"bandwidth_upload" => bandwidth_upload,
|
||||
"used_state_cache_size" => used_state_cache_size
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}).select(exit.clone()).then(|_| Ok(()));
|
||||
@@ -1130,6 +1143,19 @@ ServiceBuilder<
|
||||
telemetry
|
||||
});
|
||||
|
||||
// Grafana data source
|
||||
if let Some(port) = config.grafana_port {
|
||||
let future = select(
|
||||
grafana_data_source::run_server(port).boxed(),
|
||||
exit.clone().compat()
|
||||
).map(|either| match either {
|
||||
Either::Left((result, _)) => result.map_err(|_| ()),
|
||||
Either::Right(_) => Ok(())
|
||||
}).compat();
|
||||
|
||||
let _ = to_spawn_tx.unbounded_send(Box::new(future));
|
||||
}
|
||||
|
||||
// Instrumentation
|
||||
if let Some(tracing_targets) = config.tracing_targets.as_ref() {
|
||||
let subscriber = substrate_tracing::ProfilingSubscriber::new(
|
||||
|
||||
Reference in New Issue
Block a user