1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
This commit is contained in:
Piotr Roszatycki 2023-10-22 09:50:56 +00:00 committed by GitHub
commit a618232384
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 53 additions and 19 deletions

View File

@ -125,6 +125,7 @@ export interface ClusterPrometheusPreferences {
prometheusProvider?: { prometheusProvider?: {
type: string; type: string;
}; };
filesystemMountpoints?: string;
} }
/** /**
@ -174,6 +175,11 @@ export enum ClusterMetricsResourceType {
Namespace = "Namespace", Namespace = "Namespace",
} }
/**
* The default filesystem mountpoints for metrics
*/
export const initialFilesystemMountpoints = "/";
/** /**
* The default node shell image * The default node shell image
*/ */

View File

@ -6,7 +6,7 @@
import { apiPrefix } from "../../../common/vars"; import { apiPrefix } from "../../../common/vars";
import { getRouteInjectable } from "../../router/router.injectable"; import { getRouteInjectable } from "../../router/router.injectable";
import type { ClusterPrometheusMetadata } from "../../../common/cluster-types"; import type { ClusterPrometheusMetadata } from "../../../common/cluster-types";
import { ClusterMetadataKey } from "../../../common/cluster-types"; import { ClusterMetadataKey, initialFilesystemMountpoints } from "../../../common/cluster-types";
import type { Cluster } from "../../../common/cluster/cluster"; import type { Cluster } from "../../../common/cluster/cluster";
import { clusterRoute } from "../../router/route"; import { clusterRoute } from "../../router/route";
import { isObject } from "lodash"; import { isObject } from "lodash";
@ -69,6 +69,7 @@ const addMetricsRouteInjectable = getRouteInjectable({
const queryParams: Partial<Record<string, string>> = Object.fromEntries(query.entries()); const queryParams: Partial<Record<string, string>> = Object.fromEntries(query.entries());
const prometheusMetadata: ClusterPrometheusMetadata = {}; const prometheusMetadata: ClusterPrometheusMetadata = {};
const prometheusHandler = di.inject(prometheusHandlerInjectable, cluster); const prometheusHandler = di.inject(prometheusHandlerInjectable, cluster);
const mountpoints = cluster.preferences.filesystemMountpoints || initialFilesystemMountpoints;
try { try {
const { prometheusPath, provider } = await prometheusHandler.getPrometheusDetails(); const { prometheusPath, provider } = await prometheusHandler.getPrometheusDetails();
@ -99,7 +100,7 @@ const addMetricsRouteInjectable = getRouteInjectable({
const data = payload as Record<string, Record<string, string>>; const data = payload as Record<string, Record<string, string>>;
const queries = object.entries(data) const queries = object.entries(data)
.map(([queryName, queryOpts]) => ( .map(([queryName, queryOpts]) => (
provider.getQuery(queryOpts, queryName) provider.getQuery({ ...queryOpts, mountpoints }, queryName)
)); ));
const result = await loadMetrics(queries, cluster, prometheusPath, queryParams); const result = await loadMetrics(queries, cluster, prometheusPath, queryParams);

View File

@ -6,6 +6,7 @@
import React from "react"; import React from "react";
import { observer, disposeOnUnmount } from "mobx-react"; import { observer, disposeOnUnmount } from "mobx-react";
import type { Cluster } from "../../../common/cluster/cluster"; import type { Cluster } from "../../../common/cluster/cluster";
import { initialFilesystemMountpoints } from "../../../common/cluster-types";
import { SubTitle } from "../layout/sub-title"; import { SubTitle } from "../layout/sub-title";
import type { SelectOption } from "../select"; import type { SelectOption } from "../select";
import { Select } from "../select"; import { Select } from "../select";
@ -32,9 +33,11 @@ interface Dependencies {
@observer @observer
class NonInjectedClusterPrometheusSetting extends React.Component<ClusterPrometheusSettingProps & Dependencies> { class NonInjectedClusterPrometheusSetting extends React.Component<ClusterPrometheusSettingProps & Dependencies> {
@observable mountpoints = "";
@observable path = ""; @observable path = "";
@observable selectedOption: ProviderValue = autoDetectPrometheus; @observable selectedOption: ProviderValue = autoDetectPrometheus;
@observable loading = true; @observable loading = true;
readonly initialFilesystemMountpoints = initialFilesystemMountpoints;
readonly loadedOptions = observable.map<string, MetricProviderInfo>(); readonly loadedOptions = observable.map<string, MetricProviderInfo>();
@computed get options(): SelectOption<ProviderValue>[] { @computed get options(): SelectOption<ProviderValue>[] {
@ -68,7 +71,7 @@ class NonInjectedClusterPrometheusSetting extends React.Component<ClusterPrometh
componentDidMount() { componentDidMount() {
disposeOnUnmount(this, disposeOnUnmount(this,
autorun(() => { autorun(() => {
const { prometheus, prometheusProvider } = this.props.cluster.preferences; const { prometheus, prometheusProvider, filesystemMountpoints } = this.props.cluster.preferences;
if (prometheus) { if (prometheus) {
const prefix = prometheus.prefix || ""; const prefix = prometheus.prefix || "";
@ -83,6 +86,10 @@ class NonInjectedClusterPrometheusSetting extends React.Component<ClusterPrometh
} else { } else {
this.selectedOption = autoDetectPrometheus; this.selectedOption = autoDetectPrometheus;
} }
if (filesystemMountpoints) {
this.mountpoints = filesystemMountpoints;
}
}), }),
); );
@ -122,6 +129,10 @@ class NonInjectedClusterPrometheusSetting extends React.Component<ClusterPrometh
this.props.cluster.preferences.prometheus = this.parsePrometheusPath(); this.props.cluster.preferences.prometheus = this.parsePrometheusPath();
}; };
onSaveMountpoints = () => {
this.props.cluster.preferences.filesystemMountpoints = this.mountpoints;
};
render() { render() {
return ( return (
<> <>
@ -165,6 +176,22 @@ class NonInjectedClusterPrometheusSetting extends React.Component<ClusterPrometh
</section> </section>
</> </>
)} )}
<>
<hr />
<section>
<SubTitle title="Filesystem mountpoints" />
<Input
theme="round-black"
value={this.mountpoints}
onChange={(value) => this.mountpoints = value}
onBlur={this.onSaveMountpoints}
placeholder={this.initialFilesystemMountpoints}
/>
<small className="hint">
{`A regexp for the label with the filesystem mountpoints that will create a graph for disk usage. For the root disk only use "/" and for all disks use ".*".`}
</small>
</section>
</>
</> </>
); );
} }

View File

@ -50,9 +50,9 @@ export const getHelmLikeQueryFor =
case "podAllocatableCapacity": case "podAllocatableCapacity":
return `sum(kube_node_status_allocatable{node=~"${opts.nodes}", resource="pods"}) by (component)`; return `sum(kube_node_status_allocatable{node=~"${opts.nodes}", resource="pods"}) by (component)`;
case "fsSize": case "fsSize":
return `sum(node_filesystem_size_bytes{node=~"${opts.nodes}", mountpoint="/"}) by (node)`; return `sum(node_filesystem_size_bytes{node=~"${opts.nodes}", mountpoint=~"${opts.mountpoints}"}) by (node)`;
case "fsUsage": case "fsUsage":
return `sum(node_filesystem_size_bytes{node=~"${opts.nodes}", mountpoint="/"} - node_filesystem_avail_bytes{node=~"${opts.nodes}", mountpoint="/"}) by (node)`; return `sum(node_filesystem_size_bytes{node=~"${opts.nodes}", mountpoint=~"${opts.mountpoints}"} - node_filesystem_avail_bytes{node=~"${opts.nodes}", mountpoint=~"${opts.mountpoints}"}) by (node)`;
} }
break; break;
case "nodes": case "nodes":
@ -72,9 +72,9 @@ export const getHelmLikeQueryFor =
case "cpuAllocatableCapacity": case "cpuAllocatableCapacity":
return `sum(kube_node_status_allocatable{resource="cpu"}) by (node)`; return `sum(kube_node_status_allocatable{resource="cpu"}) by (node)`;
case "fsSize": case "fsSize":
return `sum(node_filesystem_size_bytes{mountpoint="/"}) by (node)`; return `sum(node_filesystem_size_bytes{mountpoint=~"${opts.mountpoints}"}) by (node)`;
case "fsUsage": case "fsUsage":
return `sum(node_filesystem_size_bytes{mountpoint="/"} - node_filesystem_avail_bytes{mountpoint="/"}) by (node)`; return `sum(node_filesystem_size_bytes{mountpoint=~"${opts.mountpoints}"} - node_filesystem_avail_bytes{mountpoint=~"${opts.mountpoints}"}) by (node)`;
} }
break; break;
case "pods": case "pods":

View File

@ -50,9 +50,9 @@ export const getLensLikeQueryFor =
case "podAllocatableCapacity": case "podAllocatableCapacity":
return `sum(kube_node_status_allocatable{node=~"${opts.nodes}", resource="pods"}) by (component)`; return `sum(kube_node_status_allocatable{node=~"${opts.nodes}", resource="pods"}) by (component)`;
case "fsSize": case "fsSize":
return `sum(node_filesystem_size_bytes{kubernetes_node=~"${opts.nodes}", mountpoint="/"}) by (kubernetes_node)`; return `sum(node_filesystem_size_bytes{kubernetes_node=~"${opts.nodes}", mountpoint=~"${opts.mountpoints}"}) by (kubernetes_node)`;
case "fsUsage": case "fsUsage":
return `sum(node_filesystem_size_bytes{kubernetes_node=~"${opts.nodes}", mountpoint="/"} - node_filesystem_avail_bytes{kubernetes_node=~"${opts.nodes}", mountpoint="/"}) by (kubernetes_node)`; return `sum(node_filesystem_size_bytes{kubernetes_node=~"${opts.nodes}", mountpoint=~"${opts.mountpoints}"} - node_filesystem_avail_bytes{kubernetes_node=~"${opts.nodes}", mountpoint=~"${opts.mountpoints}"}) by (kubernetes_node)`;
} }
break; break;
case "nodes": case "nodes":
@ -72,9 +72,9 @@ export const getLensLikeQueryFor =
case "cpuAllocatableCapacity": case "cpuAllocatableCapacity":
return `sum(kube_node_status_allocatable{resource="cpu"}) by (node)`; return `sum(kube_node_status_allocatable{resource="cpu"}) by (node)`;
case "fsSize": case "fsSize":
return `sum(node_filesystem_size_bytes{mountpoint="/"}) by (kubernetes_node)`; return `sum(node_filesystem_size_bytes{mountpoint=~"${opts.mountpoints}"}) by (kubernetes_node)`;
case "fsUsage": case "fsUsage":
return `sum(node_filesystem_size_bytes{mountpoint="/"} - node_filesystem_avail_bytes{mountpoint="/"}) by (kubernetes_node)`; return `sum(node_filesystem_size_bytes{mountpoint=~"${opts.mountpoints}"} - node_filesystem_avail_bytes{mountpoint=~"${opts.mountpoints}"}) by (kubernetes_node)`;
} }
break; break;
case "pods": case "pods":

