Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ interface MetricCardProps {

export function MetricCard({active, progress, label, status, resourcesUsed}: MetricCardProps) {
const renderContent = () => {
if (progress === undefined && resourcesUsed === undefined) {
return <div className={b('content')}>{i18n('no-data')}</div>;
}

return (
<div className={b('content')}>
{progress && <div className={b('progress')}>{formatUsage(progress)}</div>}
{resourcesUsed ? (
<div className={b('resources')}>{resourcesUsed}</div>
) : (
i18n('no-data')
)}
{resourcesUsed && <div className={b('resources')}>{resourcesUsed}</div>}
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function MetricsCards({
}: MetricsCardsProps) {
const location = useLocation();

const {memoryUsed, memoryLimit, cpuUsed, cpuUsage, storageUsed, storageLimit} = metrics || {};
const {memoryUsed, memoryLimit, cpuUsage, storageUsed, storageLimit} = metrics || {};

const {metricsTab} = useTypedSelector((state) => state.tenant);

Expand All @@ -64,8 +64,7 @@ export function MetricsCards({
const storageStatus = storageUsageToStatus(storageUsage);
const memoryStatus = memoryUsageToStatus(memoryUsage);

const {cpu, storage, memory} = formatTenantMetrics({
cpu: cpuUsed,
const {storage, memory} = formatTenantMetrics({
storage: storageUsed,
memory: memoryUsed,
});
Expand Down Expand Up @@ -107,7 +106,6 @@ export function MetricsCards({
label="CPU"
progress={cpuUsage}
status={cpuStatus}
resourcesUsed={cpu}
active={metricsTab === TENANT_METRICS_TABS_IDS.cpu}
/>
</Link>
Expand Down
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 usage",
"charts.cpu-usage": "CPU cores used",
"charts.storage-usage": "Tablet storage usage",
"charts.memory-usage": "Memory usage",

Expand Down
26 changes: 17 additions & 9 deletions src/store/reducers/tenants/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type {TPoolStats} from '../../../types/api/nodes';
import type {TTenant} from '../../../types/api/tenant';
import {formatBytes} from '../../../utils/bytesParsers';
import {formatCPUWithLabel} from '../../../utils/dataFormatters/dataFormatters';
Expand All @@ -21,6 +22,20 @@ const getTenantBackend = (tenant: TTenant) => {
return node.Host ? `${node.Host}${address ? address : ''}` : undefined;
};

const calculateCpuUsage = (poolsStats: TPoolStats[] | undefined) => {
if (!poolsStats) {
return undefined;
}

const systemPoolUsage = poolsStats?.find(({Name}) => Name === 'System')?.Usage || 0;
const userPoolUsage = poolsStats?.find(({Name}) => Name === 'User')?.Usage || 0;
const icPoolUsage = poolsStats?.find(({Name}) => Name === 'IC')?.Usage || 0;

// We use max of system, user and ic pools usage to calculate cpu usage because
// only these pools directly indicate resources available to perform user queries
return Math.max(Number(systemPoolUsage), Number(userPoolUsage), Number(icPoolUsage)) * 100;
};

export const calculateTenantMetrics = (tenant?: TTenant) => {
const {
CoresUsed,
Expand All @@ -33,20 +48,13 @@ export const calculateTenantMetrics = (tenant?: TTenant) => {
DatabaseQuotas = {},
} = tenant || {};

const systemPoolUsage = PoolStats?.find(({Name}) => Name === 'System')?.Usage;
const userPoolUsage = PoolStats?.find(({Name}) => Name === 'User')?.Usage;

const cpu = isNumeric(CoresUsed) ? Number(CoresUsed) * 1_000_000 : undefined;
const memory = isNumeric(MemoryUsed) ? Number(MemoryUsed) : undefined;
const blobStorage = isNumeric(StorageAllocatedSize) ? Number(StorageAllocatedSize) : undefined;
const tabletStorage = isNumeric(Metrics.Storage) ? Number(Metrics.Storage) : undefined;

// We use system pool usage and user pool usage to calculate cpu usage because
// only these pools directly indicate resources available to perform user queries
const cpuUsage =
isNumeric(systemPoolUsage) || isNumeric(userPoolUsage)
? Math.max(Number(systemPoolUsage), Number(userPoolUsage)) * 100
: undefined;
const cpuUsage = calculateCpuUsage(PoolStats);

const memoryLimit = isNumeric(MemoryLimit) ? Number(MemoryLimit) : undefined;
const blobStorageLimit = isNumeric(StorageAllocatedLimit)
? Number(StorageAllocatedLimit)
Expand Down
4 changes: 3 additions & 1 deletion src/types/api/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ export interface TSystemStateInfo {
TotalSessions?: number;
}

export type PoolName = 'System' | 'User' | 'Batch' | 'IO' | 'IC';

export interface TPoolStats {
Name?: string;
Name?: PoolName;
/** double */
Usage?: number;
Threads?: number;
Expand Down