docs(examples): add a README to each example

Resolves #3853.

Pull-Request: #3974.
This commit is contained in:
Thomas Coratger
2023-06-01 09:40:22 +02:00
committed by GitHub
parent 87e863e8c9
commit 75edcfcdb0
26 changed files with 501 additions and 223 deletions

View File

@@ -0,0 +1,40 @@
## Description
The example showcases how to run a p2p network with **libp2p** and collect metrics using `libp2p-metrics`.
It sets up multiple nodes in the network and measures various metrics, such as `libp2p_ping`, to evaluate the network's performance.
## Usage
To run the example, follow these steps:
1. Run the following command to start the first node:
```sh
cargo run
```
2. Open a second terminal and run the following command to start a second node:
```sh
cargo run -- <listen-addr-of-first-node>
```
Replace `<listen-addr-of-first-node>` with the listen address of the first node reported in the first terminal.
Look for the line that says `NewListenAddr` to find the address.
3. Open a third terminal and run the following command to retrieve the metrics from either the first or second node:
```sh
curl localhost:<metrics-port-of-first-or-second-node>/metrics
```
Replace `<metrics-port-of-first-or-second-node>` with the listen port of the metrics server of either the first or second node.
Look for the line that says `tide::server Server listening on` to find the port.
After executing the command, you should see a long list of metrics printed to the terminal.
Make sure to check the `libp2p_ping` metrics, which should have a value greater than zero (`>0`).
## Conclusion
This example demonstrates how to utilize the `libp2p-metrics` crate to collect and analyze metrics in a libp2p network.
By running multiple nodes and examining the metrics, users can gain insights into the network's performance and behavior.

View File

@@ -18,35 +18,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//! Example demonstrating `libp2p-metrics`.
//!
//! In one terminal run:
//!
//! ```
//! cargo run
//! ```
//!
//! In a second terminal run:
//!
//! ```
//! cargo run -- <listen-addr-of-first-node>
//! ```
//!
//! Where `<listen-addr-of-first-node>` is replaced by the listen address of the
//! first node reported in the first terminal. Look for `NewListenAddr`.
//!
//! In a third terminal run:
//!
//! ```
//! curl localhost:<metrics-port-of-first-or-second-node>/metrics
//! ```
//!
//! Where `<metrics-port-of-first-or-second-node>` is replaced by the listen
//! port of the metrics server of the first or the second node. Look for
//! `tide::server Server listening on`.
//!
//! You should see a long list of metrics printed to the terminal. Check the
//! `libp2p_ping` metrics, they should be `>0`.
#![doc = include_str!("../README.md")]
use env_logger::Env;
use futures::executor::block_on;