Top processes are displayed on Status page. Nice of renderd is lowered to avoid clobbering system at startup.

This commit is contained in:
Roland 2024-08-15 21:45:06 -06:00
parent 47b4da1cfe
commit 317f3f3dfb
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
26 changed files with 500 additions and 415 deletions

View file

@ -1,10 +1,20 @@
import {Accordion, Header, Progress, Segment, Statistic, StatisticGroup} from "../Theme";
import {Accordion, Header, Progress, Segment, Statistic, StatisticGroup, Table} from "../Theme";
import React, {useContext} from "react";
import {humanBandwidth, humanFileSize, LoadStatistic, useTitle} from "../Common";
import {ProgressPlaceholder} from "../Placeholder";
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
import {Media, SettingsContext, StatusContext, ThemeContext} from "../../contexts/contexts";
import {AccordionContent, AccordionTitle, SegmentGroup} from "semantic-ui-react";
import {
AccordionContent,
AccordionTitle,
SegmentGroup,
TableBody,
TableCell,
TableHeader,
TableHeaderCell,
TableRow
} from "semantic-ui-react";
import _ from "lodash";
import Icon from "semantic-ui-react/dist/commonjs/elements/Icon";
function DriveInfo({used, size, percent, mount}) {
@ -38,17 +48,17 @@ function DiskBandwidthProgress({bytes_ps, total, label, ...props}) {
return <Progress percent={percent} label={label} color={color} key={label} {...props}/>;
}
function DiskBandwidth({name, bytes_read_ps, bytes_write_ps, maximum_read_ps, maximum_write_ps}) {
function DiskBandwidth({name, bytes_read_ps, bytes_write_ps, max_read_ps, max_write_ps}) {
const read = <DiskBandwidthProgress
bytes_ps={bytes_read_ps}
total={maximum_read_ps}
total={max_read_ps}
label={`${name} read`}
size='tiny'
disabled={bytes_read_ps === 0}
/>;
const write = <DiskBandwidthProgress
bytes_ps={bytes_write_ps}
total={maximum_write_ps}
total={max_write_ps}
label={`${name} write`}
size='tiny'
disabled={bytes_write_ps === 0}
@ -79,7 +89,7 @@ export function BandwidthProgress({label = '', bytes, maxBytes, ...props}) {
maxBytes = maxBytes || 125_000_000;
label = `${label} (${humanBandwidth(bytes)})`;
const percent = (bytes / maxBytes);
const percent = (bytes / maxBytes) * 100;
if (percent > 70) {
props['color'] = 'yellow';
} else if (percent > 90) {
@ -91,10 +101,10 @@ export function BandwidthProgress({label = '', bytes, maxBytes, ...props}) {
export function BandwidthProgressGroup({bandwidth, ...props}) {
// NIC speed to bytes.
const maxBytes = bandwidth['speed'] * 125_000;
const maxBytes = bandwidth['speed'] * 1000 * 1000 / 8;
const recv = <BandwidthProgress
bytes={bandwidth['bytes_recv']}
bytes={bandwidth['bytes_recv_ps']}
label={`${bandwidth['name']} In`}
maxBytes={maxBytes}
size='small'
@ -102,7 +112,7 @@ export function BandwidthProgressGroup({bandwidth, ...props}) {
/>;
const sent = <BandwidthProgress
bytes={bandwidth['bytes_sent']}
bytes={bandwidth['bytes_sent_ps']}
label={`${bandwidth['name']} Out`}
maxBytes={maxBytes}
size='small'
@ -122,7 +132,7 @@ export function BandwidthProgressGroup({bandwidth, ...props}) {
}
export function BandwidthProgressCombined({bandwidth, ...props}) {
const maxBytes = bandwidth['speed'] ? bandwidth['speed'] * 125_000 : 125_000_000;
const maxBytes = bandwidth['speed'] ? bandwidth['speed'] * 1000 * 1000 / 8 : 125_000_000;
const combined = bandwidth['bytes_recv'] + bandwidth['bytes_sent']
return <BandwidthProgress label={bandwidth['name']} bytes={combined} maxBytes={maxBytes} {...props}/>
}
@ -160,6 +170,15 @@ export function MemoryUsageProgress({percent, label}) {
return <Progress percent={percent} progress color={color} label={label} size={size}/>
}
function ProcessInfoRow({pid, command, percent_cpu, percent_mem}) {
const color = percent_cpu >= 80 ? 'orange' : null;
return <TableRow color={color}>
<TableCell className='column-ellipsis'>{command}</TableCell>
<TableCell textAlign='right'>{percent_cpu}</TableCell>
<TableCell textAlign='right'>{percent_mem}</TableCell>
<TableCell textAlign='right'>{pid}</TableCell>
</TableRow>
}
export function StatusPage() {
useTitle('Status');
@ -175,30 +194,32 @@ export function StatusPage() {
let temperature;
let high_temperature;
let critical_temperature;
let processesStats = null;
let minute_1;
let minute_5;
let minute_15;
let bandwidth;
let drives = [];
let disk_bandwidth = [];
let nicBandwidthStats;
let drivesStats = [];
let diskBandwidthStats = [];
let memoryPercent;
let memorySize;
if (status && status['cpu_info']) {
const {cpu_info, load, memory_stats} = status;
percent = cpu_info['percent'];
cores = cpu_info['cores'];
temperature = cpu_info['temperature'];
high_temperature = cpu_info['high_temperature'];
critical_temperature = cpu_info['critical_temperature'];
if (status && status['cpu_stats']) {
const {cpu_stats, load_stats, memory_stats, processes_stats} = status;
percent = cpu_stats['percent'];
cores = cpu_stats['cores'];
temperature = cpu_stats['temperature'];
high_temperature = cpu_stats['high_temperature'];
critical_temperature = cpu_stats['critical_temperature'];
processesStats = processes_stats;
minute_1 = load['minute_1'];
minute_5 = load['minute_5'];
minute_15 = load['minute_15'];
minute_1 = load_stats['minute_1'];
minute_5 = load_stats['minute_5'];
minute_15 = load_stats['minute_15'];
drives = status['drives'];
bandwidth = status['bandwidth'];
disk_bandwidth = status['disk_bandwidth'];
drivesStats = status['drives_stats'];
nicBandwidthStats = status['nic_bandwidth_stats'];
diskBandwidthStats = status['disk_bandwidth_stats'];
memoryPercent = Math.round(memory_stats['used'] / memory_stats['total'] * 100);
memorySize = humanFileSize(memory_stats['total'], 0);
@ -218,6 +239,10 @@ export function StatusPage() {
setActiveIndex(activeIndex === index ? -1 : index);
}
const noProcessesRow = <TableRow>
<TableCell colSpan={4}>No top processes</TableCell>
</TableRow>
return <SegmentGroup>
<Media at='mobile'>
<Segment>
@ -255,20 +280,45 @@ export function StatusPage() {
<Segment>
<SizedHeader>Drive Bandwidth</SizedHeader>
{disk_bandwidth && disk_bandwidth.length > 0 ? disk_bandwidth.map((disk) => <DiskBandwidth
key={disk['name']} {...disk}/>)
{!_.isEmpty(diskBandwidthStats) ?
Object.entries(diskBandwidthStats).map(([name, disk]) => <DiskBandwidth key={name} {...disk}/>)
: <ProgressPlaceholder/>}
</Segment>
<Segment>
<SizedHeader>Network Bandwidth</SizedHeader>
{bandwidth ? bandwidth.map(i => <BandwidthProgressGroup key={i['name']} bandwidth={i}/>)
{!_.isEmpty(nicBandwidthStats) ?
Object.entries(nicBandwidthStats).map(([name, stats]) => <BandwidthProgressGroup key={name}
bandwidth={stats}/>)
: <ProgressPlaceholder/>}
</Segment>
<Segment>
<SizedHeader>Top Processes</SizedHeader>
<Table unstackable striped className='table-ellipsis'>
<TableHeader>
<TableRow>
<TableHeaderCell width={10}>Command</TableHeaderCell>
<TableHeaderCell width={2} textAlign='right'>CPU %</TableHeaderCell>
<TableHeaderCell width={2} textAlign='right'>Mem %</TableHeaderCell>
<TableHeaderCell width={2} textAlign='right'>PID</TableHeaderCell>
</TableRow>
</TableHeader>
<TableBody>
{processesStats && processesStats.length === 0 ?
noProcessesRow :
processesStats && processesStats.length > 0 ?
processesStats.map(i => <ProcessInfoRow key={i.pid} {...i}/>)
: <TableRow><TableCell><ProgressPlaceholder/></TableCell></TableRow>
}
</TableBody>
</Table>
</Segment>
<Segment>
<SizedHeader>Drive Usage</SizedHeader>
{drives && drives.length > 0 ? drives.map((drive) => <DriveInfo key={drive['mount']} {...drive}/>)
{drivesStats && drivesStats.length > 0 ? drivesStats.map((drive) => <DriveInfo
key={drive['mount']} {...drive}/>)
: <ProgressPlaceholder/>}
</Segment>