import React, { useState, useEffect } from 'react'; import { HARDWARE_STATS, fetchData, FETCH_INTERVAL } from './utils/apis'; import Chart from './components/chart'; export default function HardwareInfo() { const [hardwareStatus, setHardwareStatus] = useState({ cpu: 0, memory: 0, disk: 0, message: '', }); const getHardwareStatus = async () => { try { const result = await fetchData(HARDWARE_STATS); setHardwareStatus({ ...result }); } catch (error) { setHardwareStatus({ ...hardwareStatus, message: error.message }); } }; useEffect(() => { let getStatusIntervalId = null; getHardwareStatus(); getStatusIntervalId = setInterval(getHardwareStatus, FETCH_INTERVAL); // runs every 1 min. // returned function will be called on component unmount return () => { clearInterval(getStatusIntervalId); } }, []); if (!hardwareStatus.cpu) { return null; } return (

Hardware Info

CPU

Memory

Disk

cpu:[], disk: [], memory: []; value = %age.

the times should be the same for each, though milliseconds differ

{JSON.stringify(hardwareStatus)}
); }