This repository has been archived by the owner on Aug 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 210
docs/tutorials/visualizing-node-metrics: Update to Prometheus endpoint #461
Merged
JoshOrndorff
merged 2 commits into
polkadot-developers:source
from
mxinden:update-metric-docs
Feb 19, 2020
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -2,94 +2,139 @@ | |
title: "Visualizing Node Metrics" | ||
--- | ||
|
||
Recent versions of Substrate record metrics, such as how many peers your node | ||
is connected to, how much memory your node is using, etc. To visualize these | ||
metrics, you can use a tool called [Grafana](https://grafana.com/). | ||
Recent versions of Substrate expose metrics, such as how many peers your node is | ||
connected to, how much memory your node is using, etc. To visualize these | ||
metrics, you can use tools like [Prometheus](https://prometheus.io/) and | ||
[Grafana](https://grafana.com/). | ||
|
||
## Step 1: Install and run Grafana | ||
> Note: In the past Substrate exposed a Grafana JSON endpoint directly. This has | ||
> been replaced with a Prometheus metric endpoint. | ||
|
||
If you're on | ||
macOS, the easiest way to do that is via [Homebrew](https://brew.sh/): | ||
A possible architecture could look like: | ||
|
||
```bash | ||
brew install grafana | ||
``` | ||
+-----------+ +-------------+ +---------+ | ||
| Substrate | | Prometheus | | Grafana | | ||
+-----------+ +-------------+ +---------+ | ||
| -----------------\ | | | ||
| | Every 1 minute |-| | | ||
| |----------------| | | | ||
| | | | ||
| GET current metric values | | | ||
|<---------------------------------| | | ||
| | | | ||
| `substrate_peers_count 5` | | | ||
|--------------------------------->| | | ||
| | --------------------------------------------------------------------\ | | ||
| |-| Save metric value with corresponding time stamp in local database | | | ||
| | |-------------------------------------------------------------------| | | ||
| | -------------------------------\ | | ||
| | | Every time user opens graphs |-| | ||
| | |------------------------------| | | ||
| | | | ||
| | GET values of metric `substrate_peers_count` from time-X to time-Y | | ||
| |<-------------------------------------------------------------------------| | ||
| | | | ||
| | `substrate_peers_count (1582023828, 5), (1582023847, 4) [...]` | | ||
| |------------------------------------------------------------------------->| | ||
| | | | ||
|
||
Grafana runs via a server, which you can run via `brew` with: | ||
|
||
```bash | ||
brew services start grafana | ||
``` | ||
|
||
Downloads for other platforms are available [here](https://grafana.com/grafana/download). | ||
<details> | ||
<summary>Reproduce diagram</summary> | ||
|
||
## Step 2: Install the Grafana JSON DataSource plugin: | ||
Go to: https://textart.io/sequence | ||
|
||
We use a simple JSON interface to serve metrics. The | ||
[Grafana JSON DataSource](https://github.com/simPod/grafana-json-datasource) plugin can be | ||
installed with: | ||
``` | ||
object Substrate Prometheus Grafana | ||
note left of Prometheus: Every 1 minute | ||
Prometheus->Substrate: GET current metric values | ||
Substrate->Prometheus: `substrate_peers_count 5` | ||
note right of Prometheus: Save metric value with corresponding time stamp in local database | ||
note left of Grafana: Every time user opens graphs | ||
Grafana->Prometheus: GET values of metric `substrate_peers_count` from time-X to time-Y | ||
Prometheus->Grafana: `substrate_peers_count (1582023828, 5), (1582023847, 4) [...]` | ||
``` | ||
|
||
</details> | ||
|
||
```bash | ||
grafana-cli plugins install simpod-json-datasource | ||
``` | ||
|
||
## Step 3: Run your node | ||
|
||
## Step 1: Run your node | ||
|
||
As long as you're running a version of Substrate at or after commit | ||
<!-- TODO: Update commit hash--> | ||
[`d9ca975`](https://github.com/paritytech/substrate/commit/d9ca9750dba018463d59459a3ee1c03b71ea2d46), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR is made against the |
||
a server serving metrics for Grafana will start on port `9955`. You can specify | ||
this port with `--grafana-port <PORT>` and enable it to be accessed over a | ||
network with `--grafana-external`. | ||
an endpoint serving metrics in the [Prometheus exposition | ||
format](https://prometheus.io/docs/concepts/data_model/) will be available on | ||
port `9615`. You can change the port with `--prometheus-port <PORT>` and enable | ||
it to be accessed over an interface other than local host with | ||
`--prometheus-external`. | ||
|
||
## Step 4: Set Up Grafana | ||
```bash | ||
./substrate | ||
``` | ||
|
||
We will not cover setting up and running Grafana in great detail - there's the | ||
[Getting Started guide](https://grafana.com/docs/guides/getting_started/) for | ||
that. Here are a few pointers though: | ||
## Step 2: Retrieve the metrics | ||
|
||
1. On the 'Add data source' screen, select the JSON data source in the | ||
'Others' section. | ||
2. Set the url of the running servers (e.g. | ||
`http://localhost:9955`) | ||
> NOTE: just `locahost::<PORT>` won't work. | ||
3. Click `Save & Test`. | ||
In a second terminal run: | ||
|
||
Grafana should ping the server and show that the data source is working: | ||
```bash | ||
curl localhost:9615/metrics | ||
``` | ||
|
||
![Data Source Config](/docs/assets/tutorials/grafana/datasource-config.png) | ||
Which should return a similar output to: | ||
|
||
Creating queries is a lot simpler than in other data sources. Simply click the | ||
drop-down and select the metric you want to visualize: | ||
``` | ||
# HELP substrate_block_height_number Height of the chain | ||
# TYPE substrate_block_height_number gauge | ||
substrate_block_height_number{status="best"} 12591 | ||
substrate_block_height_number{status="finalized"} 11776 | ||
substrate_block_height_number{status="sync_target"} 1236089 | ||
# HELP substrate_cpu_usage_percentage Node CPU usage | ||
# TYPE substrate_cpu_usage_percentage gauge | ||
substrate_cpu_usage_percentage 98.90908813476563 | ||
# HELP substrate_memory_usage_bytes Node memory usage | ||
# TYPE substrate_memory_usage_bytes gauge | ||
substrate_memory_usage_bytes 195504 | ||
# HELP substrate_network_per_sec_bytes Networking bytes per second | ||
# TYPE substrate_network_per_sec_bytes gauge | ||
substrate_network_per_sec_bytes{direction="download"} 4117 | ||
substrate_network_per_sec_bytes{direction="upload"} 437 | ||
# HELP substrate_peers_count Number of network gossip peers | ||
# TYPE substrate_peers_count gauge | ||
substrate_peers_count 3 | ||
# HELP substrate_ready_transactions_number Number of transactions in the ready queue | ||
# TYPE substrate_ready_transactions_number gauge | ||
substrate_ready_transactions_number 0 | ||
``` | ||
|
||
![Creating a query](/docs/assets/tutorials/grafana/metric-selection.png) | ||
## Next Steps | ||
|
||
## Step 5: Create Your Dashboard | ||
### Configure Prometheus to scrape your Substrate node | ||
|
||
Once you've done all that, you should be able to make a pretty neat node | ||
dashboard! | ||
https://prometheus.io/docs/guides/node-exporter/#configuring-your-prometheus-instances | ||
|
||
![Node Dashboard](/docs/assets/tutorials/grafana/dashboard.png) | ||
|
||
There's a lot of work still to be done on the metrics system. Hopefully, in the | ||
future you'll be able to log metrics from anywhere in the node runtime to a | ||
variety of databases, such as [Prometheus](https://prometheus.io/). | ||
### Visualizing Prometheus metrics with Grafana | ||
|
||
If you have any suggestions, feel free to file an issue on | ||
[the substrate repository](https://github.com/paritytech/substrate). | ||
https://prometheus.io/docs/visualization/grafana/ | ||
|
||
## Next Steps | ||
|
||
### Learn More | ||
|
||
- Learn how to [set up a private Substrate network](start-a-private-network). | ||
|
||
### Examples | ||
|
||
- Take a look at the Grafana dashboard configuration for the [Polkadot network](https://github.com/w3f/polkadot-dashboard). | ||
- Take a look at the Grafana dashboard configuration for the [Polkadot | ||
network](https://github.com/w3f/polkadot-dashboard). | ||
|
||
### References | ||
|
||
<!-- TODO: Update this to RUSTDOC link--> | ||
|
||
- Visit the source code for [grafana-data-source](https://github.com/paritytech/substrate/tree/master/client/grafana-data-source). | ||
- Visit the source code for | ||
[grafana-data-source](https://github.com/paritytech/substrate/tree/master/client/grafana-data-source). | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe some of the designers can help us out with this? @goldsteinsveta
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ultimately beautiful, but sure, I'll draw a scheme by the end of Friday
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I do agree that my diagram has a lot of room for improvement, I also want to emphasize the fact that one has to view it in markdown mode, otherwise tabs will not align properly.
❤️
🎉 @goldsteinsveta let me know if you need more details. I would expect the content to change a bit in the future, thus in case it is hard to do this in a way that is not easy to adapt, it might make sense to hold off a bit longer?