diff --git a/Cargo.lock b/Cargo.lock index 439e7385..0520add0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2580,24 +2580,16 @@ dependencies = [ name = "libp2p-metrics" version = "0.12.0" dependencies = [ - "env_logger 0.10.0", - "futures", - "hyper", "libp2p-core", "libp2p-dcutr", "libp2p-gossipsub", "libp2p-identify", "libp2p-identity", "libp2p-kad", - "libp2p-noise", "libp2p-ping", "libp2p-relay", "libp2p-swarm", - "libp2p-tcp", - "libp2p-yamux", - "log", "prometheus-client", - "tokio", ] [[package]] @@ -3194,6 +3186,19 @@ dependencies = [ "autocfg", ] +[[package]] +name = "metrics-example" +version = "0.1.0" +dependencies = [ + "env_logger 0.10.0", + "futures", + "hyper", + "libp2p", + "log", + "prometheus-client", + "tokio", +] + [[package]] name = "minimal-lexical" version = "0.2.1" diff --git a/Cargo.toml b/Cargo.toml index 739a366a..280eb094 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ members = [ "examples/identify", "examples/ipfs-kad", "examples/ipfs-private", + "examples/metrics", "examples/ping-example", "examples/relay-server", "examples/rendezvous", diff --git a/examples/metrics/Cargo.toml b/examples/metrics/Cargo.toml new file mode 100644 index 00000000..32d745e8 --- /dev/null +++ b/examples/metrics/Cargo.toml @@ -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" diff --git a/misc/metrics/examples/metrics/http_service.rs b/examples/metrics/src/http_service.rs similarity index 100% rename from misc/metrics/examples/metrics/http_service.rs rename to examples/metrics/src/http_service.rs diff --git a/misc/metrics/examples/metrics/main.rs b/examples/metrics/src/main.rs similarity index 89% rename from misc/metrics/examples/metrics/main.rs rename to examples/metrics/src/main.rs index 9914a19a..789b5341 100644 --- a/misc/metrics/examples/metrics/main.rs +++ b/examples/metrics/src/main.rs @@ -23,13 +23,13 @@ //! In one terminal run: //! //! ``` -//! cargo run --example metrics +//! cargo run //! ``` //! //! In a second terminal run: //! //! ``` -//! cargo run --example metrics -- +//! cargo run -- //! ``` //! //! Where `` is replaced by the listen address of the @@ -51,16 +51,11 @@ use env_logger::Env; use futures::executor::block_on; use futures::stream::StreamExt; -use libp2p_core::{upgrade::Version, Multiaddr, Transport}; -use libp2p_identify as identify; -use libp2p_identity as identity; -use libp2p_identity::PeerId; -use libp2p_metrics::{Metrics, Recorder}; -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 libp2p::core::{upgrade::Version, Multiaddr, Transport}; +use libp2p::identity::PeerId; +use libp2p::metrics::{Metrics, Recorder}; +use libp2p::swarm::{keep_alive, NetworkBehaviour, SwarmBuilder, SwarmEvent}; +use libp2p::{identify, identity, noise, ping, tcp, yamux}; use log::info; use prometheus_client::registry::Registry; use std::error::Error; @@ -125,7 +120,6 @@ fn main() -> Result<(), Box> { /// For illustrative purposes, this includes the [`keep_alive::Behaviour`]) behaviour so the ping actually happen /// and can be observed via the metrics. #[derive(NetworkBehaviour)] -#[behaviour(prelude = "libp2p_swarm::derive_prelude")] struct Behaviour { identify: identify::Behaviour, keep_alive: keep_alive::Behaviour, diff --git a/misc/metrics/Cargo.toml b/misc/metrics/Cargo.toml index efb09236..d1e44165 100644 --- a/misc/metrics/Cargo.toml +++ b/misc/metrics/Cargo.toml @@ -32,25 +32,9 @@ prometheus-client = "0.19.0" [target.'cfg(not(target_os = "unknown"))'.dependencies] 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. # More information: https://docs.rs/about/builds#cross-compiling [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] rustc-args = ["--cfg", "docsrs"] - -[[example]] -name = "metrics" -required-features = ["ping", "identify"]