View File

@ -50,9 +50,9 @@ export const getOperatorLikeQueryFor =
case "podAllocatableCapacity": case "podAllocatableCapacity":
return `sum(kube_node_status_allocatable{node=~"${opts.nodes}", resource="pods"})`; return `sum(kube_node_status_allocatable{node=~"${opts.nodes}", resource="pods"})`;
case "fsSize": case "fsSize":
return `sum(node_filesystem_size_bytes{mountpoint="/"} * on (pod,namespace) group_left(node) kube_pod_info{node=~"${opts.nodes}"})`; return `sum(node_filesystem_size_bytes{mountpoint=~"${opts.mountpoints}"} * on (pod,namespace) group_left(node) kube_pod_info{node=~"${opts.nodes}"})`;
case "fsUsage": case "fsUsage":
return `sum(node_filesystem_size_bytes{mountpoint="/"} * on (pod,namespace) group_left(node) kube_pod_info{node=~"${opts.nodes}"} - node_filesystem_avail_bytes{mountpoint="/"} * on (pod,namespace) group_left(node) kube_pod_info{node=~"${opts.nodes}"})`; return `sum(node_filesystem_size_bytes{mountpoint=~"${opts.mountpoints}"} * on (pod,namespace) group_left(node) kube_pod_info{node=~"${opts.nodes}"} - node_filesystem_avail_bytes{mountpoint=~"${opts.mountpoints}"} * on (pod,namespace) group_left(node) kube_pod_info{node=~"${opts.nodes}"})`;
} }
break; break;
case "nodes": case "nodes":
@ -72,9 +72,9 @@ export const getOperatorLikeQueryFor =
case "cpuAllocatableCapacity": case "cpuAllocatableCapacity":
return `sum(kube_node_status_allocatable{resource="cpu"}) by (node)`; return `sum(kube_node_status_allocatable{resource="cpu"}) by (node)`;
case "fsSize": case "fsSize":
return `sum(node_filesystem_size_bytes{mountpoint="/"} * on (pod,namespace) group_left(node) kube_pod_info) by (node)`; return `sum(node_filesystem_size_bytes{mountpoint=~"${opts.mountpoints}"} * on (pod,namespace) group_left(node) kube_pod_info) by (node)`;
case "fsUsage": case "fsUsage":
return `sum((node_filesystem_size_bytes{mountpoint="/"} - node_filesystem_avail_bytes{mountpoint="/"}) * on (pod, namespace) group_left(node) kube_pod_info) by (node)`; return `sum((node_filesystem_size_bytes{mountpoint=~"${opts.mountpoints}"} - node_filesystem_avail_bytes{mountpoint=~"${opts.mountpoints}"}) * on (pod, namespace) group_left(node) kube_pod_info) by (node)`;
} }
break; break;
case "pods": case "pods":

