-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* drop -> stop Signed-off-by: Dan Bond <[email protected]> * assert error enum Signed-off-by: Dan Bond <[email protected]> Signed-off-by: Dan Bond <[email protected]>
- Loading branch information
Showing
8 changed files
with
98 additions
and
50 deletions.
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 |
---|---|---|
|
@@ -9,7 +9,7 @@ on: | |
- main | ||
|
||
env: | ||
RUST_VERSION: 1.61 | ||
RUST_VERSION: 1.64 | ||
|
||
jobs: | ||
lint: | ||
|
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "metrics_server" | ||
version = "0.9.0" | ||
version = "0.10.0" | ||
authors = ["Dan Bond <[email protected]>"] | ||
edition = "2021" | ||
rust-version = "1.58" | ||
|
@@ -22,6 +22,7 @@ log = "0.4" | |
tiny_http = "0.11" | ||
|
||
[dev-dependencies] | ||
ctrlc = { version = "3.2", features = ["termination"] } | ||
prometheus-client = "0.18" | ||
reqwest = { version = "0.11", features = ["blocking"] } | ||
|
||
|
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
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 |
---|---|---|
@@ -1,35 +1,56 @@ | ||
use std::sync::atomic::{AtomicBool, Ordering}; | ||
use std::sync::Arc; | ||
use std::{thread, time}; | ||
|
||
use metrics_server::MetricsServer; | ||
use prometheus_client::encoding::text::encode; | ||
use prometheus_client::metrics::counter::Counter; | ||
use prometheus_client::registry::Registry; | ||
|
||
fn main() { | ||
// Create a metrics registry. | ||
let mut registry = Registry::default(); | ||
|
||
// Create a metric that represents a single monotonically increasing counter. | ||
let counter: Counter = Counter::default(); | ||
use metrics_server::MetricsServer; | ||
|
||
// Register a metric with the Registry. | ||
registry.register("some_count", "Number of random counts", counter.clone()); | ||
fn main() { | ||
// Register stop handler. | ||
let stop = Arc::new(AtomicBool::new(false)); | ||
let s = stop.clone(); | ||
ctrlc::set_handler(move || { | ||
s.store(true, Ordering::Relaxed); | ||
}) | ||
.unwrap(); | ||
|
||
// Expose the Prometheus metrics. | ||
let server = MetricsServer::http("localhost:8001"); | ||
println!("Starting metrics server: http://localhost:8001/metrics"); | ||
|
||
std::thread::scope(|s| { | ||
let handle = s.spawn(|| { | ||
// Create a metrics registry and counter that represents a single monotonically | ||
// increasing counter. | ||
let mut registry = Registry::default(); | ||
let counter: Counter = Counter::default(); | ||
registry.register("some_count", "Number of random counts", counter.clone()); | ||
|
||
// Increment the counter every 5 seconds. | ||
loop { | ||
if stop.load(Ordering::Relaxed) { | ||
break; | ||
} | ||
|
||
counter.inc(); | ||
|
||
// Encode the current Registry in Prometheus format. | ||
let mut encoded = Vec::new(); | ||
encode(&mut encoded, ®istry).unwrap(); | ||
|
||
// Increment the counter every 5 seconds. | ||
loop { | ||
counter.inc(); | ||
// Update the Metrics Server with the current encoded data. | ||
server.update(encoded); | ||
|
||
// Encode the current Registry in Prometheus format. | ||
let mut encoded = Vec::new(); | ||
encode(&mut encoded, ®istry).unwrap(); | ||
thread::sleep(time::Duration::from_secs(5)); | ||
} | ||
}); | ||
|
||
// Update the Metrics Server with the current encoded data. | ||
server.update(encoded); | ||
handle.join().unwrap(); | ||
}); | ||
|
||
let five_secs = time::Duration::from_secs(5); | ||
thread::sleep(five_secs); | ||
} | ||
// Stop server. | ||
server.stop().unwrap(); | ||
} |
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
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
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
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