-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
task/TUP-331 -- system monitor client (#50)
* useSystemMonitor hook * useSystemMonitor hook * sysmon should use hook results * fix system monitor hook not returning values * clean up system monitor data structure * Convert sysmon to typescript * System monitor tests * Comment about alternate baseUrl * linting * Use more idiomatic types for table cells * Set correct URLs for profile and sysmon * Set local dev tup-services url to http://localhost:8001 * Fix system monitor operational status test * Truncate load percentage * formatting Co-authored-by: jarosenb <jrosenberg@tacc.utexas.edu>
- Loading branch information
1 parent
ecdd9f4
commit 3d8fb3c
Showing
19 changed files
with
592 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
apps/tup-ui/src/components/sysmon/SystemMonitor.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
.root { | ||
--table-border: 1px solid black; | ||
|
||
margin: 0; | ||
width: 100%; | ||
|
||
font-size: 0.875rem; /* 14px (approved deviation from design) */ | ||
} | ||
|
||
.rows tr:nth-child(even) { | ||
background-color: rgb(0 0 0 / 3%); | ||
} | ||
.rows tr:hover { | ||
background-color: rgb(0 0 0 / 5%); | ||
} | ||
.rows td { | ||
padding: 5px 8px; | ||
} | ||
|
||
.header { | ||
border-bottom: var(--table-border); | ||
} | ||
|
||
/* Columns */ | ||
@media only screen and (min-width: 1200px) { | ||
/* name */ | ||
.root tr > *:nth-child(1) { | ||
width: 22%; | ||
} | ||
/* status */ | ||
.root tr > *:nth-child(2) { | ||
width: 30%; | ||
} | ||
/* load */ | ||
.root tr > *:nth-child(3) { | ||
width: 16%; | ||
} | ||
/* run */ | ||
.root tr > *:nth-child(4) { | ||
width: 16%; | ||
} | ||
/* queue */ | ||
.root tr > *:nth-child(5) { | ||
width: 16%; | ||
} | ||
} | ||
@media only screen and (max-width: 1199px) { | ||
/* name */ | ||
.root tr > *:nth-child(1) { | ||
width: 22%; | ||
} | ||
/* status */ | ||
.root tr > *:nth-child(2) { | ||
width: 24%; | ||
} | ||
/* load */ | ||
.root tr > *:nth-child(3) { | ||
width: 18%; | ||
} | ||
/* run */ | ||
.root tr > *:nth-child(4) { | ||
width: 18%; | ||
} | ||
/* queue */ | ||
.root tr > *:nth-child(5) { | ||
width: 18%; | ||
} | ||
} | ||
|
||
/* Messaging */ | ||
.error { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
color: var(--global-color-accent--normal); | ||
padding: 30px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import SystemMonitor from './SystemMonitor'; | ||
import { testRender } from '../../utils'; | ||
import { waitFor } from '@testing-library/react'; | ||
|
||
describe('System Monitor Component', () => { | ||
it('display a no-systems message when there is no data', async () => { | ||
const { getByText } = testRender(<SystemMonitor hosts={[]} />); | ||
await waitFor(() => | ||
expect(getByText('No systems being monitored')).toBeDefined() | ||
); | ||
}); | ||
it('should display the system name in each row', async () => { | ||
const { getByText } = testRender(<SystemMonitor />); | ||
await waitFor(() => expect(getByText('Frontera')).toBeDefined()); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import React, { useMemo } from 'react'; | ||
import { useTable, Column } from 'react-table'; | ||
import { LoadingSpinner, Message } from '@tacc/core-components'; | ||
import { Display, Operational, Load } from './SystemMonitorCells'; | ||
import { SystemMonitorSystem, useSystemMonitor } from '../../hooks'; | ||
import styles from './SystemMonitor.module.css'; | ||
|
||
const SystemMonitor: React.FC<{ hosts?: Array<string> }> = ({ hosts }) => { | ||
const { systems, isLoading, error } = useSystemMonitor(hosts); | ||
const columns = useMemo<Column<SystemMonitorSystem>[]>( | ||
() => [ | ||
{ | ||
accessor: 'display_name', | ||
Header: 'Name', | ||
Cell: Display, | ||
}, | ||
{ | ||
accessor: 'isOperational', | ||
Header: 'Status', | ||
Cell: Operational, | ||
}, | ||
{ | ||
accessor: 'loadPercentage', | ||
Header: 'Load', | ||
Cell: Load, | ||
}, | ||
{ | ||
accessor: ({ jobs }) => (jobs ? jobs.running : '--'), | ||
Header: 'Running', | ||
}, | ||
{ | ||
accessor: ({ jobs }) => (jobs ? jobs.queued : '--'), | ||
Header: 'Queued', | ||
}, | ||
], | ||
[] | ||
); | ||
const { getTableProps, getTableBodyProps, rows, prepareRow, headerGroups } = | ||
useTable({ | ||
columns, | ||
data: systems, | ||
}); | ||
|
||
if (isLoading) { | ||
return <LoadingSpinner />; | ||
} | ||
|
||
if (error) { | ||
return ( | ||
<Message type="warn" className={styles['error']}> | ||
Unable to gather system information | ||
</Message> | ||
); | ||
} | ||
|
||
return ( | ||
<table | ||
{...getTableProps()} | ||
// Emulate <InfiniteScrollTable> and its use of `o-fixed-header-table` | ||
// TODO: Create global table styles & Make <InfiniteScrollTable> use them | ||
className={`multi-system InfiniteScrollTable o-fixed-header-table ${styles['root']}`} | ||
> | ||
<thead> | ||
{headerGroups.map((headerGroup) => ( | ||
<tr | ||
{...headerGroup.getHeaderGroupProps()} | ||
className={styles['header']} | ||
> | ||
{headerGroup.headers.map((column) => ( | ||
<th key={column.id}>{column.render('Header')}</th> | ||
))} | ||
</tr> | ||
))} | ||
</thead> | ||
<tbody {...getTableBodyProps()} className={styles['rows']}> | ||
{rows.length ? ( | ||
rows.map((row, idx) => { | ||
prepareRow(row); | ||
return ( | ||
<tr {...row.getRowProps()}> | ||
{row.cells.map((cell) => ( | ||
<td {...cell.getCellProps()}>{cell.render('Cell')}</td> | ||
))} | ||
</tr> | ||
); | ||
}) | ||
) : ( | ||
<tr> | ||
<td colSpan={5}>No systems being monitored</td> | ||
</tr> | ||
)} | ||
</tbody> | ||
</table> | ||
); | ||
}; | ||
|
||
export default SystemMonitor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from 'react'; | ||
import { Pill } from '@tacc/core-components'; | ||
import { Cell } from 'react-table'; | ||
import { SystemMonitorSystem } from '../../hooks'; | ||
|
||
export const Display: React.FC<{ cell: Cell<SystemMonitorSystem, string> }> = ({ | ||
cell: { value }, | ||
}) => <strong className="wb-text-primary">{value}</strong>; | ||
|
||
export const Operational: React.FC<{ | ||
cell: Cell<SystemMonitorSystem, boolean>; | ||
}> = ({ cell: { value } }) => { | ||
if (value) { | ||
return <Pill type="success">Operational</Pill>; | ||
} | ||
return <Pill type="warning">Maintenance</Pill>; | ||
}; | ||
|
||
export const Load: React.FC<{ | ||
cell: Cell<SystemMonitorSystem, number | undefined>; | ||
}> = ({ cell: { value } }) => <span>{value ? `${value}%` : '--'}</span>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './SystemMonitor'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.