Skip to content

Commit

Permalink
chore: reflect various feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nodebreaker0-0 committed Jan 10, 2020
1 parent 97e37e4 commit f3e444e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 46 deletions.
2 changes: 1 addition & 1 deletion client/service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub struct Configuration<C, G, E = NoExtension> {
pub rpc_cors: Option<Vec<String>>,
/// Grafana data source http port. `None` if disabled.
pub grafana_port: Option<SocketAddr>,
/// Promteheus Port. `None` if disabled. and defult port 33333
/// Prometheus Port.`None` if disabled and port 33333 by default.
pub prometheus_port: Option<SocketAddr>,
/// Telemetry service URL. `None` if disabled.
pub telemetry_endpoints: Option<TelemetryEndpoints>,
Expand Down
2 changes: 1 addition & 1 deletion utils/prometheus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ derive_more = "0.99"
grafana-data-source = { version = "2.0.0", path = "../grafana-data-source" }

[target.'cfg(not(target_os = "unknown"))'.dependencies]
async-std = { version = "1.0.1", features = ["unstable"] }
async-std = { version = "1.0.1", features = ["unstable"] }
28 changes: 7 additions & 21 deletions utils/prometheus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
![grants](./photo_2019-12-13_16-32-53.jpg)
## Introduction

Prometheus is one of the most widely used monitoring tool for managing high availability services supported by [Cloud Native Computing Foundation](https://www.cncf.io/). By providing Prometheus exporter in substrate, node operators can easily adopt widely used display/alert tool such as Grafana without seting-up/operating external Prometheus agent through RPC connections. Easy access to such monitoring tools will benefit parachain develepers/operators and validators to have much higher availability quality of their services.
Prometheus is one of the most widely used monitoring tool for managing high availability services supported by [Cloud Native Computing Foundation](https://www.cncf.io/). By providing Prometheus metrics in Substrate, node operators can easily adopt widely used display/alert tools such as Grafana and Alertmanager without setting-up/operating external Prometheus push gateways (which is an antipattern in the first place) through RPC connections. Easy access to such monitoring tools will benefit parachain developers/operators and validators to have much higher availability of their services.

## List of Contents
## Table of Contents

Hack Prometheus in Substrate
- Prometheus starter
- Prometheus primer
- CLI Config
- Metrics Add

Expand All @@ -23,11 +23,11 @@ Start Grafana
- Install Grafana

## Substrate Dev hack
### Prometheus starter
### Prometheus primer

Here is the entry point of prometheus core module in Parity Substrate.

In existing sources, refer to the grapana source due to the issue of the wasm.
In existing sources, refer to the Grafana source due to the issue of the wasm.

utils/prometheus/src/lib.rs
```rust
Expand Down Expand Up @@ -74,13 +74,11 @@ async fn request_metrics(req: Request<Body>) -> Result<Response<Body>, Error> {
.header("Content-Type", encoder.format_type())
.body(Body::from(buffer))
.map_err(Error::Http)
//.expect("Sends OK(200) response with one or more data metrics")
} else {
Response::builder()
.status(StatusCode::NOT_FOUND)
.body(Body::from("Not found."))
.map_err(Error::Http)
//.expect("Sends NOT_FOUND(404) message with no data metric")
}

}
Expand Down Expand Up @@ -168,18 +166,7 @@ macro_rules! prometheus_histogram(
}
);

/*
TODO: Make abstract type for all metrics(e.g. Gauge, Histogram, Counter) with generic traits so that all metrics can be set up with one function `set`
#[macro_export]
macro_rules! prometheus(
($($a: expr; $metric:expr => $value:expr),*) => {
use $crate::{metrics::*};
$(
metrics::set(#$a, &$metric, $value);
)*
}
);
*/

```


Expand Down Expand Up @@ -338,7 +325,7 @@ client/service/src/config.rs
#[derive(Clone)]
pub struct Configuration<C, G, E = NoExtension> {
...
/// Promteheus Port. `None` if disabled. and defult port 33333
/// Prometheus Port.`None` if disabled and port 33333 by default.
pub prometheus_port: Option<SocketAddr>,
...
}
Expand Down Expand Up @@ -392,7 +379,6 @@ lazy_static! {
pub static ref FINALITY_HEIGHT: Result<IntGauge> = try_create_int_gauge(
"consensus_finality_block_height_number",
"block is finality HEIGHT"

);
}
```
Expand Down
15 changes: 0 additions & 15 deletions utils/prometheus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,11 @@ async fn request_metrics(req: Request<Body>) -> Result<Response<Body>, Error> {
.header("Content-Type", encoder.format_type())
.body(Body::from(buffer))
.map_err(Error::Http)
//.expect("Sends OK(200) response with one or more data metrics")
} else {
Response::builder()
.status(StatusCode::NOT_FOUND)
.body(Body::from("Not found."))
.map_err(Error::Http)
//.expect("Sends NOT_FOUND(404) message with no data metric")
}

}
Expand Down Expand Up @@ -152,16 +150,3 @@ macro_rules! prometheus_histogram(
)*
}
);

/*
TODO: Make abstract type for all metrics(e.g. Gauge, Histogram, Counter) with generic traits so that all metrics can be set up with one function `set`
#[macro_export]
macro_rules! prometheus(
($($a: expr; $metric:expr => $value:expr),*) => {
use $crate::{metrics::*};
$(
metrics::set(#$a, &$metric, $value);
)*
}
);
*/
20 changes: 12 additions & 8 deletions utils/prometheus/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,65 +32,69 @@ pub fn try_create_histogram(name: &str, help: &str) -> Result<Histogram> {
Ok(histogram)
}

///Gauge Metrics a value in injection.
/// Gauge Metrics a value in injection.
pub fn set_gauge(gauge: &Result<IntGauge>, value: u64) {
if let Ok(gauge) = gauge {
gauge.set(value as i64);
}
}
///histogram Metrics a value in injection.
/// histogram Metrics a value in injection.
pub fn set_histogram(histogram: &Result<Histogram>, value: f64) {
if let Ok(histogram) = histogram {
histogram.observe(value)
}
}
//All of the metrics in the prometheus are managed by the lazy_static.
/// All of the metrics in the prometheus are managed by the lazy_static.
lazy_static! {
pub static ref FINALITY_HEIGHT: Result<IntGauge> = try_create_int_gauge(
"consensus_finality_block_height_number",
"block is finality HEIGHT"

);

pub static ref BEST_HEIGHT: Result<IntGauge> = try_create_int_gauge(
"consensus_best_block_height_number",
"block is best HEIGHT"
);

pub static ref BLOCK_INTERVAL_SECONDS: Result<Histogram> = try_create_histogram(
"consensus_block_interval_seconds",
"Time between this and last block(Block.Header.Time) in seconds"
);
pub static ref P2P_PEERS_NUM: Result<IntGauge> = try_create_int_gauge(
"p2p_peers_number",
"network gosip peers number"
);

pub static ref TARGET_NUM: Result<IntGauge> = try_create_int_gauge(
"consensus_target_syn_number",
"block syn target number"
);

pub static ref TX_COUNT: Result<IntGauge> = try_create_int_gauge(
"consensus_num_txs",
"Number of transactions"
);

pub static ref NODE_MEMORY: Result<IntGauge> = try_create_int_gauge(
"consensus_node_memory",
"node memory"
);

pub static ref NODE_CPU: Result<IntGauge> = try_create_int_gauge(
"consensus_node_cpu",
"node cpu"
);

pub static ref STATE_CACHE_SIZE: Result<IntGauge> = try_create_int_gauge(
"consensus_state_cache_size",
"used state cache size"
);

pub static ref P2P_NODE_DOWNLOAD: Result<IntGauge> = try_create_int_gauge(
"p2p_peers_receive_byte_per_sec",
"p2p_node_download_per_sec_byte"
);

pub static ref P2P_NODE_UPLOAD: Result<IntGauge> = try_create_int_gauge(
"p2p_peers_send_byte_per_sec",
"p2p_node_upload_per_sec_byte"
);
}
}

0 comments on commit f3e444e

Please sign in to comment.