mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
More work
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
160b29c004
commit
c7da2ea81c
@ -26,7 +26,7 @@ import { observable, reaction } from "mobx";
|
|||||||
import { disposeOnUnmount, observer } from "mobx-react";
|
import { disposeOnUnmount, observer } from "mobx-react";
|
||||||
import { nodesStore } from "../+nodes/nodes.store";
|
import { nodesStore } from "../+nodes/nodes.store";
|
||||||
import { podsStore } from "../+workloads-pods/pods.store";
|
import { podsStore } from "../+workloads-pods/pods.store";
|
||||||
import { createStorage, getHostedClusterId, interval } from "../../utils";
|
import { boundMethod, createStorage, interval } from "../../utils";
|
||||||
import { TabLayout } from "../layout/tab-layout";
|
import { TabLayout } from "../layout/tab-layout";
|
||||||
import { Spinner } from "../spinner";
|
import { Spinner } from "../spinner";
|
||||||
import { ClusterIssues } from "./cluster-issues";
|
import { ClusterIssues } from "./cluster-issues";
|
||||||
@ -35,8 +35,9 @@ import { kubeClusterStore } from "./cluster-overview.store";
|
|||||||
import { ClusterPieCharts } from "./cluster-pie-charts";
|
import { ClusterPieCharts } from "./cluster-pie-charts";
|
||||||
import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
|
import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
|
||||||
import { ClusterMetricsResourceType } from "../../../common/cluster-types";
|
import { ClusterMetricsResourceType } from "../../../common/cluster-types";
|
||||||
import { ClusterStore } from "../../../common/cluster-store";
|
import { getMetricsByNodeNames, IClusterMetrics, Node } from "../../../common/k8s-api/endpoints";
|
||||||
import type { IClusterMetrics } from "../../../common/k8s-api/endpoints";
|
import type { IMetricsReqParams } from "../../../common/k8s-api/endpoints/metrics.api";
|
||||||
|
import { ResourceMetrics } from "../resource-metrics";
|
||||||
|
|
||||||
export enum MetricType {
|
export enum MetricType {
|
||||||
MEMORY = "memory",
|
MEMORY = "memory",
|
||||||
@ -51,76 +52,59 @@ export enum MetricNodeRole {
|
|||||||
const storage = createStorage("cluster_overview", {
|
const storage = createStorage("cluster_overview", {
|
||||||
metricType: MetricType.CPU, // setup defaults
|
metricType: MetricType.CPU, // setup defaults
|
||||||
metricNodeRole: MetricNodeRole.WORKER,
|
metricNodeRole: MetricNodeRole.WORKER,
|
||||||
|
showVirtualNodes: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class ClusterOverview extends React.Component {
|
export class ClusterOverview extends React.Component {
|
||||||
@observable metrics?: IClusterMetrics = undefined;
|
@observable metrics?: IClusterMetrics = undefined;
|
||||||
private metricPoller = interval(60, () => this.loadMetrics());
|
|
||||||
|
|
||||||
loadMetrics() {
|
get metricNodeRole() {
|
||||||
const cluster = ClusterStore.getInstance().getById(getHostedClusterId());
|
return storage.get().metricNodeRole;
|
||||||
|
|
||||||
if (cluster.available) {
|
|
||||||
kubeClusterStore.loadMetrics();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
async loadMetrics() {
|
|
||||||
const { object: pod } = this.props;
|
|
||||||
|
|
||||||
this.metrics = await getMetricsForPods([pod], pod.getNs());
|
|
||||||
this.containerMetrics = await getMetricsForPods([pod], pod.getNs(), "container, namespace");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
get showVirtualNodes() {
|
||||||
this.metricPoller.start(true);
|
return storage.get().showVirtualNodes;
|
||||||
|
|
||||||
disposeOnUnmount(this, [
|
|
||||||
reaction(
|
|
||||||
() => kubeClusterStore.metricNodeRole, // Toggle Master/Worker node switcher
|
|
||||||
() => this.metricPoller.restart(true)
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
getNodesForMetrics(): Node[] {
|
||||||
this.metricPoller.stop();
|
const { masterNodes, workerNodes } = nodesStore;
|
||||||
}
|
const nodes = this.metricNodeRole === MetricNodeRole.MASTER
|
||||||
|
? masterNodes
|
||||||
|
: workerNodes;
|
||||||
|
|
||||||
renderMetrics(isMetricsHidden: boolean) {
|
if (this.showVirtualNodes) {
|
||||||
if (isMetricsHidden) {
|
return nodes;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return nodes.filter(node => node.metadata.labels?.kind !== "virtual-kubelet");
|
||||||
<>
|
|
||||||
<ClusterMetrics/>
|
|
||||||
<ClusterPieCharts/>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
renderClusterOverview(isLoaded: boolean, isMetricsHidden: boolean) {
|
@boundMethod
|
||||||
if (!isLoaded) {
|
async loadMetrics(params?: IMetricsReqParams): Promise<void> {
|
||||||
return <Spinner center/>;
|
const nodesNames = this.getNodesForMetrics().map(node => node.getName());
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
this.metrics = await getMetricsByNodeNames(nodesNames, params);
|
||||||
<>
|
|
||||||
{this.renderMetrics(isMetricsHidden)}
|
|
||||||
<ClusterIssues className={isMetricsHidden ? "OnlyClusterIssues" : ""}/>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const isLoaded = nodesStore.isLoaded && podsStore.isLoaded;
|
const { metrics } = this;
|
||||||
const isMetricHidden = getActiveClusterEntity()?.isMetricHidden(ClusterMetricsResourceType.Cluster);
|
const isMetricHidden = getActiveClusterEntity()?.isMetricHidden(ClusterMetricsResourceType.Cluster);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TabLayout>
|
<TabLayout>
|
||||||
<div className="ClusterOverview">
|
<div className="ClusterOverview">
|
||||||
{this.renderClusterOverview(isLoaded, isMetricHidden)}
|
{!isMetricHidden && (
|
||||||
|
<ResourceMetrics
|
||||||
|
loader={this.loadMetrics}
|
||||||
|
tabs={[MetricType.CPU, MetricType.MEMORY]}
|
||||||
|
params={{ metrics }}
|
||||||
|
>
|
||||||
|
<ClusterMetrics />
|
||||||
|
<ClusterPieCharts />
|
||||||
|
</ResourceMetrics>
|
||||||
|
)}
|
||||||
|
<ClusterIssues className={isMetricHidden ? "OnlyClusterIssues" : ""} />
|
||||||
</div>
|
</div>
|
||||||
</TabLayout>
|
</TabLayout>
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user