Compare commits

...

2 commits

Author SHA1 Message Date
Jan Christian Grünhage 44251fa2f7
bump version to 0.2.3 2020-04-08 12:02:54 +02:00
Jan Christian Grünhage 0448980dd9
fix interval timings for concurrent pings 2020-04-08 12:01:19 +02:00
5 changed files with 13 additions and 14 deletions

View file

@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
## [v0.2.3] - 2020-04-08
### Fixed
- fix interval timings concurrent pings
## [v0.2.2] - 2020-04-06 ## [v0.2.2] - 2020-04-06
### Added ### Added
- added documentation to the sample config file - added documentation to the sample config file

2
Cargo.lock generated
View file

@ -430,7 +430,7 @@ dependencies = [
[[package]] [[package]]
name = "peshming" name = "peshming"
version = "0.2.2" version = "0.2.3"
dependencies = [ dependencies = [
"chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "peshming" name = "peshming"
version = "0.2.2" version = "0.2.3"
authors = ["Jan Christian Grünhage <jan.christian@gruenhage.xyz>"] authors = ["Jan Christian Grünhage <jan.christian@gruenhage.xyz>"]
edition = "2018" edition = "2018"
description = "Pings configured hosts in a configurable intervals and exposes metrics for prometheus." description = "Pings configured hosts in a configurable intervals and exposes metrics for prometheus."

View file

@ -10,7 +10,7 @@ someone comes up with something better.
### Usage: ### Usage:
``` ```
$ peshming --help $ peshming --help
peshming 0.2.2 peshming 0.2.3
Jan Christian Grünhage <jan.christian@gruenhage.xyz> Jan Christian Grünhage <jan.christian@gruenhage.xyz>
Pings configured hosts in a configurable intervals and exposes metrics for prometheus. Pings configured hosts in a configurable intervals and exposes metrics for prometheus.

View file

@ -18,13 +18,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * * along with this program. If not, see <https://www.gnu.org/licenses/>. *
********************************************************************************/ ********************************************************************************/
use crate::config::Config; use crate::config::Config;
use futures_util::stream::StreamExt;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use log::{error, info, trace}; use log::{error, info, trace};
use prometheus::*; use prometheus::*;
use std::net::IpAddr; use std::net::IpAddr;
use std::time::Duration; use std::time::Duration;
use tokio_ping::Pinger; use tokio_ping::{PingFuture, Pinger};
lazy_static! { lazy_static! {
static ref PING_HISTOGRAM: HistogramVec = register_histogram_vec!( static ref PING_HISTOGRAM: HistogramVec = register_histogram_vec!(
@ -58,21 +57,17 @@ pub(crate) async fn start_pinging_hosts(
} }
async fn ping_host(pinger: Pinger, host: IpAddr, interval: u64) { async fn ping_host(pinger: Pinger, host: IpAddr, interval: u64) {
let pingchain = pinger.chain(host).timeout(Duration::from_secs(3)); let mut pingchain = pinger.chain(host).timeout(Duration::from_secs(3));
let host = host.to_string();
let mut stream = pingchain.stream();
let mut interval = tokio::time::interval(Duration::from_millis(interval)); let mut interval = tokio::time::interval(Duration::from_millis(interval));
let host_string = host.to_string();
loop { loop {
interval.tick().await; interval.tick().await;
handle_ping_result(stream.next().await.unwrap(), &host).await; tokio::spawn(handle_ping_result(pingchain.send(), host_string.clone()));
} }
} }
async fn handle_ping_result( async fn handle_ping_result(result: PingFuture, host: String) {
result: std::result::Result<Option<Duration>, tokio_ping::Error>, let pong = match result.await {
host: &str,
) {
let pong = match result {
Ok(pong) => pong, Ok(pong) => pong,
Err(error) => { Err(error) => {
error!("Couldn't ping {}: {}", &host, error); error!("Couldn't ping {}: {}", &host, error);