Update cpu and memory event code

Co-Authored-By: Julia <30666851+ForLoveOfCats@users.noreply.github.com>
This commit is contained in:
Joseph T. Lyons 2023-10-03 13:27:32 -04:00
parent cf5d89d13c
commit b10255a6dd

View File

@ -90,14 +90,12 @@ pub enum ClickhouseEvent {
model: &'static str, model: &'static str,
}, },
Cpu { Cpu {
usage_as_percent: f32, usage_as_percentage: f32,
core_count: u32, core_count: u32,
}, },
Memory { Memory {
memory_in_bytes: u64, memory_in_bytes: u64,
virtual_memory_in_bytes: u64, virtual_memory_in_bytes: u64,
start_time_in_seconds: u64,
run_time_in_seconds: u64,
}, },
} }
@ -168,8 +166,6 @@ impl Telemetry {
const DURATION_BETWEEN_SYSTEM_EVENTS: Duration = Duration::from_secs(60); const DURATION_BETWEEN_SYSTEM_EVENTS: Duration = Duration::from_secs(60);
smol::Timer::after(DURATION_BETWEEN_SYSTEM_EVENTS).await; smol::Timer::after(DURATION_BETWEEN_SYSTEM_EVENTS).await;
let telemetry_settings = cx.update(|cx| *settings::get::<TelemetrySettings>(cx));
system.refresh_memory(); system.refresh_memory();
system.refresh_processes(); system.refresh_processes();
@ -184,15 +180,15 @@ impl Telemetry {
let memory_event = ClickhouseEvent::Memory { let memory_event = ClickhouseEvent::Memory {
memory_in_bytes: process.memory(), memory_in_bytes: process.memory(),
virtual_memory_in_bytes: process.virtual_memory(), virtual_memory_in_bytes: process.virtual_memory(),
start_time_in_seconds: process.start_time(),
run_time_in_seconds: process.run_time(),
}; };
let cpu_event = ClickhouseEvent::Cpu { let cpu_event = ClickhouseEvent::Cpu {
usage_as_percent: process.cpu_usage(), usage_as_percentage: process.cpu_usage(),
core_count: system.cpus().len() as u32, core_count: system.cpus().len() as u32,
}; };
let telemetry_settings = cx.update(|cx| *settings::get::<TelemetrySettings>(cx));
this.report_clickhouse_event(memory_event, telemetry_settings); this.report_clickhouse_event(memory_event, telemetry_settings);
this.report_clickhouse_event(cpu_event, telemetry_settings); this.report_clickhouse_event(cpu_event, telemetry_settings);
} }