mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Respond to review comments
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
7b1a092616
commit
a9411b2337
@ -56,11 +56,13 @@ enum columnId {
|
|||||||
interface Props extends RouteComponentProps<NodesRouteParams> {
|
interface Props extends RouteComponentProps<NodesRouteParams> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MetricsTooltipFormatter = (metrics: [number, number]) => string;
|
||||||
|
|
||||||
interface UsageArgs {
|
interface UsageArgs {
|
||||||
node: Node;
|
node: Node;
|
||||||
title: string;
|
title: string;
|
||||||
metricNames: [string, string];
|
metricNames: [string, string];
|
||||||
secondFormater: (metrics: [number, number]) => string;
|
formatters: MetricsTooltipFormatter[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
@ -85,18 +87,17 @@ export class Nodes extends React.Component<Props> {
|
|||||||
if (isEmpty(this.metrics)) {
|
if (isEmpty(this.metrics)) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const nodeName = node.getName();
|
const nodeName = node.getName();
|
||||||
|
|
||||||
return metricNames.map(metricName => {
|
return metricNames.map(metricName => {
|
||||||
try {
|
try {
|
||||||
const metric = this.metrics[metricName];
|
const metric = this.metrics[metricName];
|
||||||
const result = metric.data.result.find(result => {
|
const result = metric.data.result.find(({ metric: { node, instance, kubernetes_node }}) => (
|
||||||
return [
|
nodeName === node
|
||||||
result.metric.node,
|
|| nodeName === instance
|
||||||
result.metric.instance,
|
|| nodeName === kubernetes_node
|
||||||
result.metric.kubernetes_node,
|
));
|
||||||
].includes(nodeName);
|
|
||||||
});
|
|
||||||
|
|
||||||
return result ? parseFloat(result.values.slice(-1)[0][1]) : 0;
|
return result ? parseFloat(result.values.slice(-1)[0][1]) : 0;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -105,7 +106,7 @@ export class Nodes extends React.Component<Props> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private renderUsage({ node, title, metricNames, secondFormater }: UsageArgs) {
|
private renderUsage({ node, title, metricNames, formatters }: UsageArgs) {
|
||||||
const metrics = this.getLastMetricValues(node, metricNames);
|
const metrics = this.getLastMetricValues(node, metricNames);
|
||||||
|
|
||||||
if (!metrics || metrics.length < 2) {
|
if (!metrics || metrics.length < 2) {
|
||||||
@ -120,7 +121,7 @@ export class Nodes extends React.Component<Props> {
|
|||||||
value={usage}
|
value={usage}
|
||||||
tooltip={{
|
tooltip={{
|
||||||
preferredPositions: TooltipPosition.BOTTOM,
|
preferredPositions: TooltipPosition.BOTTOM,
|
||||||
children: `${title}: ${(usage * 100 / capacity).toFixed(2)}%, ${secondFormater([usage, capacity])}`,
|
children: `${title}: ${formatters.map(formatter => formatter([usage, capacity])).join(", ")}`,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@ -131,7 +132,10 @@ export class Nodes extends React.Component<Props> {
|
|||||||
node,
|
node,
|
||||||
title: "CPU",
|
title: "CPU",
|
||||||
metricNames: ["cpuUsage", "cpuCapacity"],
|
metricNames: ["cpuUsage", "cpuCapacity"],
|
||||||
secondFormater: ([, cap]) => `cores: ${cap}`,
|
formatters: [
|
||||||
|
([usage, capacity]) => `${(usage * 100 / capacity).toFixed(2)}%`,
|
||||||
|
([, cap]) => `cores: ${cap}`,
|
||||||
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,16 +144,22 @@ export class Nodes extends React.Component<Props> {
|
|||||||
node,
|
node,
|
||||||
title: "Memory",
|
title: "Memory",
|
||||||
metricNames: ["workloadMemoryUsage", "memoryAllocatableCapacity"],
|
metricNames: ["workloadMemoryUsage", "memoryAllocatableCapacity"],
|
||||||
secondFormater: ([usage]) => bytesToUnits(usage, 3),
|
formatters: [
|
||||||
|
([usage, capacity]) => `${(usage * 100 / capacity).toFixed(2)}%`,
|
||||||
|
([usage]) => bytesToUnits(usage, 3),
|
||||||
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
renderDiskUsage(node: Node): any {
|
renderDiskUsage(node: Node) {
|
||||||
return this.renderUsage({
|
return this.renderUsage({
|
||||||
node,
|
node,
|
||||||
title: "Disk",
|
title: "Disk",
|
||||||
metricNames: ["fsUsage", "fsSize"],
|
metricNames: ["fsUsage", "fsSize"],
|
||||||
secondFormater: ([usage]) => bytesToUnits(usage, 3),
|
formatters: [
|
||||||
|
([usage, capacity]) => `${(usage * 100 / capacity).toFixed(2)}%`,
|
||||||
|
([usage]) => bytesToUnits(usage, 3),
|
||||||
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user