mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-05-04 07:02:16 +00:00
chore(metrics): move example to examples/
Related: #3111. Pull-Request: #3661.
This commit is contained in:
parent
7261856e7a
commit
f7c3db9d6b
21
Cargo.lock
generated
21
Cargo.lock
generated
@ -2580,24 +2580,16 @@ dependencies = [
|
|||||||
name = "libp2p-metrics"
|
name = "libp2p-metrics"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"env_logger 0.10.0",
|
|
||||||
"futures",
|
|
||||||
"hyper",
|
|
||||||
"libp2p-core",
|
"libp2p-core",
|
||||||
"libp2p-dcutr",
|
"libp2p-dcutr",
|
||||||
"libp2p-gossipsub",
|
"libp2p-gossipsub",
|
||||||
"libp2p-identify",
|
"libp2p-identify",
|
||||||
"libp2p-identity",
|
"libp2p-identity",
|
||||||
"libp2p-kad",
|
"libp2p-kad",
|
||||||
"libp2p-noise",
|
|
||||||
"libp2p-ping",
|
"libp2p-ping",
|
||||||
"libp2p-relay",
|
"libp2p-relay",
|
||||||
"libp2p-swarm",
|
"libp2p-swarm",
|
||||||
"libp2p-tcp",
|
|
||||||
"libp2p-yamux",
|
|
||||||
"log",
|
|
||||||
"prometheus-client",
|
"prometheus-client",
|
||||||
"tokio",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -3194,6 +3186,19 @@ dependencies = [
|
|||||||
"autocfg",
|
"autocfg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "metrics-example"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"env_logger 0.10.0",
|
||||||
|
"futures",
|
||||||
|
"hyper",
|
||||||
|
"libp2p",
|
||||||
|
"log",
|
||||||
|
"prometheus-client",
|
||||||
|
"tokio",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "minimal-lexical"
|
name = "minimal-lexical"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
|
@ -9,6 +9,7 @@ members = [
|
|||||||
"examples/identify",
|
"examples/identify",
|
||||||
"examples/ipfs-kad",
|
"examples/ipfs-kad",
|
||||||
"examples/ipfs-private",
|
"examples/ipfs-private",
|
||||||
|
"examples/metrics",
|
||||||
"examples/ping-example",
|
"examples/ping-example",
|
||||||
"examples/relay-server",
|
"examples/relay-server",
|
||||||
"examples/rendezvous",
|
"examples/rendezvous",
|
||||||
|
15
examples/metrics/Cargo.toml
Normal file
15
examples/metrics/Cargo.toml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
[package]
|
||||||
|
name = "metrics-example"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
publish = false
|
||||||
|
license = "MIT"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
env_logger = "0.10.0"
|
||||||
|
futures = "0.3.27"
|
||||||
|
hyper = { version = "0.14", features = ["server", "tcp", "http1"] }
|
||||||
|
libp2p = { path = "../../libp2p", features = ["async-std", "metrics", "ping", "noise", "identify", "tcp", "yamux", "macros"] }
|
||||||
|
log = "0.4.0"
|
||||||
|
tokio = { version = "1", features = ["rt-multi-thread"] }
|
||||||
|
prometheus-client = "0.19.0"
|
@ -23,13 +23,13 @@
|
|||||||
//! In one terminal run:
|
//! In one terminal run:
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
//! cargo run --example metrics
|
//! cargo run
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! In a second terminal run:
|
//! In a second terminal run:
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
//! cargo run --example metrics -- <listen-addr-of-first-node>
|
//! cargo run -- <listen-addr-of-first-node>
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! Where `<listen-addr-of-first-node>` is replaced by the listen address of the
|
//! Where `<listen-addr-of-first-node>` is replaced by the listen address of the
|
||||||
@ -51,16 +51,11 @@
|
|||||||
use env_logger::Env;
|
use env_logger::Env;
|
||||||
use futures::executor::block_on;
|
use futures::executor::block_on;
|
||||||
use futures::stream::StreamExt;
|
use futures::stream::StreamExt;
|
||||||
use libp2p_core::{upgrade::Version, Multiaddr, Transport};
|
use libp2p::core::{upgrade::Version, Multiaddr, Transport};
|
||||||
use libp2p_identify as identify;
|
use libp2p::identity::PeerId;
|
||||||
use libp2p_identity as identity;
|
use libp2p::metrics::{Metrics, Recorder};
|
||||||
use libp2p_identity::PeerId;
|
use libp2p::swarm::{keep_alive, NetworkBehaviour, SwarmBuilder, SwarmEvent};
|
||||||
use libp2p_metrics::{Metrics, Recorder};
|
use libp2p::{identify, identity, noise, ping, tcp, yamux};
|
||||||
use libp2p_noise as noise;
|
|
||||||
use libp2p_ping as ping;
|
|
||||||
use libp2p_swarm::{keep_alive, NetworkBehaviour, SwarmBuilder, SwarmEvent};
|
|
||||||
use libp2p_tcp as tcp;
|
|
||||||
use libp2p_yamux as yamux;
|
|
||||||
use log::info;
|
use log::info;
|
||||||
use prometheus_client::registry::Registry;
|
use prometheus_client::registry::Registry;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
@ -125,7 +120,6 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
/// For illustrative purposes, this includes the [`keep_alive::Behaviour`]) behaviour so the ping actually happen
|
/// For illustrative purposes, this includes the [`keep_alive::Behaviour`]) behaviour so the ping actually happen
|
||||||
/// and can be observed via the metrics.
|
/// and can be observed via the metrics.
|
||||||
#[derive(NetworkBehaviour)]
|
#[derive(NetworkBehaviour)]
|
||||||
#[behaviour(prelude = "libp2p_swarm::derive_prelude")]
|
|
||||||
struct Behaviour {
|
struct Behaviour {
|
||||||
identify: identify::Behaviour,
|
identify: identify::Behaviour,
|
||||||
keep_alive: keep_alive::Behaviour,
|
keep_alive: keep_alive::Behaviour,
|
@ -32,25 +32,9 @@ prometheus-client = "0.19.0"
|
|||||||
[target.'cfg(not(target_os = "unknown"))'.dependencies]
|
[target.'cfg(not(target_os = "unknown"))'.dependencies]
|
||||||
libp2p-gossipsub = { version = "0.44.0", path = "../../protocols/gossipsub", optional = true }
|
libp2p-gossipsub = { version = "0.44.0", path = "../../protocols/gossipsub", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
env_logger = "0.10.0"
|
|
||||||
futures = "0.3.28"
|
|
||||||
hyper = { version="0.14", features = ["server", "tcp", "http1"] }
|
|
||||||
libp2p-noise = { path = "../../transports/noise" }
|
|
||||||
libp2p-ping = { path = "../../protocols/ping" }
|
|
||||||
libp2p-swarm = { path = "../../swarm", features = ["macros"] }
|
|
||||||
libp2p-tcp = { path = "../../transports/tcp", features = ["async-io"] }
|
|
||||||
libp2p-yamux = { path = "../../muxers/yamux" }
|
|
||||||
log = "0.4.0"
|
|
||||||
tokio = { version = "1", features = ["rt-multi-thread"] }
|
|
||||||
|
|
||||||
# Passing arguments to the docsrs builder in order to properly document cfg's.
|
# Passing arguments to the docsrs builder in order to properly document cfg's.
|
||||||
# More information: https://docs.rs/about/builds#cross-compiling
|
# More information: https://docs.rs/about/builds#cross-compiling
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
all-features = true
|
all-features = true
|
||||||
rustdoc-args = ["--cfg", "docsrs"]
|
rustdoc-args = ["--cfg", "docsrs"]
|
||||||
rustc-args = ["--cfg", "docsrs"]
|
rustc-args = ["--cfg", "docsrs"]
|
||||||
|
|
||||||
[[example]]
|
|
||||||
name = "metrics"
|
|
||||||
required-features = ["ping", "identify"]
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user