2021-04-28 15:50:42 +00:00
|
|
|
import { useContext } from 'react';
|
2021-04-15 14:53:31 +00:00
|
|
|
import { Box } from '@material-ui/core';
|
2021-03-17 16:36:48 +00:00
|
|
|
import * as prettyBytes from 'pretty-bytes';
|
2021-04-30 15:43:03 +00:00
|
|
|
import { Panel } from './Panels';
|
2021-04-08 16:20:10 +00:00
|
|
|
import { AllocationBar } from './Bars';
|
2021-03-09 22:20:27 +00:00
|
|
|
import { HeaderText, BodyText } from './Text';
|
2021-03-17 16:36:48 +00:00
|
|
|
import PeriodicFetch from '../lib/fetchers/periodicFetch';
|
2021-04-28 15:50:42 +00:00
|
|
|
import { AnvilContext } from './AnvilContext';
|
2021-05-28 00:31:34 +00:00
|
|
|
import Spinner from './Spinner';
|
2021-03-17 16:36:48 +00:00
|
|
|
|
2021-04-28 15:50:42 +00:00
|
|
|
const Memory = (): JSX.Element => {
|
|
|
|
const { uuid } = useContext(AnvilContext);
|
2021-03-22 15:38:20 +00:00
|
|
|
const { data, isLoading } = PeriodicFetch<AnvilMemory>(
|
2021-05-27 21:59:32 +00:00
|
|
|
`${process.env.NEXT_PUBLIC_API_URL}/get_memory?anvil_uuid=${uuid}`,
|
2021-03-17 16:36:48 +00:00
|
|
|
);
|
|
|
|
|
2021-05-27 22:31:59 +00:00
|
|
|
const memoryData =
|
|
|
|
isLoading || !data ? { total: 0, allocated: 0, reserved: 0 } : data;
|
2021-03-09 16:34:44 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Panel>
|
2021-04-15 14:53:31 +00:00
|
|
|
<HeaderText text="Memory" />
|
2021-05-28 00:31:34 +00:00
|
|
|
{!isLoading ? (
|
|
|
|
<>
|
|
|
|
{' '}
|
|
|
|
<Box display="flex" width="100%">
|
|
|
|
<Box flexGrow={1}>
|
|
|
|
<BodyText
|
|
|
|
text={`Allocated: ${prettyBytes.default(memoryData.allocated, {
|
|
|
|
binary: true,
|
|
|
|
})}`}
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
<Box>
|
|
|
|
<BodyText
|
|
|
|
text={`Free: ${prettyBytes.default(
|
|
|
|
memoryData.total - memoryData.allocated,
|
|
|
|
{
|
|
|
|
binary: true,
|
|
|
|
},
|
|
|
|
)}`}
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
<Box display="flex" width="100%">
|
|
|
|
<Box flexGrow={1}>
|
|
|
|
<AllocationBar
|
|
|
|
allocated={(memoryData.allocated / memoryData.total) * 100}
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
<Box display="flex" justifyContent="center" width="100%">
|
|
|
|
<BodyText
|
|
|
|
text={`Total: ${prettyBytes.default(memoryData.total, {
|
2021-05-27 22:18:05 +00:00
|
|
|
binary: true,
|
2021-05-28 00:31:34 +00:00
|
|
|
})} | Reserved: ${prettyBytes.default(memoryData.reserved, {
|
|
|
|
binary: true,
|
|
|
|
})}`}
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<Spinner />
|
|
|
|
)}
|
2021-03-09 16:34:44 +00:00
|
|
|
</Panel>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Memory;
|