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

Add Inserted/Selected rows into summary #65

Merged
merged 1 commit into from
Jun 16, 2024
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
19 changes: 19 additions & 0 deletions src/interpreter/clickhouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ pub struct ClickHouseServerStorages {
pub distributed_insert_files: u64,
}
#[derive(Default)]
pub struct ClickHouseServerRows {
pub selected: u64,
pub inserted: u64,
}
#[derive(Default)]
pub struct ClickHouseServerSummary {
pub processes: u64,
pub merges: u64,
Expand All @@ -109,6 +114,7 @@ pub struct ClickHouseServerSummary {
pub replication_queue_tries: u64,
pub fetches: u64,
pub servers: u64,
pub rows: ClickHouseServerRows,
pub storages: ClickHouseServerStorages,
pub uptime: ClickHouseServerUptime,
pub memory: ClickHouseServerMemory,
Expand Down Expand Up @@ -396,6 +402,7 @@ impl ClickHouse {
assumeNotNull(memory_dictionaries_) AS memory_dictionaries,

asynchronous_metrics.*,
events.*,
metrics.*
FROM
(
Expand Down Expand Up @@ -433,6 +440,12 @@ impl ClickHouse {
CAST(anyLastIf(value, metric == 'AsynchronousMetricsUpdateInterval') AS UInt64) AS metrics_update_interval
FROM {asynchronous_metrics}
) as asynchronous_metrics,
(
SELECT
sumIf(CAST(value AS UInt64), event == 'SelectedRows') AS selected_rows,
sumIf(CAST(value AS UInt64), event == 'InsertedRows') AS inserted_rows
FROM {events}
) as events,
(
SELECT
sumIf(CAST(value AS UInt64), metric == 'StorageBufferBytes') AS storage_buffer_bytes,
Expand Down Expand Up @@ -474,6 +487,7 @@ impl ClickHouse {
SETTINGS enable_global_with_statement=0
"#,
metrics=self.get_table_name("system.metrics"),
events=self.get_table_name("system.events"),
tables=self.get_table_name("system.tables"),
processes=self.get_table_name("system.processes"),
merges=self.get_table_name("system.merges"),
Expand Down Expand Up @@ -503,6 +517,11 @@ impl ClickHouse {
server: get("uptime"),
},

rows: ClickHouseServerRows {
selected: get("selected_rows"),
inserted: get("inserted_rows"),
},

storages: ClickHouseServerStorages {
buffer_bytes: get("storage_buffer_bytes"),
distributed_insert_files: get("storage_distributed_insert_files"),
Expand Down
48 changes: 46 additions & 2 deletions src/view/summary_view.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use chrono::{DateTime, Local};
use cursive::{
event::{AnyCb, Event, EventResult},
theme::BaseColor,
Expand All @@ -15,6 +16,9 @@ use crate::interpreter::{
};

pub struct SummaryView {
prev_summary: Option<ClickHouseServerSummary>,
prev_update_time: Option<DateTime<Local>>,

layout: views::LinearLayout,

#[allow(unused)]
Expand Down Expand Up @@ -149,7 +153,21 @@ impl SummaryView {
BaseColor::Cyan.dark(),
)))
.child(views::DummyView.fixed_width(1))
.child(views::TextView::new("").with_name("disk_write")),
.child(views::TextView::new("").with_name("disk_write"))
.child(views::DummyView.fixed_width(1))
.child(views::TextView::new(StyledString::styled(
"Selected rows:",
BaseColor::Cyan.dark(),
)))
.child(views::DummyView.fixed_width(1))
.child(views::TextView::new("").with_name("selected_rows"))
.child(views::DummyView.fixed_width(1))
.child(views::TextView::new(StyledString::styled(
"Inserted rows:",
BaseColor::Cyan.dark(),
)))
.child(views::DummyView.fixed_width(1))
.child(views::TextView::new("").with_name("inserted_rows")),
)
.child(
views::LinearLayout::horizontal()
Expand Down Expand Up @@ -181,7 +199,12 @@ impl SummaryView {
let mut bg_runner = BackgroundRunner::new(delay, bg_runner_cv);
bg_runner.start(update_callback);

return Self { layout, bg_runner };
return Self {
prev_summary: None,
prev_update_time: None,
layout,
bg_runner,
};
}

pub fn set_view_content<S>(&mut self, view_name: &str, content: S)
Expand All @@ -207,6 +230,13 @@ impl SummaryView {
} else {
1
};
let now = Local::now();
let mut since_prev_us = (now - self.prev_update_time.unwrap_or(Local::now()))
.num_microseconds()
.unwrap_or_default() as u64;
if since_prev_us == 0 {
since_prev_us = 1;
}

{
let mut description: Vec<String> = Vec::new();
Expand Down Expand Up @@ -311,6 +341,17 @@ impl SummaryView {
fmt_ref.format((summary.blkdev.write_bytes / update_interval) as i64),
);

let mut selected_rows = summary.rows.selected / summary.uptime.server;
let mut inserted_rows = summary.rows.inserted / summary.uptime.server;
if let Some(prev_summary) = &self.prev_summary {
selected_rows =
(summary.rows.selected - prev_summary.rows.selected) * 1_000_000 / since_prev_us;
inserted_rows =
(summary.rows.inserted - prev_summary.rows.inserted) * 1_000_000 / since_prev_us;
}
self.set_view_content("selected_rows", fmt_ref.format(selected_rows as i64));
self.set_view_content("inserted_rows", fmt_ref.format(inserted_rows as i64));

self.set_view_content(
"uptime",
format_duration(Duration::from_secs(summary.uptime.server)).to_string(),
Expand Down Expand Up @@ -389,6 +430,9 @@ impl SummaryView {
);
self.set_view_content("storage_distributed_insert_files", content);
}

self.prev_summary = Some(summary);
self.prev_update_time = Some(now);
}
}

Expand Down
Loading