Monitoring bandwidth for 2 seconds when running status main.

Updating archive's single-file call to use asyncio as well as fixing JSON error that used to be thrown.

Trying two place for single-file executable.

Adding more docs to bandwidth functions.  Extracting reused functions out.  Testing worker.

Ordering bandwidth statuses by their name.

Breaking down bandwidth by interface.

Splitting download buttons to avoid overflow.

Creating bandwidth worker which tracks server bandwidth usage to display on the status page.

Testing get_bandwidth_info() with no psutil.

Using psutil to fetch status.  Adding bandwidth status.
This commit is contained in:
Roland 2022-09-29 16:36:39 -06:00 • committed by lrnselfreliance
parent d82b7c12fb
commit c235ef65f3
11 changed files with 475 additions and 56 deletions

View file

@ -1,9 +1,10 @@
import {Header, Loader, Progress, Statistic, StatisticGroup} from "../Theme";
import React from "react";
import {humanFileSize, LoadStatistic} from "../Common";
import {humanBandwidth, humanFileSize, LoadStatistic} from "../Common";
import {getStatus} from "../../api";
import {ThemeContext} from "../../contexts/contexts";
import {Container} from "semantic-ui-react";
import {Container, Divider} from "semantic-ui-react";
import {ProgressPlaceholder} from "../Placeholder";
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
function DriveInfo({used, size, percent, mount}) {
let color;
@ -20,17 +21,67 @@ function DriveInfo({used, size, percent, mount}) {
/>
}
function CPUTemperatureStatistic({value}) {
function CPUTemperatureStatistic({value, high_temperature, critical_temperature}) {
if (!value) {
return <Statistic label='Temp C°' value='?'/>
}
let color;
if (value >= 75) {
color = 'red';
} else if (value >= 50) {
color = 'yellow';
const props = {};
if ((critical_temperature && value >= critical_temperature) || (!critical_temperature && value >= 75)) {
props['color'] = 'red';
} else if ((high_temperature && value >= high_temperature) || (!high_temperature && value >= 60)) {
props['color'] = 'orange';
}
return <Statistic label='Temp C°' value={value} color={color}/>
return <Statistic label='Temp C°' value={value} {...props}/>
}
export function BandwidthProgress({label = '', bytes, maxBytes, ...props}) {
// Gigabit by default.
maxBytes = maxBytes || 125_000_000;
label = `${label} (${humanBandwidth(bytes)})`;
const percent = (bytes / maxBytes);
if (percent > 70) {
props['color'] = 'yellow';
} else if (percent > 90) {
props['color'] = 'red';
}
return <Progress percent={percent} label={label} {...props}/>
}
export function BandwidthProgressGroup({bandwidth, ...props}) {
// NIC speed to bytes.
const maxBytes = bandwidth['speed'] * 125_000;
const recv = <BandwidthProgress
bytes={bandwidth['bytes_recv']}
label={`${bandwidth['name']} In`}
maxBytes={maxBytes}
{...props}
/>;
const sent = <BandwidthProgress
bytes={bandwidth['bytes_sent']}
label={`${bandwidth['name']} Out`}
maxBytes={maxBytes}
{...props}
/>;
return <Grid columns={2} stackable>
<Grid.Row>
<Grid.Column>
{recv}
</Grid.Column>
<Grid.Column>
{sent}
</Grid.Column>
</Grid.Row>
</Grid>
}
export function BandwidthProgressCombined({bandwidth , ...props}) {
const maxBytes = bandwidth['speed'] ? bandwidth['speed'] * 125_000 : 125_000_000;
const combined = bandwidth['bytes_recv'] + bandwidth['bytes_sent']
return <BandwidthProgress label={bandwidth['name']} bytes={combined} maxBytes={maxBytes} {...props}/>
}
export function CPUUsageProgress({value, label}) {
@ -82,33 +133,44 @@ export class Status extends React.Component {
render() {
if (this.state.status) {
const {cpu_info, load, drives} = this.state.status;
const {cpu_info, load, drives, bandwidth} = this.state.status;
const {minute_1, minute_5, minute_15} = load;
const {percent, cores, temperature} = cpu_info;
const {percent, cores, temperature, high_temperature, critical_temperature} = cpu_info;
return <ThemeContext.Consumer>
{({i}) => <>
<CPUUsageProgress value={percent} label='CPU Usage'/>
return <>
<CPUUsageProgress value={percent} label='CPU Usage'/>
<CPUTemperatureStatistic value={temperature}/>
<Statistic label='Cores' value={cores || '?'}/>
<StatisticGroup>
<LoadStatistic label='1 Minute Load' value={minute_1} cores={cores}/>
<LoadStatistic label='5 Minute Load' value={minute_5} cores={cores}/>
<LoadStatistic label='15 Minute Load' value={minute_15} cores={cores}/>
</StatisticGroup>
<CPUTemperatureStatistic
value={temperature}
high_temperature={high_temperature}
critical_temperature={critical_temperature}
/>
<Statistic label='Cores' value={cores || '?'}/>
<Header as='h2'>Drive Usage</Header>
{drives.map((drive) => <DriveInfo key={drive['mount']} {...drive}/>)}
</>}
</ThemeContext.Consumer>
<Divider/>
<StatisticGroup>
<LoadStatistic label='1 Minute Load' value={minute_1} cores={cores}/>
<LoadStatistic label='5 Minute Load' value={minute_5} cores={cores}/>
<LoadStatistic label='15 Minute Load' value={minute_15} cores={cores}/>
</StatisticGroup>
<Divider/>
<Header as='h1'>Bandwidth</Header>
{bandwidth ?
bandwidth.map(i => <BandwidthProgressGroup key={i['name']} bandwidth={i}/>) :
<ProgressPlaceholder/>}
<Divider/>
<Header as='h1'>Drive Usage</Header>
{drives.map((drive) => <DriveInfo key={drive['mount']} {...drive}/>)}
</>
}
return <ThemeContext.Consumer>
{({i}) => <Container fluid style={{marginBottom: '5em'}}>
<Loader active inline='centered'>Loading system status</Loader>;
</Container>
}
</ThemeContext.Consumer>
return <Container fluid style={{marginBottom: '5em'}}>
<Loader active inline='centered' size='big'>Loading system status</Loader>
</Container>
}
}