View File

@ -50,9 +50,9 @@ export const getStacklightLikeQueryFor =
case "podAllocatableCapacity": case "podAllocatableCapacity":
return `sum(kube_node_status_allocatable{node=~"${opts.nodes}", resource="pods"}) by (component)`; return `sum(kube_node_status_allocatable{node=~"${opts.nodes}", resource="pods"}) by (component)`;
case "fsSize": case "fsSize":
return `sum(node_filesystem_size_bytes{node=~"${opts.nodes}", mountpoint="/"}) by (node)`; return `sum(node_filesystem_size_bytes{node=~"${opts.nodes}", mountpoint=~"${opts.mountpoints}"}) by (node)`;
case "fsUsage": case "fsUsage":
return `sum(node_filesystem_size_bytes{node=~"${opts.nodes}", mountpoint="/"} - node_filesystem_avail_bytes{node=~"${opts.nodes}", mountpoint="/"}) by (node)`; return `sum(node_filesystem_size_bytes{node=~"${opts.nodes}", mountpoint=~"${opts.mountpoints}"} - node_filesystem_avail_bytes{node=~"${opts.nodes}", mountpoint=~"${opts.mountpoints}"}) by (node)`;
} }
break; break;
case "nodes": case "nodes":
@ -72,9 +72,9 @@ export const getStacklightLikeQueryFor =
case "cpuAllocatableCapacity": case "cpuAllocatableCapacity":
return `sum(kube_node_status_allocatable{resource="cpu"}) by (node)`; return `sum(kube_node_status_allocatable{resource="cpu"}) by (node)`;
case "fsSize": case "fsSize":
return `sum(node_filesystem_size_bytes{mountpoint="/"}) by (node)`; return `sum(node_filesystem_size_bytes{mountpoint=~"${opts.mountpoints}"}) by (node)`;
case "fsUsage": case "fsUsage":
return `sum(node_filesystem_size_bytes{mountpoint="/"} - node_filesystem_avail_bytes{mountpoint="/"}) by (node)`; return `sum(node_filesystem_size_bytes{mountpoint=~"${opts.mountpoints}"} - node_filesystem_avail_bytes{mountpoint=~"${opts.mountpoints}"}) by (node)`;
} }
break; break;
case "pods": case "pods":