diff --git a/web/src/pages/Cluster/Metrics.js b/web/src/pages/Cluster/Metrics.js
index d46193ec..6a57de91 100644
--- a/web/src/pages/Cluster/Metrics.js
+++ b/web/src/pages/Cluster/Metrics.js
@@ -36,6 +36,7 @@ import { EuiSuperDatePicker } from "@elastic/eui";
import { calculateBounds } from "../../components/kibana/data/common/query/timefilter";
import NodeMetric from "./components/node_metric";
import IndexMetric from "./components/index_metric";
+import ClusterMetric from "./components/cluster_metric";
import { formatter, getFormatter, getNumFormatter } from "./format";
const { RangePicker } = DatePicker;
@@ -169,7 +170,6 @@ class ClusterMonitor extends PureComponent {
super(props);
//this.timePicker = React.createRef();
this.handleChartBrush = this.handleChartBrush.bind(this);
- this.chartRefs = [];
this.handleTimeChange = this.handleTimeChange.bind(this);
this.state = {
spinning: false,
@@ -214,9 +214,6 @@ class ClusterMonitor extends PureComponent {
cluster_id: this.state.clusterID,
},
}).then((res) => {
- this.chartRefs = Object.keys(res?.metrics || {}).map(() => {
- return React.createRef();
- });
this.setState({
spinning: false,
});
@@ -592,107 +589,19 @@ class ClusterMonitor extends PureComponent {
-
+
- {Object.keys(clusterMetrics).map((e, i) => {
- let axis = clusterMetrics[e].axis;
- let lines = clusterMetrics[e].lines;
- let disableHeaderFormat = false;
- let headerUnit = "";
- return (
-
-
-
- `${formatter.full_dates(value)}${
- headerUnit ? ` ${headerUnit}` : ""
- }`,
- }}
- debug={false}
- />
-
- {axis.map((item) => {
- return (
-
- );
- })}
-
- {lines.map((item) => {
- return (
-
- );
- })}
-
-
- );
- })}
+
{
+ const queryParams = React.useMemo(() => {
+ const bounds = calculateBounds({
+ from: timeRange.min,
+ to: timeRange.max,
+ });
+ return {
+ min: bounds.min.valueOf(),
+ max: bounds.max.valueOf(),
+ };
+ }, [timeRange]);
+ const { loading, error, value } = useFetch(
+ `${ESPrefix}/${clusterID}/cluster_metrics`,
+ {
+ queryParams: queryParams,
+ },
+ [clusterID, queryParams]
+ );
+ const { metrics = {} } = value || {};
+
+ const chartRefs = React.useRef();
+ React.useEffect(() => {
+ let refs = [];
+ Object.keys(metrics).map((m) => {
+ refs.push(React.createRef());
+ });
+ chartRefs.current = refs;
+ }, [metrics]);
+
+ const pointerUpdate = (event) => {
+ chartRefs.current.forEach((ref) => {
+ if (ref.current) {
+ ref.current.dispatchExternalPointerEvent(event);
+ }
+ });
+ };
+
+ const handleChartBrush = ({ x }) => {
+ if (!x) {
+ return;
+ }
+ const [from, to] = x;
+ if (typeof handleTimeChange == "function") {
+ handleTimeChange({
+ start: moment(from).toISOString(),
+ end: moment(to).toISOString(),
+ });
+ }
+ };
+ let refIdx = 0;
+ if (Object.keys(metrics).length == 0) {
+ return null;
+ }
+
+ return (
+
+
+
+ {Object.keys(metrics).map((e, i) => {
+ let axis = metrics[e].axis;
+ let lines = metrics[e].lines;
+ let disableHeaderFormat = false;
+ let headerUnit = "";
+ return (
+
+
+
+ `${formatter.full_dates(value)}${
+ headerUnit ? ` ${headerUnit}` : ""
+ }`,
+ }}
+ debug={false}
+ />
+
+ {e == "cluster_health" ? (
+ Number(d).toFixed(0) + "%"}
+ />
+ ) : null}
+
+ {axis.map((item) => {
+ return (
+
+ );
+ })}
+
+ {lines.map((item) => {
+ if (item.type == "bar") {
+ return (
+ {
+ const g = splitAccessors.get("g");
+ if (
+ yAccessor === "y" &&
+ ["red", "yellow", "green"].includes(g)
+ ) {
+ return g;
+ }
+ return null;
+ }}
+ />
+ );
+ }
+ return (
+
+ );
+ })}
+
+
+ );
+ })}
+
+
+
+ );
+};
diff --git a/web/src/pages/Cluster/components/node_metric.jsx b/web/src/pages/Cluster/components/node_metric.jsx
index 395fe4ab..1dbf8455 100644
--- a/web/src/pages/Cluster/components/node_metric.jsx
+++ b/web/src/pages/Cluster/components/node_metric.jsx
@@ -178,6 +178,9 @@ export default ({ clusterID, timezone, timeRange, handleTimeChange }) => {
{metrics[e].map((metric) => {
let axis = metric.axis;
let lines = metric.lines;
+ if (lines && lines[0].data && lines[0].data.length == 0) {
+ return null;
+ }
let disableHeaderFormat = false;
let headerUnit = "";
return (