#health-check #async

moon-healthcheck

An async healthcheck library for Rust

2 unstable releases

0.2.0 Apr 2, 2023
0.1.0 Apr 2, 2023

#4 in #healthcheck

MIT/Apache

76KB
1.5K SLoC

Moon Healthcheck

Build & Test codecov

An async healthcheck library for Rust.

Docs

https://docs.rs/moon-healthcheck


lib.rs:

Moon Healthcheck

An async healthcheck library for Rust.

Features

  • TCP healthcheck
  • HTTP healthcheck
    • HTTP GET, POST, PUT, DELETE, HEAD, PATCH
    • HTTP/1.1, HTTP/2
  • UDP healthcheck
  • Active (background) healthcheck
  • Passive (report manually) healthcheck

Examples

TCP healthcheck

use moon_healthcheck::tcp::TcpChecker;
use moon_healthcheck::dispatcher::Dispatcher;
use tokio::time::Duration;
use tokio::time::sleep;

#[tokio::main]
async fn main() {
    let mut dispatcher: Dispatcher<TcpChecker> = Dispatcher::new();
    
    let tcp_checker = TcpChecker::new("really.really.not.exists.host", 80, 1);
    let uuid = dispatcher.schedule(tcp_checker, Duration::from_secs(1)).unwrap();
    
    sleep(Duration::from_secs(3)).await;
    assert_eq!(dispatcher.is_healthy(&uuid).await.unwrap(), false);
}

UDP healthcheck

use moon_healthcheck::udp::UdpChecker;
use moon_healthcheck::dispatcher::Dispatcher;
use tokio::time::Duration;
use tokio::time::sleep;

#[tokio::main]
async fn main() {
    let mut dispatcher: Dispatcher<UdpChecker> = Dispatcher::new();

    let udp_checker = UdpChecker::new("really.really.not.exists.host", 53, &vec![1, 2, 3], &vec![1, 2, 3], 1);
    let uuid = dispatcher.schedule(udp_checker, Duration::from_secs(1)).unwrap();

    sleep(Duration::from_secs(3)).await;
    assert_eq!(dispatcher.is_healthy(&uuid).await.unwrap(), false);
}

HTTP healthcheck

use moon_healthcheck::http::HttpChecker;
use moon_healthcheck::dispatcher::Dispatcher;
use tokio::time::Duration;
use tokio::time::sleep;

#[tokio::main]
async fn main() {
    let mut dispatcher: Dispatcher<HttpChecker> = Dispatcher::new();

    let http_checker = HttpChecker::new("https://really.really.not.exists.host", 1);
    let uuid = dispatcher.schedule(http_checker, Duration::from_secs(1)).unwrap();

    sleep(Duration::from_secs(3)).await;
    assert_eq!(dispatcher.is_healthy(&uuid).await.unwrap(), false);
}

Dependencies

~6–18MB
~263K SLoC