Skip to content

Commit

Permalink
feat(MetricChart): display per pool cpu usage (#769)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemmufazalov authored Mar 21, 2024
1 parent fd6ae9a commit 6902afa
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
9 changes: 9 additions & 0 deletions src/components/MetricChart/getDefaultDataFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export const getDefaultDataFormatter = (dataType?: ChartDataType) => {
case 'size': {
return formatChartValueToSize;
}
case 'percent': {
return formatChartValueToPercent;
}
default:
return undefined;
}
Expand All @@ -34,6 +37,12 @@ function formatChartValueToSize(value: ChartValue) {
}
return formatBytes({value: convertToNumber(value), precision: 3});
}
function formatChartValueToPercent(value: ChartValue) {
if (value === null) {
return EMPTY_DATA_PLACEHOLDER;
}
return Math.round(convertToNumber(value) * 100) + '%';
}

// Numeric values expected, not numeric value should be displayd as 0
function convertToNumber(value: unknown): number {
Expand Down
19 changes: 12 additions & 7 deletions src/components/MetricChart/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import type {PoolName} from '../../types/api/nodes';

type Percentile = 'p50' | 'p75' | 'p90' | 'p99';
type QueriesLatenciesMetric = `queries.latencies.${Percentile}`;

type PoolUsageMetric = `resources.cpu.${PoolName}.usage`;

export type Metric =
| 'queries.requests'
| 'queries.latencies.p50'
| 'queries.latencies.p75'
| 'queries.latencies.p90'
| 'queries.latencies.p99'
| 'resources.cpu.usage'
| 'resources.memory.used_bytes'
| 'resources.storage.used_bytes';
| 'resources.storage.used_bytes'
| 'resources.cpu.usage'
| PoolUsageMetric
| QueriesLatenciesMetric;

export interface MetricDescription {
target: Metric;
Expand All @@ -25,7 +30,7 @@ export interface PreparedMetricsData {

export type ChartValue = number | string | null;

export type ChartDataType = 'ms' | 'size';
export type ChartDataType = 'ms' | 'size' | 'percent';

export interface ChartOptions {
dataType?: ChartDataType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import type {MetricDescription} from '../../../../../components/MetricChart';
import type {PoolName} from '../../../../../types/api/nodes';
import type {ChartConfig} from '../TenantDashboard/TenantDashboard';
import i18n from '../i18n';

const pools: PoolName[] = ['IC', 'IO', 'Batch', 'User', 'System'];

const getPoolMetricConfig = (poolName: PoolName): MetricDescription => {
return {
target: `resources.cpu.${poolName}.usage`,
title: poolName,
};
};

export const cpuDashboardConfig: ChartConfig[] = [
{
title: i18n('charts.cpu-usage'),
metrics: [
{
target: 'resources.cpu.usage',
title: i18n('charts.cpu-usage'),
},
],
metrics: pools.map(getPoolMetricConfig),
options: {
dataType: 'percent',
},
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

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

Expand Down

0 comments on commit 6902afa

Please sign in to comment.