import {Accordion, Header, Progress, Segment, Statistic, StatisticGroup} 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 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, maximum_read_ps, maximum_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 } 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'; } const disabled = percent === 0; return } export function BandwidthProgressGroup({bandwidth, ...props}) { // NIC speed to bytes. const maxBytes = bandwidth['speed'] * 125_000; const recv = ; const sent = ; return {recv} {sent} } 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 } 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 } 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 minute_1; let minute_5; let minute_15; let bandwidth; let drives = []; let disk_bandwidth = []; 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']; minute_1 = load['minute_1']; minute_5 = load['minute_5']; minute_15 = load['minute_15']; drives = status['drives']; bandwidth = status['bandwidth']; disk_bandwidth = status['disk_bandwidth']; memoryPercent = Math.round(memory_stats['used'] / memory_stats['total'] * 100); memorySize = humanFileSize(memory_stats['total'], 0); } const SizedHeader = ({children, sizeMobile = 'h1', sizeTablet = 'h2'}) => { return {children} {children} } const cpuProgress = ; const memoryUsageProgress = ; const handleAccordionClick = (e, {index}) => { setActiveIndex(activeIndex === index ? -1 : index); } return {cpuProgress} {memoryUsageProgress} {cpuProgress} {memoryUsageProgress} Drive Bandwidth {disk_bandwidth && disk_bandwidth.length > 0 ? disk_bandwidth.map((disk) => ) : } Network Bandwidth {bandwidth ? bandwidth.map(i => ) : } Drive Usage {drives && drives.length > 0 ? drives.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)}