import {Accordion, Header, Progress, Segment, Statistic, Table} from "../Theme"; import React, {useContext} from "react"; import { Duration, humanBandwidth, humanFileSize, InfoHeader, LoadStatistic, secondsToHMS, secondsToHumanElapsed, 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, 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}) { let color; if (percent >= 90) { color = 'red'; } else if (percent >= 80) { color = 'orange'; } return } function DiskBandwidthProgress({bytes_ps, total, label, ...props}) { // Calculate percent so colors can be shown. let percent = (bytes_ps / total) * 100; percent = percent || 0; let color = null; if (percent >= 90) { color = 'red'; } else if (percent >= 80) { color = 'orange'; } else if (percent >= 50) { color = 'yellow'; } label = `${label} ${humanBandwidth(bytes_ps)}`; return ; } function DiskBandwidth({name, bytes_read_ps, bytes_write_ps, max_read_ps, max_write_ps}) { const read = ; const write = ; return {read} {write} } function CPUTemperatureStatistic({temperature, high_temperature, critical_temperature, ...props}) { if (!temperature) { return } if ((critical_temperature && temperature >= critical_temperature) || (!critical_temperature && temperature >= 75)) { props['color'] = 'red'; } else if ((high_temperature && temperature >= high_temperature) || (!high_temperature && temperature >= 55)) { props['color'] = 'orange'; } return } function IOWaitStatistic({percent_iowait, ...props}) { if (percent_iowait === null || percent_iowait === undefined) { return } if (percent_iowait >= 30) { props['color'] = 'red'; } else if (percent_iowait >= 10) { props['color'] = 'orange'; } return } function formatUptime(seconds) { if (!seconds || seconds < 0) return '?'; const days = Math.floor(seconds / 86400); const hours = Math.floor((seconds % 86400) / 3600); const minutes = Math.floor((seconds % 3600) / 60); if (days > 0) { return `${days}d ${hours}h`; } else if (hours > 0) { return `${hours}h ${minutes}m`; } else { return `${minutes}m`; } } function UptimeStatistic({uptime_seconds, ...props}) { const value = formatUptime(uptime_seconds); return } export function BandwidthProgress({label = '', bytes, maxBytes, ...props}) { // Gigabit by default. maxBytes = maxBytes || 125_000_000; label = `${label} (${humanBandwidth(bytes)})`; const percent = (bytes / maxBytes) * 100; if (percent > 70) { props['color'] = 'yellow'; } else if (percent > 90) { props['color'] = 'red'; } const disabled = percent === 0; return } export function BandwidthProgressGroup({bandwidth, ...props}) { // NIC speed to bytes. const maxBytes = bandwidth['speed'] * 1000 * 1000 / 8; const recv = ; const sent = ; return {recv} {sent} } export function BandwidthProgressCombined({bandwidth, ...props}) { const maxBytes = bandwidth['speed'] ? bandwidth['speed'] * 1000 * 1000 / 8 : 125_000_000; const combined = bandwidth['bytes_recv_ps'] + bandwidth['bytes_sent_ps']; return } export function CPUUsageProgress({percent, label}) { if (percent === null) { return } let color = 'black'; if (percent >= 90) { color = 'red'; } else if (percent >= 70) { color = 'brown'; } else if (percent >= 50) { color = 'orange'; } return } export function MemoryUsageProgress({percent, label}) { if (percent === null) { return } let color = 'black'; let size = 'small'; if (percent >= 90) { color = 'red'; size = 'large'; } else if (percent >= 70) { color = 'orange'; size = 'large'; } return } function ProcessInfoRow({pid, command, percent_cpu, percent_mem}) { const color = percent_cpu >= 80 ? 'orange' : null; return {command} {percent_cpu} {percent_mem} {pid} } export function StatusPage() { useTitle('Status'); const [activeIndex, setActiveIndex] = React.useState(null); const {status} = useContext(StatusContext); const {settings} = useContext(SettingsContext); const {s} = useContext(ThemeContext); let percent; let cores; let temperature; let high_temperature; let critical_temperature; let processesStats = null; let minute_1; let minute_5; let minute_15; let nicBandwidthStats; let drivesStats = []; let diskBandwidthStats = []; let memoryPercent; let memorySize; let percent_iowait; let uptime_seconds; if (status && status['cpu_stats']) { const {cpu_stats, load_stats, memory_stats, processes_stats, iostat_stats, uptime_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_stats['minute_1']; minute_5 = load_stats['minute_5']; minute_15 = load_stats['minute_15']; 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); // Extract IO wait from iostat stats if (iostat_stats) { percent_iowait = iostat_stats['percent_iowait']; } // Extract uptime from uptime stats if (uptime_stats) { uptime_seconds = uptime_stats['uptime_seconds']; } } const SizedHeader = ({children, sizeMobile = 'h1', sizeTablet = 'h2'}) => { return {children} {children} } const cpuProgress = ; const memoryUsageProgress = ; const handleAccordionClick = (e, {index}) => { setActiveIndex(activeIndex === index ? -1 : index); } const noProcessesRow = No top processes return {cpuProgress} {memoryUsageProgress} {cpuProgress} {memoryUsageProgress} {!_.isEmpty(diskBandwidthStats) ? Object.entries(diskBandwidthStats).map(([name, disk]) => ) : } Network Bandwidth {!_.isEmpty(nicBandwidthStats) ? Object.entries(nicBandwidthStats).map(([name, stats]) => ) : } Top Processes Command CPU % Mem % PID {processesStats && processesStats.length === 0 ? noProcessesRow : processesStats && processesStats.length > 0 ? processesStats.map(i => ) : } Drive Usage {drivesStats && drivesStats.length > 0 ? drivesStats.map((drive) => ) : } Developer Status Details {JSON.stringify(status, undefined, 1)} Settings Details {JSON.stringify(settings, undefined, 1)} }
{JSON.stringify(status, undefined, 1)}
{JSON.stringify(settings, undefined, 1)}