Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
40762b6
Refactor rebase master prometheus_v0.3
nodebreaker0-0 Nov 28, 2019
472aca1
Milestone1: Final Version of v0.3
nodebreaker0-0 Dec 10, 2019
1974f94
no-std or warm compatibility issues, grapana-data -source code refere…
nodebreaker0-0 Jan 2, 2020
62a873d
Cargo.lock paritytech/master rebase
nodebreaker0-0 Jan 2, 2020
97e37e4
prometheus networking.rs del, grafana-data-source networking.rs pub e…
nodebreaker0-0 Jan 3, 2020
f3e444e
chore: reflect various feedback
nodebreaker0-0 Jan 10, 2020
8145df7
Spaces to tabs.
gavofyork Jan 6, 2020
fca71be
Replace grafana and tidy
expenses Jan 10, 2020
855ceed
Add generics
expenses Jan 10, 2020
70c6bcc
Add photo back
expenses Jan 10, 2020
5941041
Re-fix spaces in primitives/consensus/babe/src/inherents.rs
expenses Jan 10, 2020
7d9d341
Refactor rebase master prometheus_v0.3
nodebreaker0-0 Nov 28, 2019
52316ae
Milestone1: Final Version of v0.3
nodebreaker0-0 Dec 10, 2019
82cd8cf
no-std or warm compatibility issues, grapana-data -source code refere…
nodebreaker0-0 Jan 2, 2020
b052829
prometheus networking.rs del, grafana-data-source networking.rs pub e…
nodebreaker0-0 Jan 3, 2020
4e831e9
chore: reflect various feedback
nodebreaker0-0 Jan 10, 2020
0b15bc4
Replace grafana and tidy
expenses Jan 10, 2020
8025361
Add generics
expenses Jan 10, 2020
fd081c9
Add photo back
expenses Jan 10, 2020
f00bb9b
Re-fix spaces in primitives/consensus/babe/src/inherents.rs
expenses Jan 10, 2020
398da97
chore: revert this file back to paritytech/master inherents.rs.
nodebreaker0-0 Jan 14, 2020
84c458f
Add newline at EOF
expenses Jan 14, 2020
f931588
Merge remote-tracking branch 'nodebreaker/prometheus_v0.3' into ashle…
expenses Jan 16, 2020
5796c85
Merge remote-tracking branch 'parity/master' into ashley-prometheus
expenses Jan 16, 2020
2a45de8
Merge remote-tracking branch 'parity/master' into ashley-prometheus
expenses Jan 16, 2020
8bae73b
Merge remote-tracking branch 'parity/master' into ashley-prometheus
expenses Jan 17, 2020
1caa0f1
Merge remote-tracking branch 'parity/master' into ashley-prometheus
expenses Jan 17, 2020
ffb4746
Tidy
expenses Jan 17, 2020
8a6e3c5
Use local registry
expenses Jan 17, 2020
53c95de
fix typo
hskang9 Jan 17, 2020
23cb72e
chore: Apply review feedback
nodebreaker0-0 Jan 20, 2020
3d1634b
Merge remote-tracking branch 'nodebreaker/prometheus_v0.3' into ashle…
expenses Jan 20, 2020
55ac4f8
Merge remote-tracking branch 'parity/master' into ashley-prometheus
expenses Jan 20, 2020
3cfe43c
endpoint -> exporter
expenses Jan 20, 2020
0af2369
fix readme
expenses Jan 20, 2020
44f8c0e
Merge pull request #3 from paritytech/ashley-prometheus
nodebreaker0-0 Jan 21, 2020
d2bba61
Remove lazy_static, use ServiceMetrics struct instead
expenses Jan 21, 2020
5d3d9a7
Merge pull request #4 from paritytech/ashley-prometheus
nodebreaker0-0 Jan 22, 2020
32c04b4
Merge branch 'paritytech/master' into prometheus_v0.3
mxinden Jan 23, 2020
9bde830
Switch to using GaugeVecs
expenses Jan 23, 2020
97faad6
Merge pull request #5 from mxinden/prometheus_v0.3
nodebreaker0-0 Jan 24, 2020
f64a482
chore: without nightly , edit README
nodebreaker0-0 Jan 24, 2020
5d56d93
Merge branch 'prometheus_v0.3' into ashley-prometheus
nodebreaker0-0 Jan 24, 2020
50f2928
block_height -> block_height_number
expenses Jan 27, 2020
8edb710
Merge branch 'ashley-prometheus' of github.com:paritytech/substrate i…
expenses Jan 27, 2020
6a25ea8
Switch to a ready_transactions_number gauge
expenses Jan 29, 2020
18cf2be
Merge pull request #7 from paritytech/ashley-prometheus
nodebreaker0-0 Jan 29, 2020
bb388f5
Update utils/prometheus/src/lib.rs
hskang9 Jan 31, 2020
77ba252
no-prometheus flag add
nodebreaker0-0 Jan 31, 2020
5e327c2
/metrics url Input check
nodebreaker0-0 Jan 31, 2020
ccb3179
remove prometheus in Tracing
nodebreaker0-0 Feb 5, 2020
152176f
remove prometheus in Tracing
nodebreaker0-0 Feb 14, 2020
8de57c2
Merge branch 'master' into prometheus_v0.3
nodebreaker0-0 Feb 14, 2020
e76f200
chore: master code rebase edit
nodebreaker0-0 Feb 14, 2020
55428b7
gitlab-check-web-wasm edit code
nodebreaker0-0 Feb 14, 2020
d1003e6
From:from and cargo.lock update
nodebreaker0-0 Feb 17, 2020
5c2e085
Merge commit 'db1ab7d18fbe7876cdea43bbf30f147ddd263f94' into promethe…
nodebreaker0-0 Feb 17, 2020
b4b4432
with_prometheus_registry add background_tasks
nodebreaker0-0 Feb 17, 2020
ee421a6
Merge commit '419e5fd0026cfd528cd3b327789bb0a3a8215703' into promethe…
nodebreaker0-0 Feb 18, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: reflect various feedback
  • Loading branch information
nodebreaker0-0 committed Jan 10, 2020
commit f3e444ec1c5bd699fff1bb7bcbca126a69b409f9
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this picture necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a request from the W3F, which can only be placed in a private repo under consultation

## 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"
);
}
}