Skip to content

Commit 0f363c0

Browse files
senanzSenan Zedan (EXT-Nokia)
andauthored
feat(ws): Notebooks 2.0 // FrontEnd // Add CPU and RAM columns (#169)
* feat(ws): Notebooks 2.0 // FrontEnd // Add CPU and RAM columns Signed-off-by: Senan Zedan (EXT-Nokia) <[email protected]> * feat(ws): Notebooks 2.0 // FrontEnd // Add CPU and RAM columns Signed-off-by: Senan Zedan (EXT-Nokia) <[email protected]> --------- Signed-off-by: Senan Zedan (EXT-Nokia) <[email protected]> Co-authored-by: Senan Zedan (EXT-Nokia) <[email protected]>
1 parent 034a530 commit 0f363c0

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

workspaces/frontend/src/app/pages/Workspaces/Workspaces.tsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ import {
3535
IActions,
3636
} from '@patternfly/react-table';
3737
import { FilterIcon } from '@patternfly/react-icons';
38-
import { Workspace, WorkspaceState } from '~/shared/types';
38+
import { Workspace, WorkspaceState } from 'shared/types';
39+
import { formatRam } from 'shared/utilities/WorkspaceResources';
3940

4041
export const Workspaces: React.FunctionComponent = () => {
4142
/* Mocked workspaces, to be removed after fetching info from backend */
@@ -46,6 +47,8 @@ export const Workspaces: React.FunctionComponent = () => {
4647
paused: true,
4748
deferUpdates: true,
4849
kind: 'jupyter-lab',
50+
cpu: 3,
51+
ram: 500,
4952
podTemplate: {
5053
volumes: {
5154
home: '/home',
@@ -85,6 +88,8 @@ export const Workspaces: React.FunctionComponent = () => {
8588
paused: false,
8689
deferUpdates: false,
8790
kind: 'jupyter-lab',
91+
cpu: 1,
92+
ram: 12540,
8893
podTemplate: {
8994
volumes: {
9095
home: '/home',
@@ -129,6 +134,8 @@ export const Workspaces: React.FunctionComponent = () => {
129134
state: 'State',
130135
homeVol: 'Home Vol',
131136
dataVol: 'Data Vol',
137+
cpu: 'CPU',
138+
ram: 'Memory',
132139
lastActivity: 'Last Activity',
133140
};
134141

@@ -315,17 +322,19 @@ export const Workspaces: React.FunctionComponent = () => {
315322
const [activeSortDirection, setActiveSortDirection] = React.useState<'asc' | 'desc' | null>(null);
316323

317324
const getSortableRowValues = (workspace: Workspace): (string | number)[] => {
318-
const { name, kind, image, podConfig, state, homeVol, dataVol, lastActivity } = {
325+
const { name, kind, image, podConfig, state, homeVol, dataVol, cpu, ram, lastActivity } = {
319326
name: workspace.name,
320327
kind: workspace.kind,
321328
image: workspace.options.imageConfig,
322329
podConfig: workspace.options.podConfig,
323330
state: WorkspaceState[workspace.status.state],
324331
homeVol: workspace.podTemplate.volumes.home,
325332
dataVol: workspace.podTemplate.volumes.data[0].pvcName || '',
333+
cpu: workspace.cpu,
334+
ram: workspace.ram,
326335
lastActivity: workspace.status.activity.lastActivity,
327336
};
328-
return [name, kind, image, podConfig, state, homeVol, dataVol, lastActivity];
337+
return [name, kind, image, podConfig, state, homeVol, dataVol, cpu, ram, lastActivity];
329338
};
330339

331340
let sortedWorkspaces = filteredWorkspaces;
@@ -436,7 +445,13 @@ export const Workspaces: React.FunctionComponent = () => {
436445
<Th sort={getSortParams(4)}>{columnNames.state}</Th>
437446
<Th sort={getSortParams(5)}>{columnNames.homeVol}</Th>
438447
<Th sort={getSortParams(6)}>{columnNames.dataVol}</Th>
439-
<Th sort={getSortParams(7)}>{columnNames.lastActivity}</Th>
448+
<Th sort={getSortParams(7)} info={{ tooltip: 'Workspace CPU usage' }}>
449+
{columnNames.cpu}
450+
</Th>
451+
<Th sort={getSortParams(8)} info={{ tooltip: 'Workspace memory usage' }}>
452+
{columnNames.ram}
453+
</Th>
454+
<Th sort={getSortParams(9)}>{columnNames.lastActivity}</Th>
440455
<Th screenReaderText="Primary action" />
441456
</Tr>
442457
</Thead>
@@ -456,6 +471,8 @@ export const Workspaces: React.FunctionComponent = () => {
456471
<Td dataLabel={columnNames.dataVol}>
457472
{workspace.podTemplate.volumes.data[0].pvcName || ''}
458473
</Td>
474+
<Td dataLabel={columnNames.cpu}>{`${workspace.cpu}%`}</Td>
475+
<Td dataLabel={columnNames.ram}>{formatRam(workspace.ram)}</Td>
459476
<Td dataLabel={columnNames.lastActivity}>
460477
<Timestamp
461478
date={new Date(workspace.status.activity.lastActivity)}

workspaces/frontend/src/shared/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export interface Workspace {
5252
paused: boolean;
5353
deferUpdates: boolean;
5454
kind: string;
55+
cpu: number;
56+
ram: number;
5557
podTemplate: {
5658
volumes: {
5759
home: string;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export const formatRam = (valueInKb: number): string => {
2+
const units = ['KB', 'MB', 'GB', 'TB'];
3+
let index = 0;
4+
let value = valueInKb;
5+
6+
while (value >= 1024 && index < units.length - 1) {
7+
value /= 1024;
8+
index += 1;
9+
}
10+
11+
return `${value.toFixed(2)} ${units[index]}`;
12+
};

0 commit comments

Comments
 (0)