1
1
import DataTable from '@gravity-ui/react-data-table' ;
2
+ import { DefinitionList } from '@gravity-ui/uikit' ;
2
3
3
4
import { getLoadSeverityForNode } from '../../store/reducers/nodes/utils' ;
4
5
import type { TPoolStats } from '../../types/api/nodes' ;
5
6
import type { TTabletStateInfo } from '../../types/api/tablet' ;
6
7
import { valueIsDefined } from '../../utils' ;
8
+ import { cn } from '../../utils/cn' ;
7
9
import { EMPTY_DATA_PLACEHOLDER } from '../../utils/constants' ;
8
- import { formatStorageValuesToGb } from '../../utils/dataFormatters/dataFormatters' ;
10
+ import {
11
+ formatStorageValues ,
12
+ formatStorageValuesToGb ,
13
+ } from '../../utils/dataFormatters/dataFormatters' ;
9
14
import { getSpaceUsageSeverity } from '../../utils/storage' ;
10
15
import type { Column } from '../../utils/tableUtils/types' ;
16
+ import { isNumeric } from '../../utils/utils' ;
11
17
import { CellWithPopover } from '../CellWithPopover/CellWithPopover' ;
12
18
import { NodeHostWrapper } from '../NodeHostWrapper/NodeHostWrapper' ;
13
19
import type { NodeHostData } from '../NodeHostWrapper/NodeHostWrapper' ;
14
20
import { PoolsGraph } from '../PoolsGraph/PoolsGraph' ;
15
21
import { ProgressViewer } from '../ProgressViewer/ProgressViewer' ;
16
22
import { TabletsStatistic } from '../TabletsStatistic' ;
23
+ import { formatPool } from '../TooltipsContent' ;
17
24
import { UsageLabel } from '../UsageLabel/UsageLabel' ;
18
25
19
26
import { NODES_COLUMNS_IDS , NODES_COLUMNS_TITLES } from './constants' ;
27
+ import i18n from './i18n' ;
20
28
import type { GetNodesColumnsParams } from './types' ;
21
29
30
+ import './NodesColumns.scss' ;
31
+
32
+ const b = cn ( 'ydb-nodes-columns' ) ;
33
+
22
34
export function getNodeIdColumn < T extends { NodeId ?: string | number } > ( ) : Column < T > {
23
35
return {
24
36
name : NODES_COLUMNS_IDS . NodeId ,
@@ -111,6 +123,57 @@ export function getMemoryColumn<
111
123
resizeMinWidth : 170 ,
112
124
} ;
113
125
}
126
+
127
+ export function getRAMColumn < T extends { MemoryUsed ?: string ; MemoryLimit ?: string } > ( ) : Column < T > {
128
+ return {
129
+ name : NODES_COLUMNS_IDS . RAM ,
130
+ header : NODES_COLUMNS_TITLES . RAM ,
131
+ sortAccessor : ( { MemoryUsed = 0 } ) => Number ( MemoryUsed ) ,
132
+ defaultOrder : DataTable . DESCENDING ,
133
+ render : ( { row} ) => {
134
+ const [ memoryUsed , memoryLimit ] =
135
+ isNumeric ( row . MemoryUsed ) && isNumeric ( row . MemoryLimit )
136
+ ? formatStorageValues (
137
+ Number ( row . MemoryUsed ) ,
138
+ Number ( row . MemoryLimit ) ,
139
+ 'gb' ,
140
+ undefined ,
141
+ true ,
142
+ )
143
+ : [ 0 , 0 ] ;
144
+ return (
145
+ < CellWithPopover
146
+ placement = { [ 'top' , 'auto' ] }
147
+ fullWidth
148
+ content = {
149
+ < DefinitionList responsive >
150
+ < DefinitionList . Item name = { i18n ( 'field_memory-used' ) } >
151
+ { memoryUsed }
152
+ </ DefinitionList . Item >
153
+ < DefinitionList . Item name = { i18n ( 'field_memory-limit' ) } >
154
+ { memoryLimit }
155
+ </ DefinitionList . Item >
156
+ </ DefinitionList >
157
+ }
158
+ >
159
+ < ProgressViewer
160
+ value = { row . MemoryUsed }
161
+ capacity = { row . MemoryLimit }
162
+ formatValues = { ( value , total ) =>
163
+ formatStorageValues ( value , total , 'gb' , undefined , true )
164
+ }
165
+ className = { b ( 'column-ram' ) }
166
+ colorizeProgress
167
+ hideCapacity
168
+ />
169
+ </ CellWithPopover >
170
+ ) ;
171
+ } ,
172
+ align : DataTable . LEFT ,
173
+ width : 80 ,
174
+ resizeMinWidth : 40 ,
175
+ } ;
176
+ }
114
177
export function getSharedCacheUsageColumn <
115
178
T extends { SharedCacheUsed ?: string | number ; SharedCacheLimit ?: string | number } ,
116
179
> ( ) : Column < T > {
@@ -130,10 +193,10 @@ export function getSharedCacheUsageColumn<
130
193
resizeMinWidth : 170 ,
131
194
} ;
132
195
}
133
- export function getCpuColumn < T extends { PoolStats ?: TPoolStats [ ] } > ( ) : Column < T > {
196
+ export function getPoolsColumn < T extends { PoolStats ?: TPoolStats [ ] } > ( ) : Column < T > {
134
197
return {
135
- name : NODES_COLUMNS_IDS . CPU ,
136
- header : NODES_COLUMNS_TITLES . CPU ,
198
+ name : NODES_COLUMNS_IDS . Pools ,
199
+ header : NODES_COLUMNS_TITLES . Pools ,
137
200
sortAccessor : ( { PoolStats = [ ] } ) => Math . max ( ...PoolStats . map ( ( { Usage} ) => Number ( Usage ) ) ) ,
138
201
defaultOrder : DataTable . DESCENDING ,
139
202
render : ( { row} ) =>
@@ -143,6 +206,65 @@ export function getCpuColumn<T extends {PoolStats?: TPoolStats[]}>(): Column<T>
143
206
resizeMinWidth : 60 ,
144
207
} ;
145
208
}
209
+ export function getCpuColumn <
210
+ T extends { PoolStats ?: TPoolStats [ ] ; CoresUsed ?: number ; CoresTotal ?: number } ,
211
+ > ( ) : Column < T > {
212
+ return {
213
+ name : NODES_COLUMNS_IDS . CPU ,
214
+ header : NODES_COLUMNS_TITLES . CPU ,
215
+ sortAccessor : ( { PoolStats = [ ] } ) => Math . max ( ...PoolStats . map ( ( { Usage} ) => Number ( Usage ) ) ) ,
216
+ defaultOrder : DataTable . DESCENDING ,
217
+ render : ( { row} ) => {
218
+ if ( ! row . PoolStats ) {
219
+ return EMPTY_DATA_PLACEHOLDER ;
220
+ }
221
+
222
+ let totalPoolUsage =
223
+ isNumeric ( row . CoresUsed ) && isNumeric ( row . CoresTotal )
224
+ ? row . CoresUsed / row . CoresTotal
225
+ : undefined ;
226
+
227
+ if ( totalPoolUsage === undefined ) {
228
+ let totalThreadsCount = 0 ;
229
+ totalPoolUsage = row . PoolStats . reduce ( ( acc , pool ) => {
230
+ totalThreadsCount += Number ( pool . Threads ) ;
231
+ return acc + Number ( pool . Usage ) * Number ( pool . Threads ) ;
232
+ } , 0 ) ;
233
+
234
+ totalPoolUsage = totalPoolUsage / totalThreadsCount ;
235
+ }
236
+
237
+ return (
238
+ < CellWithPopover
239
+ placement = { [ 'top' , 'auto' ] }
240
+ fullWidth
241
+ content = {
242
+ < DefinitionList responsive >
243
+ { row . PoolStats . map ( ( pool ) =>
244
+ isNumeric ( pool . Usage ) ? (
245
+ < DefinitionList . Item key = { pool . Name } name = { pool . Name } >
246
+ { formatPool ( 'Usage' , pool . Usage ) . value }
247
+ </ DefinitionList . Item >
248
+ ) : null ,
249
+ ) }
250
+ </ DefinitionList >
251
+ }
252
+ >
253
+ < ProgressViewer
254
+ className = { b ( 'column-cpu' ) }
255
+ value = { totalPoolUsage }
256
+ capacity = { 1 }
257
+ colorizeProgress
258
+ percents
259
+ />
260
+ </ CellWithPopover >
261
+ ) ;
262
+ } ,
263
+ align : DataTable . LEFT ,
264
+ width : 80 ,
265
+ resizeMinWidth : 40 ,
266
+ } ;
267
+ }
146
268
export function getLoadAverageColumn < T extends { LoadAveragePercents ?: number [ ] } > ( ) : Column < T > {
147
269
return {
148
270
name : NODES_COLUMNS_IDS . LoadAverage ,
0 commit comments