diff --git a/config/endstat_conf.example.ron b/config/endstat_conf.example.ron
index 0675bb0..c8e6210 100644
--- a/config/endstat_conf.example.ron
+++ b/config/endstat_conf.example.ron
@@ -35,6 +35,7 @@
endpoints:[
(label: "The code doesn't match!", endpoint: "http://example.com/", code: 204),
(label: "The body doesn't match!", endpoint: "http://example.com/", body: "asdf"),
+ (label: "Slow reponse time", endpoint: "http://slowwly.robertomurray.co.uk/delay/2000/url/"),
(label: "Here's an error:", endpoint: "https://some-invalid-website.arpa")
]
),
diff --git a/config/templates/index.html b/config/templates/index.html
index 41f8bab..ad91b58 100644
--- a/config/templates/index.html
+++ b/config/templates/index.html
@@ -68,10 +68,11 @@
+ {{ status.location }}
{% if status.error %}{{ status.error }}
{% endif %}
-
+
{% endfor -%}
{% endfor -%}
diff --git a/src/handlers.rs b/src/handlers.rs
index 59f8083..019cf02 100644
--- a/src/handlers.rs
+++ b/src/handlers.rs
@@ -12,24 +12,27 @@ pub struct EndpointStatus {
pub status: u8,
pub location: String,
pub endpoint: String,
+ pub rtt: Option,
pub error: Option,
}
impl EndpointStatus {
- pub fn ok(location: String, endpoint: String) -> Self {
+ pub fn ok(location: String, endpoint: String, rtt: String) -> Self {
EndpointStatus {
status: 0,
location,
endpoint,
+ rtt: Some(rtt),
error: None,
}
}
- pub fn warn(location: String, endpoint: String, error: Option) -> Self {
+ pub fn warn(location: String, endpoint: String, rtt: String, error: Option) -> Self {
EndpointStatus {
status: 1,
location,
endpoint,
+ rtt: Some(rtt),
error,
}
}
@@ -39,6 +42,7 @@ impl EndpointStatus {
status: 2,
location,
endpoint,
+ rtt: None,
error,
}
}
diff --git a/src/main.rs b/src/main.rs
index 525d86d..4d18311 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,5 @@
+#![forbid(unsafe_code)]
+
extern crate actix;
extern crate actix_web;
extern crate chrono;
diff --git a/src/updater.rs b/src/updater.rs
index 69065ce..c295891 100644
--- a/src/updater.rs
+++ b/src/updater.rs
@@ -3,7 +3,7 @@ use crate::{
handlers::{EndpointStatus, StatusGroup},
State,
};
-use chrono::prelude::Utc;
+use chrono::Utc;
use reqwest::{Client, RedirectPolicy, Url, UrlError};
use ring::{
digest::{digest, SHA256},
@@ -51,8 +51,14 @@ fn get_result(
) -> EndpointStatus {
let (label, path, port, code, body) = get_endpoint_info(endpoint.clone());
let url = get_url(&website_conf.base, &path, port).expect("reading config");
+ let ping_start = Utc::now();
let ping_result = client.get(&url).send();
-
+ let duration = Utc::now() - ping_start;
+ let duration = if duration.num_seconds() > 0 {
+ format!("{}s", duration.num_milliseconds() as f64 / 1000.)
+ } else {
+ format!("{}ms", duration.num_milliseconds())
+ };
match ping_result {
Ok(mut res) => {
let res_body = res.text().expect("could not get body of request");
@@ -90,14 +96,14 @@ fn get_result(
}
if error.is_some() {
- EndpointStatus::warn(url, label, error)
+ EndpointStatus::warn(url, label, duration, error)
} else {
- EndpointStatus::ok(url, label)
+ EndpointStatus::ok(url, label, duration)
}
}
Err(e) => {
if let Some(true) = endpoint.should_err {
- EndpointStatus::ok(url, label)
+ EndpointStatus::ok(url, label, duration)
} else {
EndpointStatus::error(url, label, Some(format!("{}", e)))
}