Skip to content

Commit

Permalink
feat: display mem & cpu in /status
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Feb 26, 2024
1 parent 18a2209 commit e7dacfb
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion buildit-utils/src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ use jsonwebtoken::EncodingKey;
use log::{debug, error, info};
use octocrab::{models::pulls::PullRequest, params};
use std::{
borrow::Cow, collections::{HashMap, HashSet}, fs, io::{BufRead, BufReader}, path::{Path, PathBuf}, process::Output
borrow::Cow,
collections::{HashMap, HashSet},
fs,
io::{BufRead, BufReader},
path::{Path, PathBuf},
process::Output,
};
use tokio::{process, task};
use walkdir::WalkDir;
Expand Down
1 change: 1 addition & 0 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ tokio = { version = "1.36.0", features = ["macros", "rt-multi-thread", "process"
console = "0.15.8"
buildit-utils = { path = "../buildit-utils" }
jsonwebtoken = "9.2.0"
size = "0.4.1"
4 changes: 3 additions & 1 deletion server/src/bot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,15 @@ async fn status(args: &Args) -> anyhow::Result<String> {
if let Ok(lock) = WORKERS.lock() {
for (identifier, status) in lock.iter() {
res += &teloxide::utils::markdown::escape(&format!(
"{} ({}{}): Online as of {}\n",
"{} ({}{}, {} core(s), {} memory): Online as of {}\n",
identifier.hostname,
identifier.arch,
match &status.git_commit {
Some(git_commit) => format!(" {}", git_commit),
None => String::new(),
},
status.logical_cores,
size::Size::from_bytes(status.memory_bytes),
fmt.convert_chrono(status.last_heartbeat, Local::now())
));
}
Expand Down
4 changes: 4 additions & 0 deletions server/src/heartbeat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,16 @@ pub async fn heartbeat_worker_inner(amqp_addr: String) -> anyhow::Result<()> {
if let Some(status) = lock.get_mut(&heartbeat.identifier) {
status.last_heartbeat = Local::now();
status.git_commit = heartbeat.git_commit;
status.logical_cores = heartbeat.logical_cores;
status.memory_bytes = heartbeat.memory_bytes;
} else {
lock.insert(
heartbeat.identifier.clone(),
WorkerStatus {
last_heartbeat: Local::now(),
git_commit: heartbeat.git_commit,
logical_cores: heartbeat.logical_cores,
memory_bytes: heartbeat.memory_bytes,
},
);
}
Expand Down
2 changes: 2 additions & 0 deletions server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub mod job;
pub struct WorkerStatus {
pub last_heartbeat: DateTime<Local>,
pub git_commit: Option<String>,
pub logical_cores: u64,
pub memory_bytes: u64,
}

pub static WORKERS: Lazy<Arc<Mutex<BTreeMap<WorkerIdentifier, WorkerStatus>>>> =
Expand Down

0 comments on commit e7dacfb

Please sign in to comment.