commit
7d32a717af
6 changed files with 65 additions and 9 deletions
5
Cargo.lock
generated
5
Cargo.lock
generated
|
@ -1415,6 +1415,7 @@ dependencies = [
|
||||||
"settings",
|
"settings",
|
||||||
"smol",
|
"smol",
|
||||||
"sum_tree",
|
"sum_tree",
|
||||||
|
"sysinfo",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"text",
|
"text",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
|
@ -7607,9 +7608,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sysinfo"
|
name = "sysinfo"
|
||||||
version = "0.27.8"
|
version = "0.29.10"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a902e9050fca0a5d6877550b769abd2bd1ce8c04634b941dbe2809735e1a1e33"
|
checksum = "0a18d114d420ada3a891e6bc8e96a2023402203296a47cdd65083377dad18ba5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"core-foundation-sys 0.8.3",
|
"core-foundation-sys 0.8.3",
|
||||||
|
|
|
@ -111,6 +111,7 @@ serde_derive = { version = "1.0", features = ["deserialize_in_place"] }
|
||||||
serde_json = { version = "1.0", features = ["preserve_order", "raw_value"] }
|
serde_json = { version = "1.0", features = ["preserve_order", "raw_value"] }
|
||||||
smallvec = { version = "1.6", features = ["union"] }
|
smallvec = { version = "1.6", features = ["union"] }
|
||||||
smol = { version = "1.2" }
|
smol = { version = "1.2" }
|
||||||
|
sysinfo = "0.29.10"
|
||||||
tempdir = { version = "0.3.7" }
|
tempdir = { version = "0.3.7" }
|
||||||
thiserror = { version = "1.0.29" }
|
thiserror = { version = "1.0.29" }
|
||||||
time = { version = "0.3", features = ["serde", "serde-well-known"] }
|
time = { version = "0.3", features = ["serde", "serde-well-known"] }
|
||||||
|
|
|
@ -33,15 +33,16 @@ parking_lot.workspace = true
|
||||||
postage.workspace = true
|
postage.workspace = true
|
||||||
rand.workspace = true
|
rand.workspace = true
|
||||||
schemars.workspace = true
|
schemars.workspace = true
|
||||||
|
serde.workspace = true
|
||||||
|
serde_derive.workspace = true
|
||||||
smol.workspace = true
|
smol.workspace = true
|
||||||
|
sysinfo.workspace = true
|
||||||
|
tempfile = "3"
|
||||||
thiserror.workspace = true
|
thiserror.workspace = true
|
||||||
time.workspace = true
|
time.workspace = true
|
||||||
tiny_http = "0.8"
|
tiny_http = "0.8"
|
||||||
uuid = { version = "1.1.2", features = ["v4"] }
|
|
||||||
url = "2.2"
|
url = "2.2"
|
||||||
serde.workspace = true
|
uuid = { version = "1.1.2", features = ["v4"] }
|
||||||
serde_derive.workspace = true
|
|
||||||
tempfile = "3"
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
collections = { path = "../collections", features = ["test-support"] }
|
collections = { path = "../collections", features = ["test-support"] }
|
||||||
|
|
|
@ -4,6 +4,7 @@ use lazy_static::lazy_static;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use std::{env, io::Write, mem, path::PathBuf, sync::Arc, time::Duration};
|
use std::{env, io::Write, mem, path::PathBuf, sync::Arc, time::Duration};
|
||||||
|
use sysinfo::{Pid, PidExt, ProcessExt, System, SystemExt};
|
||||||
use tempfile::NamedTempFile;
|
use tempfile::NamedTempFile;
|
||||||
use util::http::HttpClient;
|
use util::http::HttpClient;
|
||||||
use util::{channel::ReleaseChannel, TryFutureExt};
|
use util::{channel::ReleaseChannel, TryFutureExt};
|
||||||
|
@ -88,6 +89,16 @@ pub enum ClickhouseEvent {
|
||||||
kind: AssistantKind,
|
kind: AssistantKind,
|
||||||
model: &'static str,
|
model: &'static str,
|
||||||
},
|
},
|
||||||
|
Cpu {
|
||||||
|
usage_as_percent: f32,
|
||||||
|
core_count: u32,
|
||||||
|
},
|
||||||
|
Memory {
|
||||||
|
memory_in_bytes: u64,
|
||||||
|
virtual_memory_in_bytes: u64,
|
||||||
|
start_time_in_seconds: u64,
|
||||||
|
run_time_in_seconds: u64,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
|
@ -136,7 +147,7 @@ impl Telemetry {
|
||||||
Some(self.state.lock().log_file.as_ref()?.path().to_path_buf())
|
Some(self.state.lock().log_file.as_ref()?.path().to_path_buf())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start(self: &Arc<Self>, installation_id: Option<String>) {
|
pub fn start(self: &Arc<Self>, installation_id: Option<String>, cx: &mut AppContext) {
|
||||||
let mut state = self.state.lock();
|
let mut state = self.state.lock();
|
||||||
state.installation_id = installation_id.map(|id| id.into());
|
state.installation_id = installation_id.map(|id| id.into());
|
||||||
let has_clickhouse_events = !state.clickhouse_events_queue.is_empty();
|
let has_clickhouse_events = !state.clickhouse_events_queue.is_empty();
|
||||||
|
@ -145,6 +156,48 @@ impl Telemetry {
|
||||||
if has_clickhouse_events {
|
if has_clickhouse_events {
|
||||||
self.flush_clickhouse_events();
|
self.flush_clickhouse_events();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let this = self.clone();
|
||||||
|
cx.spawn(|mut cx| async move {
|
||||||
|
let mut system = System::new_all();
|
||||||
|
system.refresh_all();
|
||||||
|
|
||||||
|
loop {
|
||||||
|
// Waiting some amount of time before the first query is important to get a reasonable value
|
||||||
|
// https://docs.rs/sysinfo/0.29.10/sysinfo/trait.ProcessExt.html#tymethod.cpu_usage
|
||||||
|
const DURATION_BETWEEN_SYSTEM_EVENTS: Duration = Duration::from_secs(60);
|
||||||
|
smol::Timer::after(DURATION_BETWEEN_SYSTEM_EVENTS).await;
|
||||||
|
|
||||||
|
let telemetry_settings = cx.update(|cx| *settings::get::<TelemetrySettings>(cx));
|
||||||
|
|
||||||
|
system.refresh_memory();
|
||||||
|
system.refresh_processes();
|
||||||
|
|
||||||
|
let current_process = Pid::from_u32(std::process::id());
|
||||||
|
let Some(process) = system.processes().get(¤t_process) else {
|
||||||
|
let process = current_process;
|
||||||
|
log::error!("Failed to find own process {process:?} in system process table");
|
||||||
|
// TODO: Fire an error telemetry event
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
let memory_event = ClickhouseEvent::Memory {
|
||||||
|
memory_in_bytes: process.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 {
|
||||||
|
usage_as_percent: process.cpu_usage(),
|
||||||
|
core_count: system.cpus().len() as u32,
|
||||||
|
};
|
||||||
|
|
||||||
|
this.report_clickhouse_event(memory_event, telemetry_settings);
|
||||||
|
this.report_clickhouse_event(cpu_event, telemetry_settings);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_authenticated_user_info(
|
pub fn set_authenticated_user_info(
|
||||||
|
|
|
@ -33,7 +33,7 @@ lazy_static.workspace = true
|
||||||
postage.workspace = true
|
postage.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_derive.workspace = true
|
serde_derive.workspace = true
|
||||||
sysinfo = "0.27.1"
|
sysinfo.workspace = true
|
||||||
tree-sitter-markdown = { git = "https://github.com/MDeiml/tree-sitter-markdown", rev = "330ecab87a3e3a7211ac69bbadc19eabecdb1cca" }
|
tree-sitter-markdown = { git = "https://github.com/MDeiml/tree-sitter-markdown", rev = "330ecab87a3e3a7211ac69bbadc19eabecdb1cca" }
|
||||||
urlencoding = "2.1.2"
|
urlencoding = "2.1.2"
|
||||||
|
|
||||||
|
|
|
@ -177,7 +177,7 @@ fn main() {
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
|
|
||||||
client.telemetry().start(installation_id);
|
client.telemetry().start(installation_id, cx);
|
||||||
|
|
||||||
let app_state = Arc::new(AppState {
|
let app_state = Arc::new(AppState {
|
||||||
languages,
|
languages,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue