Skip to content

Commit 6902afa

Browse files
feat(MetricChart): display per pool cpu usage (#769)
1 parent fd6ae9a commit 6902afa

File tree

4 files changed

+37
-14
lines changed

4 files changed

+37
-14
lines changed

src/components/MetricChart/getDefaultDataFormatter.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ export const getDefaultDataFormatter = (dataType?: ChartDataType) => {
1414
case 'size': {
1515
return formatChartValueToSize;
1616
}
17+
case 'percent': {
18+
return formatChartValueToPercent;
19+
}
1720
default:
1821
return undefined;
1922
}
@@ -34,6 +37,12 @@ function formatChartValueToSize(value: ChartValue) {
3437
}
3538
return formatBytes({value: convertToNumber(value), precision: 3});
3639
}
40+
function formatChartValueToPercent(value: ChartValue) {
41+
if (value === null) {
42+
return EMPTY_DATA_PLACEHOLDER;
43+
}
44+
return Math.round(convertToNumber(value) * 100) + '%';
45+
}
3746

3847
// Numeric values expected, not numeric value should be displayd as 0
3948
function convertToNumber(value: unknown): number {

src/components/MetricChart/types.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1+
import type {PoolName} from '../../types/api/nodes';
2+
3+
type Percentile = 'p50' | 'p75' | 'p90' | 'p99';
4+
type QueriesLatenciesMetric = `queries.latencies.${Percentile}`;
5+
6+
type PoolUsageMetric = `resources.cpu.${PoolName}.usage`;
7+
18
export type Metric =
29
| 'queries.requests'
3-
| 'queries.latencies.p50'
4-
| 'queries.latencies.p75'
5-
| 'queries.latencies.p90'
6-
| 'queries.latencies.p99'
7-
| 'resources.cpu.usage'
810
| 'resources.memory.used_bytes'
9-
| 'resources.storage.used_bytes';
11+
| 'resources.storage.used_bytes'
12+
| 'resources.cpu.usage'
13+
| PoolUsageMetric
14+
| QueriesLatenciesMetric;
1015

1116
export interface MetricDescription {
1217
target: Metric;
@@ -25,7 +30,7 @@ export interface PreparedMetricsData {
2530

2631
export type ChartValue = number | string | null;
2732

28-
export type ChartDataType = 'ms' | 'size';
33+
export type ChartDataType = 'ms' | 'size' | 'percent';
2934

3035
export interface ChartOptions {
3136
dataType?: ChartDataType;
Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1+
import type {MetricDescription} from '../../../../../components/MetricChart';
2+
import type {PoolName} from '../../../../../types/api/nodes';
13
import type {ChartConfig} from '../TenantDashboard/TenantDashboard';
24
import i18n from '../i18n';
35

6+
const pools: PoolName[] = ['IC', 'IO', 'Batch', 'User', 'System'];
7+
8+
const getPoolMetricConfig = (poolName: PoolName): MetricDescription => {
9+
return {
10+
target: `resources.cpu.${poolName}.usage`,
11+
title: poolName,
12+
};
13+
};
14+
415
export const cpuDashboardConfig: ChartConfig[] = [
516
{
617
title: i18n('charts.cpu-usage'),
7-
metrics: [
8-
{
9-
target: 'resources.cpu.usage',
10-
title: i18n('charts.cpu-usage'),
11-
},
12-
],
18+
metrics: pools.map(getPoolMetricConfig),
19+
options: {
20+
dataType: 'percent',
21+
},
1322
},
1423
];

src/containers/Tenant/Diagnostics/TenantOverview/i18n/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
"charts.queries-per-second": "Queries per second",
2525
"charts.transaction-latency": "Transactions latencies {{percentile}}",
26-
"charts.cpu-usage": "CPU cores used",
26+
"charts.cpu-usage": "CPU usage by pool",
2727
"charts.storage-usage": "Tablet storage usage",
2828
"charts.memory-usage": "Memory usage",
2929

0 commit comments

Comments
 (0)