Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display current time in the top-right corner of the dashboard #7

Merged
merged 3 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 153 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ readme = "README.md"

[dependencies]
anyhow = "1"
chrono = { version = "0.4.31", features = ["serde"] }
clap = { version = "4", features = ["derive"] }
crossterm = "0.27"
dirs = "5"
Expand Down
37 changes: 23 additions & 14 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,10 @@ impl MetricsPoller {
matches!(self, Self::Replay(_))
}

pub fn system_version(&self) -> &SystemVersion {
pub fn header(&self) -> &Header {
match self {
Self::Realtime(poller) => &poller.system_version,
Self::Replay(poller) => &poller.system_version,
Self::Realtime(poller) => &poller.header,
Self::Replay(poller) => &poller.header,
}
}

Expand Down Expand Up @@ -295,9 +295,15 @@ impl MetricsPoller {
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Header {
pub system_version: SystemVersion,
pub start_time: chrono::DateTime<chrono::Local>,
}

#[derive(Debug)]
pub struct ReplayMetricsPoller {
system_version: SystemVersion,
header: Header,
metrics_log: Vec<Metrics>,
}

Expand All @@ -311,12 +317,12 @@ impl ReplayMetricsPoller {
})?;
let reader = std::io::BufReader::new(file);

let mut system_version = None;
let mut header = None;
let mut metrics_log = Vec::new();
for (i, line) in reader.lines().enumerate() {
let line = line?;
if i == 0 {
system_version = Some(
header = Some(
serde_json::from_str(&line)
.with_context(|| format!("failed to parse record file: line={}", i + 1))?,
);
Expand All @@ -326,10 +332,9 @@ impl ReplayMetricsPoller {
.with_context(|| format!("failed to parse record file: line={}", i + 1))?;
metrics_log.push(metrics);
}
let system_version =
system_version.ok_or_else(|| anyhow::anyhow!("record file is empty"))?;
let header = header.ok_or_else(|| anyhow::anyhow!("record file is empty"))?;
Ok(Self {
system_version,
header,
metrics_log,
})
}
Expand All @@ -338,7 +343,7 @@ impl ReplayMetricsPoller {
#[derive(Debug)]
pub struct RealtimeMetricsPoller {
rx: MetricsReceiver,
system_version: SystemVersion,
header: Header,
rpc_client: RpcClient,
old_microstate_accounting_flag: bool,
}
Expand Down Expand Up @@ -371,7 +376,7 @@ struct MetricsPollerThread {
tx: MetricsSender,
prev_metrics: Metrics,
start: Instant,
system_version: SystemVersion,
header: Header,
record_file: Option<File>,
}

Expand All @@ -391,9 +396,13 @@ impl MetricsPollerThread {
"enabled microstate accounting (old flag state is {old_microstate_accounting_flag})"
);

let header = Header {
system_version: system_version.clone(),
start_time: chrono::Local::now(),
};
let poller = RealtimeMetricsPoller {
rx,
system_version: system_version.clone(),
header: header.clone(),
rpc_client: rpc_client.clone(),
old_microstate_accounting_flag,
};
Expand All @@ -414,7 +423,7 @@ impl MetricsPollerThread {
tx,
prev_metrics: Metrics::new(start),
start,
system_version,
header,
record_file,
}
.run()
Expand All @@ -436,7 +445,7 @@ impl MetricsPollerThread {
let interval = Duration::from_secs(self.options.polling_interval.get() as u64);
let mut next_time = Duration::from_secs(0);
smol::block_on(async {
if let Err(e) = self.write_json_line(&self.system_version.clone()).await {
if let Err(e) = self.write_json_line(&self.header.clone()).await {
log::error!("faild to write record file: {e}");
return;
}
Expand Down
Loading
Loading