Using heartbeat api instead
This commit is contained in:
parent
4cedb17b60
commit
d024280878
10 changed files with 319 additions and 40 deletions
28
src/heartbeat/parser.rs
Normal file
28
src/heartbeat/parser.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
use anyhow::{Context, Ok, Result};
|
||||
use std::collections::HashMap;
|
||||
use crate::i18n::t;
|
||||
use super::HeartbeatResponse;
|
||||
|
||||
pub fn parse_response(json_text: &str) -> Result<HeartbeatResponse> {
|
||||
let mut response: HeartbeatResponse = serde_json::from_str(json_text)
|
||||
.with_context(|| t("invalid-json-heartbeat"))?;
|
||||
|
||||
response.process()?;
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
pub fn status_to_string(status: u8) -> String {
|
||||
match status {
|
||||
1 => t("up"),
|
||||
2 => t("down"),
|
||||
_ => t("unknown"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn format_duration(duration_ms:Option<u64>) -> String {
|
||||
match duration_ms {
|
||||
Some(ms) if ms < 1000 => format!("{}ms", ms),
|
||||
Some(ms) => format!("{:.1}s", ms),
|
||||
None => "N/A".to_string(),
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue