From ce53fb3ad71d3e3ac2672c09511c4de306bf27fa Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 16 Nov 2026 01:05:54 +0300 Subject: [PATCH] ClickHouse tab: the application's figures; OpenSearch tab: clearer per-node columns ClickHouse queries, failures, query time, inserted rows, running queries, data size and the fullest partition (which feeds the parts check) now come from the agent's user-only series: an idle database no longer shows the agent's own queries or the server's log tables as activity. OpenSearch: the rejections chart draws only pools and breakers that rejected something, and the document and size columns say they are per node. Agent: claude Co-Authored-By: Claude Fable 5.2 --- auditor/clickhouse.go | 35 ++++++++++++++++++--------- auditor/opensearch.go | 15 ++++++++---- auditor/opensearch_clickhouse_test.go | 4 +-- constructor/clickhouse.go | 18 +++++++++++--- constructor/queries.go | 8 +++++- model/clickhouse.go | 15 ++++++++++-- 6 files changed, 70 insertions(+), 25 deletions(-) diff --git a/auditor/clickhouse.go b/auditor/clickhouse.go index 4c79e8406..b07a3585b 100644 --- a/auditor/clickhouse.go +++ b/auditor/clickhouse.go @@ -6,7 +6,9 @@ import ( "github.com/coroot/coroot/utils" ) -// The tab exists once the cluster agent scrapes at least one server. +// The tab exists once the cluster agent scrapes at least one server. Query, +// insert, size and parts figures are the application's: the agent leaves out +// its own queries and the server's log tables (database system). func (a *appAuditor) clickhouse() { if !a.app.IsClickhouse() { return @@ -24,7 +26,7 @@ func (a *appAuditor) clickhouse() { latencyChart := report.GetOrCreateChart("Average query time, seconds", nil) runningChart := report.GetOrCreateChart("Running queries", nil) longestChart := report.GetOrCreateChart("Longest running query, seconds", nil) - insertedChart := report.GetOrCreateChart("Inserted rows, per second", nil) + insertedChart := report.GetOrCreateChart("Rows inserted by queries, per second", nil) connectionsChart := report.GetOrCreateChartGroup("Connections on ", nil) partsChart := report.GetOrCreateChartGroup("Active parts in the fullest partition on ", nil) mergesChart := report.GetOrCreateChartGroup("Merges and mutations on ", nil) @@ -59,7 +61,7 @@ func (a *appAuditor) clickhouse() { replicationCheck.AddItem("%s", i.Name) } - maxParts := c.AsyncMetrics["MaxPartCountForPartition"] + maxParts := c.MaxPartsInPartition if limit := c.PartsToDelayInsert.Last(); live && limit > 0 && maxParts.Last()/limit*100 > partsCheck.Threshold { partsCheck.AddItem("%s", i.Name) } @@ -74,22 +76,22 @@ func (a *appAuditor) clickhouse() { if queriesChart != nil { queriesChart.GetOrCreateChart(i.Name). - AddSeries("select", c.Events["SelectQuery"]). - AddSeries("insert", c.Events["InsertQuery"]). - AddSeries("failed", c.Events["FailedQuery"], "black") + AddSeries("select", c.Queries["select"]). + AddSeries("insert", c.Queries["insert"]). + AddSeries("other", c.Queries["other"]). + AddSeries("failed", c.FailedQueries, "black") } if latencyChart != nil { - latencyChart.AddSeries(i.Name, timeseries.Aggregate2(c.Events["QueryTimeMicroseconds"], c.Events["Query"], - func(micros, queries float32) float32 { return micros / queries / 1e6 })) + latencyChart.AddSeries(i.Name, timeseries.Div(c.QueryTime, clickhouseQueries(c))) } if runningChart != nil { - runningChart.AddSeries(i.Name, c.Metrics["Query"]) + runningChart.AddSeries(i.Name, c.RunningQueries) } if longestChart != nil { longestChart.AddSeries(i.Name, c.LongestQuery) } if insertedChart != nil { - insertedChart.AddSeries(i.Name, c.Events["InsertedRows"]) + insertedChart.AddSeries(i.Name, c.InsertedRows) } if connectionsChart != nil { connectionsChart.GetOrCreateChart(i.Name).Stacked(). @@ -156,7 +158,7 @@ func clickhouseInstanceRow(table *model.Table, i *model.Instance) { } queries := model.NewTableCell() - if v := c.Events["Query"].Last(); !timeseries.IsNaN(v) { + if v := clickhouseQueries(c).Last(); !timeseries.IsNaN(v) { queries.SetValue(utils.FormatFloat(v)).SetUnit("/s") } @@ -170,9 +172,18 @@ func clickhouseInstanceRow(table *model.Table, i *model.Instance) { } size := model.NewTableCell() - if v := c.AsyncMetrics["TotalBytesOfMergeTreeTables"].Last(); !timeseries.IsNaN(v) { + if v := c.TablesSize.Last(); !timeseries.IsNaN(v) { size.Value, size.Unit = utils.FormatBytes(v) } table.AddRow(name, status, queries, delay, size, model.NewTableCell(c.Version.Value())) } + +// clickhouseQueries is the rate of all the queries other users ran. +func clickhouseQueries(c *model.Clickhouse) *timeseries.TimeSeries { + total := timeseries.NewAggregate(timeseries.NanSum) + for _, ts := range c.Queries { + total.Add(ts) + } + return total.Get() +} diff --git a/auditor/opensearch.go b/auditor/opensearch.go index 74dd6b02b..06893af6b 100644 --- a/auditor/opensearch.go +++ b/auditor/opensearch.go @@ -18,7 +18,7 @@ func (a *appAuditor) opensearch() { statusCheck := report.CreateCheck(model.Checks.OpensearchClusterStatus) rejectionsCheck := report.CreateCheck(model.Checks.OpensearchRejections) - table := report.GetOrCreateTable("Node", "Roles", "Status", "Cluster", "Documents", "Size", "Version") + table := report.GetOrCreateTable("Node", "Roles", "Status", "Cluster", "Documents on node", "Size on node", "Version") shardsChart := report.GetOrCreateChart("Shards by state", nil) searchChart := report.GetOrCreateChart("Search requests, per second", nil) searchLatencyChart := report.GetOrCreateChart("Search average latency, seconds", nil) @@ -28,8 +28,8 @@ func (a *appAuditor) opensearch() { queueChart := report.GetOrCreateChartGroup("Thread pool queues on ", nil) heapChart := report.GetOrCreateChart("JVM heap usage, %", nil) gcChart := report.GetOrCreateChart("Time spent in garbage collection, seconds/second", nil) - docsChart := report.GetOrCreateChart("Documents", nil) - sizeChart := report.GetOrCreateChart("Index size, bytes", nil) + docsChart := report.GetOrCreateChart("Documents on each node (with replica copies)", nil) + sizeChart := report.GetOrCreateChart("Index size on each node, bytes", nil) availabilityCheck.AddWidget(table.Widget()) statusCheck.AddWidget(shardsChart.Widget()) @@ -68,13 +68,18 @@ func (a *appAuditor) opensearch() { rejected := timeseries.NewAggregate(timeseries.NanSum) rejectedBy := map[string]model.SeriesData{} + // Only what was rejected is drawn: a chart of zero series says nothing. for pool, ts := range o.PoolRejected { rejected.Add(ts) - rejectedBy[pool+" pool"] = ts + if ts.Reduce(timeseries.Max) > 0 { + rejectedBy[pool+" pool"] = ts + } } for breaker, ts := range o.BreakerTripped { rejected.Add(ts) - rejectedBy[breaker+" breaker"] = ts + if ts.Reduce(timeseries.Max) > 0 { + rejectedBy[breaker+" breaker"] = ts + } } if !obsolete && rejected.Get().Last() > 0 { rejectionsCheck.AddItem("%s", i.Name) diff --git a/auditor/opensearch_clickhouse_test.go b/auditor/opensearch_clickhouse_test.go index d4f3a77b9..427c4f09b 100644 --- a/auditor/opensearch_clickhouse_test.go +++ b/auditor/opensearch_clickhouse_test.go @@ -89,7 +89,7 @@ func TestClickhouseReport(t *testing.T) { i.Clickhouse = c c.Up = constSeries(ctx, 1) c.PartsToDelayInsert = constSeries(ctx, 1000) - c.AsyncMetrics["MaxPartCountForPartition"] = constSeries(ctx, 300) + c.MaxPartsInPartition = constSeries(ctx, 300) // Not replicated: a delay value must not raise the replication check. c.ReplicatedTables = constSeries(ctx, 0) c.AsyncMetrics["ReplicasMaxAbsoluteDelay"] = constSeries(ctx, 120) @@ -102,7 +102,7 @@ func TestClickhouseReport(t *testing.T) { assert.Empty(t, failing(a.reports[0])) c.ReplicatedTables = constSeries(ctx, 3) - c.AsyncMetrics["MaxPartCountForPartition"] = constSeries(ctx, 900) + c.MaxPartsInPartition = constSeries(ctx, 900) c.MutationsFailing = constSeries(ctx, 1) a.reports = nil a.clickhouse() diff --git a/constructor/clickhouse.go b/constructor/clickhouse.go index 310e7ec97..5353b173e 100644 --- a/constructor/clickhouse.go +++ b/constructor/clickhouse.go @@ -23,9 +23,21 @@ func clickhouse(instance *model.Instance, queryName string, m *model.MetricValue case "clickhouse_metric": n := m.Labels["metric"] c.Metrics[n] = merge(c.Metrics[n], m.Values, timeseries.Any) - case "clickhouse_events_total": - n := m.Labels["event"] - c.Events[n] = merge(c.Events[n], m.Values, timeseries.Any) + case "clickhouse_queries_per_second": + k := m.Labels["kind"] + c.Queries[k] = merge(c.Queries[k], m.Values, timeseries.Any) + case "clickhouse_failed_queries_per_second": + c.FailedQueries = merge(c.FailedQueries, m.Values, timeseries.Any) + case "clickhouse_query_seconds_per_second": + c.QueryTime = merge(c.QueryTime, m.Values, timeseries.Any) + case "clickhouse_inserted_rows_per_second": + c.InsertedRows = merge(c.InsertedRows, m.Values, timeseries.Any) + case "clickhouse_running_queries": + c.RunningQueries = merge(c.RunningQueries, m.Values, timeseries.Any) + case "clickhouse_tables_size_bytes": + c.TablesSize = merge(c.TablesSize, m.Values, timeseries.Any) + case "clickhouse_max_parts_in_partition": + c.MaxPartsInPartition = merge(c.MaxPartsInPartition, m.Values, timeseries.Any) case "clickhouse_async_metric": n := m.Labels["metric"] c.AsyncMetrics[n] = merge(c.AsyncMetrics[n], m.Values, timeseries.Any) diff --git a/constructor/queries.go b/constructor/queries.go index bebef9bc3..81154f412 100644 --- a/constructor/queries.go +++ b/constructor/queries.go @@ -522,7 +522,13 @@ var QUERIES = []Query{ qDB("clickhouse_scrape_error", `clickhouse_scrape_error`, "error"), qDB("clickhouse_info", `clickhouse_info`, "version"), qDB("clickhouse_metric", `clickhouse_metric`, "metric"), - qDB("clickhouse_events_total", `rate(clickhouse_events_total[$RANGE])`, "event"), + qDB("clickhouse_queries_per_second", `clickhouse_queries_per_second`, "kind"), + qDB("clickhouse_failed_queries_per_second", `clickhouse_failed_queries_per_second`), + qDB("clickhouse_query_seconds_per_second", `clickhouse_query_seconds_per_second`), + qDB("clickhouse_inserted_rows_per_second", `clickhouse_inserted_rows_per_second`), + qDB("clickhouse_running_queries", `clickhouse_running_queries`), + qDB("clickhouse_tables_size_bytes", `clickhouse_tables_size_bytes`), + qDB("clickhouse_max_parts_in_partition", `clickhouse_max_parts_in_partition`), qDB("clickhouse_async_metric", `clickhouse_async_metric`, "metric"), qDB("clickhouse_replicated_tables", `clickhouse_replicated_tables`), qDB("clickhouse_mutations_unfinished", `clickhouse_mutations_unfinished`), diff --git a/model/clickhouse.go b/model/clickhouse.go index e422601bc..0ec7e6426 100644 --- a/model/clickhouse.go +++ b/model/clickhouse.go @@ -22,9 +22,16 @@ type Clickhouse struct { Version LabelLastValue Metrics map[string]*timeseries.TimeSeries // system.metrics: current values - Events map[string]*timeseries.TimeSeries // system.events: per-second rates AsyncMetrics map[string]*timeseries.TimeSeries // system.asynchronous_metrics + // What other users do (system.query_log, without the agent's own + // queries and the server's log tables), per second. + Queries map[string]*timeseries.TimeSeries // by kind: select, insert, other + FailedQueries *timeseries.TimeSeries + QueryTime *timeseries.TimeSeries // seconds spent in queries + InsertedRows *timeseries.TimeSeries + RunningQueries *timeseries.TimeSeries + ReplicatedTables *timeseries.TimeSeries MutationsUnfinished *timeseries.TimeSeries MutationsFailing *timeseries.TimeSeries @@ -32,6 +39,10 @@ type Clickhouse struct { PartsToThrowInsert *timeseries.TimeSeries PartsToDelayInsert *timeseries.TimeSeries + // Tables outside the system database. + TablesSize *timeseries.TimeSeries + MaxPartsInPartition *timeseries.TimeSeries + TableSize map[ClickhouseTable]*timeseries.TimeSeries TableParts map[ClickhouseTable]*timeseries.TimeSeries } @@ -39,7 +50,7 @@ type Clickhouse struct { func NewClickhouse() *Clickhouse { return &Clickhouse{ Metrics: map[string]*timeseries.TimeSeries{}, - Events: map[string]*timeseries.TimeSeries{}, + Queries: map[string]*timeseries.TimeSeries{}, AsyncMetrics: map[string]*timeseries.TimeSeries{}, TableSize: map[ClickhouseTable]*timeseries.TimeSeries{}, TableParts: map[ClickhouseTable]*timeseries.TimeSeries{},