Skip to content

Commit

Permalink
Update metrics dependency from 0.21.0 to 0.22.0 (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
zohnannor authored Dec 27, 2023
1 parent 4882190 commit 0a12cef
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 58 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ jobs:
cargo fmt --version
- name: Format
run: |
cargo fmt
- name: Diff check
run: |
test -z "$(git status -s)"
cargo fmt --check
check:
runs-on: ubuntu-latest
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ description = "Cross-platform Prometheus style process metrics collector of metr
repository = "https://github.com/lambdalisue/rs-metrics-process"
license = "MIT"
readme = "README.md"
keywords = ["cross-platform", "metrics", "prometheus", "open-metrics", "process"]
keywords = [ "cross-platform", "metrics", "prometheus", "open-metrics", "process", ]

[package.metadata.docs.rs]
all-features = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
metrics = "0.21.0"
metrics = "0.22.0"

[target.'cfg(target_os = "macos")'.dependencies]
libproc = "0.14.2"
Expand All @@ -39,5 +39,5 @@ features = [
[dev-dependencies]
assert_matches = "1.5.0"
axum = "0.7.2"
metrics-exporter-prometheus = "0.12.0"
metrics-exporter-prometheus = "0.13.0"
tokio = { version = "1.20.1", features = ["full"] }
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@

# ⏱ metrics-process

This crate provides [Prometheus][] style [process metrics][] collector of [metrics][] crate for Linux, macOS, and Windows.
Collector code is manually re-written to Rust from an official prometheus client of go ([client_golang][])
This crate provides [Prometheus] style [process metrics] collector of [metrics] crate for Linux, macOS, and Windows.
Collector code is manually re-written to Rust from an official prometheus client of go ([client_golang])

[prometheus]: https://prometheus.io/
[process metrics]: https://prometheus.io/docs/instrumenting/writing_clientlibs/#process-metrics
[metrics]: https://crates.io/crates/metrics

## Supported metrics

This crate supports the following metrics, equal to what official prometheus client of go ([client_golang][]) provides.
This crate supports the following metrics, equal to what official prometheus client of go ([client_golang]) provides.

| Metric name | Help string | Linux | macOS | Windows |
| ---------------------------------- | ------------------------------------------------------ | ----- | ----- | ------- |
Expand All @@ -35,7 +35,7 @@ This crate supports the following metrics, equal to what official prometheus cli

## Usage

Use this crate with [metrics-exporter-prometheus][] as an exporter like:
Use this crate with [metrics-exporter-prometheus] as an exporter like:

[metrics-exporter-prometheus]: https://crates.io/crates/metrics-exporter-prometheus

Expand Down Expand Up @@ -63,15 +63,16 @@ loop {
}
```

Or with [axum][] (or any web application framework you like) to collect metrics whenever
Or with [axum] (or any web application framework you like) to collect metrics whenever
the `/metrics` endpoint is invoked like:

[axum]: https://crates.io/crates/axum

```rust
use axum::{routing::get, Router, Server};
use axum::{routing::get, Router};
use metrics_exporter_prometheus::PrometheusBuilder;
use metrics_process::Collector;
use tokio::net::TcpListener;

#[tokio::main]
async fn main() {
Expand All @@ -93,16 +94,14 @@ async fn main() {
std::future::ready(handle.render())
}),
);
Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();
let listener = TcpListener::bind("127.0.0.1:9000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
```

## Difference from [metrics-process-promstyle][]
## Difference from [metrics-process-promstyle]

It seems [metrics-process-promstyle][] only support Linux but this crate (metrics-process) supports Linux, macOS, and Windows.
It seems [metrics-process-promstyle] only support Linux but this crate (metrics-process) supports Linux, macOS, and Windows.
Additionally, this crate supports `process_open_fds` and `process_max_fds` addition to what metrics-process-promstyle supports.

[metrics-process-promstyle]: https://crates.io/crates/metrics-process-promstyle
Expand Down
6 changes: 3 additions & 3 deletions examples/basic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
metrics = "0.20.1"
metrics-exporter-prometheus = "0.11.0"
metrics-process = { path = "../../"}
metrics = "0.22.0"
metrics-exporter-prometheus = "0.13.0"
metrics-process = { path = "../../" }
rand = "0.8.5"
2 changes: 1 addition & 1 deletion examples/basic/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# basic

An example code of `metrics-process` with [metrics-exporter-prometheus][].
An example code of `metrics-process` with [metrics-exporter-prometheus].

[metrics-exporter-prometheus]: https://crates.io/crates/metrics-exporter-prometheus

Expand Down
8 changes: 4 additions & 4 deletions examples/with_axum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
axum = "0.5.15"
metrics = "0.20.1"
metrics-exporter-prometheus = { version = "0.11.0", default-features = false }
metrics-process = { path = "../../"}
axum = "0.7.2"
metrics = "0.22.0"
metrics-exporter-prometheus = { version = "0.13.0", default-features = false }
metrics-process = { path = "../../" }
tokio = { version = "1.20.1", features = ["full"] }
2 changes: 1 addition & 1 deletion examples/with_axum/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# with_axum

An example of `metrics-process` crate with [axum][] and [metrics-exporter-prometheus][].
An example of `metrics-process` crate with [axum] and [metrics-exporter-prometheus].

[axum]: https://crates.io/crates/axum
[metrics-exporter-prometheus]: https://crates.io/crates/metrics-exporter-prometheus
Expand Down
10 changes: 4 additions & 6 deletions examples/with_axum/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use axum::{routing::get, Router, Server};
use axum::{routing::get, Router};
use metrics_exporter_prometheus::PrometheusBuilder;
use metrics_process::Collector;
use tokio::net::TcpListener;

#[tokio::main]
async fn main() {
Expand All @@ -13,7 +14,6 @@ async fn main() {
// Call `describe()` method to register help string.
collector.describe();

let addr = "127.0.0.1:9000".parse().unwrap();
let app = Router::new().route(
"/metrics",
get(move || {
Expand All @@ -22,8 +22,6 @@ async fn main() {
std::future::ready(handle.render())
}),
);
Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();
let listener = TcpListener::bind("127.0.0.1:9000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
44 changes: 20 additions & 24 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! This crate provides [Prometheus][] style [process metrics][] collector of [metrics][] crate for Linux, macOS, and Windows.
//! Collector code is manually re-written to Rust from an official prometheus client of go ([client_golang][])
//! This crate provides [Prometheus] style [process metrics] collector of [metrics] crate for Linux, macOS, and Windows.
//! Collector code is manually re-written to Rust from an official prometheus client of go ([client_golang])
//!
//! [Prometheus]: https://prometheus.io/
//! [process metrics]: https://prometheus.io/docs/instrumenting/writing_clientlibs/#process-metrics
//! [metrics]: https://crates.io/crates/metrics
//!
//! # Supported metrics
//!
//! This crate supports the following metrics, equal to what official prometheus client of go ([client_golang][]) provides.
//! This crate supports the following metrics, equal to what official prometheus client of go ([client_golang]) provides.
//!
//! | Metric name | Help string | Linux | macOS | Windows |
//! | ---------------------------------- | ------------------------------------------------------ | ----- | ----- | ------- |
Expand All @@ -25,7 +25,7 @@
//!
//! # Usage
//!
//! Use this crate with [metrics-exporter-prometheus][] as an exporter like:
//! Use this crate with [metrics-exporter-prometheus] as an exporter like:
//!
//! [metrics-exporter-prometheus]: https://crates.io/crates/metrics-exporter-prometheus
//!
Expand Down Expand Up @@ -53,15 +53,16 @@
//! }
//! ```
//!
//! Or with [axum][] (or any web application framework you like) to collect metrics whenever
//! Or with [axum] (or any web application framework you like) to collect metrics whenever
//! the `/metrics` endpoint is invoked like:
//!
//! [axum]: https://crates.io/crates/axum
//!
//! ```no_run
//! use axum::{routing::get, Router, Server};
//! use axum::{routing::get, Router};
//! use metrics_exporter_prometheus::PrometheusBuilder;
//! use metrics_process::Collector;
//! use tokio::net::TcpListener;
//!
//! #[tokio::main]
//! async fn main() {
Expand All @@ -74,7 +75,6 @@
//! // Call `describe()` method to register help string.
//! collector.describe();
//!
//! let addr = "127.0.0.1:9000".parse().unwrap();
//! let app = Router::new().route(
//! "/metrics",
//! get(move || {
Expand All @@ -83,19 +83,18 @@
//! std::future::ready(handle.render())
//! }),
//! );
//! Server::bind(&addr)
//! .serve(app.into_make_service())
//! .await
//! .unwrap();
//! let listener = TcpListener::bind("127.0.0.1:3000").await.unwrap();
//! axum::serve(listener, app).await.unwrap();
//! }
//! ```
//!
//! # Difference from [metrics-process-promstyle][]
//! # Difference from [metrics-process-promstyle]
//!
//! It seems [metrics-process-promstyle][] only support Linux but this crate (metrics-process) supports Linux, macOS, and Windows.
//! It seems [metrics-process-promstyle] only support Linux but this crate (metrics-process) supports Linux, macOS, and Windows.
//! Additionally, this crate supports `process_open_fds` and `process_max_fds` addition to what metrics-process-promstyle supports.
//!
//! [metrics-process-promstyle]: https://crates.io/crates/metrics-process-promstyle
mod collector;

use metrics::{describe_gauge, gauge, Unit};
Expand Down Expand Up @@ -220,33 +219,30 @@ impl Collector {
let prefix = &self.prefix;
let mut m = collector::collect();
if let Some(v) = m.cpu_seconds_total.take() {
gauge!(format!("{}process_cpu_seconds_total", prefix), v);
gauge!(format!("{}process_cpu_seconds_total", prefix)).set(v);
}
if let Some(v) = m.open_fds.take() {
gauge!(format!("{}process_open_fds", prefix), v as f64);
gauge!(format!("{}process_open_fds", prefix)).set(v as f64);
}
if let Some(v) = m.max_fds.take() {
gauge!(format!("{}process_max_fds", prefix), v as f64);
gauge!(format!("{}process_max_fds", prefix)).set(v as f64);
}
if let Some(v) = m.virtual_memory_bytes.take() {
gauge!(format!("{}process_virtual_memory_bytes", prefix), v as f64);
gauge!(format!("{}process_virtual_memory_bytes", prefix)).set(v as f64);
}
#[cfg(not(target_os = "windows"))]
if let Some(v) = m.virtual_memory_max_bytes.take() {
gauge!(
format!("{}process_virtual_memory_max_bytes", prefix),
v as f64,
);
gauge!(format!("{}process_virtual_memory_max_bytes", prefix)).set(v as f64);
}
if let Some(v) = m.resident_memory_bytes.take() {
gauge!(format!("{}process_resident_memory_bytes", prefix), v as f64);
gauge!(format!("{}process_resident_memory_bytes", prefix)).set(v as f64);
}
if let Some(v) = m.start_time_seconds.take() {
gauge!(format!("{}process_start_time_seconds", prefix), v as f64);
gauge!(format!("{}process_start_time_seconds", prefix)).set(v as f64);
}
#[cfg(not(target_os = "windows"))]
if let Some(v) = m.threads.take() {
gauge!(format!("{}process_threads", prefix), v as f64);
gauge!(format!("{}process_threads", prefix)).set(v as f64);
}
}
}

0 comments on commit 0a12cef

Please sign in to comment.