Skip to content

Commit fc57b23

Browse files
committed
Added graphs for CPU and GPU temperatures
1 parent d4772ff commit fc57b23

File tree

7 files changed

+63
-6
lines changed

7 files changed

+63
-6
lines changed

frontend/src/App.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React from 'react'
22
import RamUtil from './sockets/RamUtil'
33
import CpuUtil from './sockets/CpuUtil'
4+
import CpuTemp from './sockets/CpuTemp'
5+
import GpuTemp from './sockets/GpuTemp'
46

57
import classes from './App.module.css'
68

@@ -9,6 +11,8 @@ const App: React.FC = () => {
911
<div className={classes.parent}>
1012
<RamUtil />
1113
<CpuUtil />
14+
<GpuTemp/>
15+
<CpuTemp/>
1216
</div>
1317
)
1418
}

frontend/src/graphs/AreaChartGraph.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { AreaChart, XAxis, YAxis, CartesianGrid, Tooltip, Area, Legend, Responsi
55
import Wrapper from '../shared/Wrapper';
66

77
// COMPONENT
8-
const AreaChartGraph: React.FC<AreaChartProps> = ({ data, dataLabel}) => {
8+
const AreaChartGraph: React.FC<AreaChartProps> = ({ data, dataLabel, dataX }) => {
99
return (
1010
<Wrapper>
1111
<ResponsiveContainer width="100%" height="100%">
@@ -17,11 +17,11 @@ const AreaChartGraph: React.FC<AreaChartProps> = ({ data, dataLabel}) => {
1717
</linearGradient>
1818
</defs>
1919
<XAxis stroke="#ccc" />
20-
<YAxis stroke="#ccc"/>
20+
<YAxis stroke="#ccc" />
2121
<Legend />
2222
<CartesianGrid strokeDasharray="2 2" stroke="rgba(204, 204, 204, 0.5)" />
2323
<Tooltip />
24-
<Area name={dataLabel} type="monotone" dataKey="x" stroke="#4CAF50" fillOpacity={1} fill="url(#colorUv)" />
24+
<Area name={dataLabel} type="monotone" dataKey={dataX} stroke="#4CAF50" fillOpacity={1} fill="url(#colorUv)" />
2525
</AreaChart>
2626
</ResponsiveContainer>
2727
</Wrapper>

frontend/src/hooks/useSocket.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import socketIOClient from 'socket.io-client'
33

44
const backendServer: string = import.meta.env.VITE_BACKEND_SERVER as string
55

6-
export const useSocket = <T>(eventName: string, socketUrl: string = backendServer) => {
6+
export const useSocket = <T>(eventName: string, logData: boolean = false, socketUrl: string = backendServer) => {
77
const [data, setData] = useState<T[]>([]);
88
const [isLoading, setIsLoading] = useState<boolean>(true);
99

@@ -13,6 +13,7 @@ export const useSocket = <T>(eventName: string, socketUrl: string = backendServe
1313
// connect to a socket
1414
socket.on(eventName, (data: T[]) => {
1515
setData(data);
16+
if (logData) console.log(data)
1617
setIsLoading(false);
1718
});
1819

frontend/src/sockets/CpuTemp.tsx

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react'
2+
import AreaChartGraph from '../graphs/AreaChartGraph'
3+
4+
import Spinner from '../shared/Spinner'
5+
import { useSocket } from '../hooks/useSocket'
6+
import { isTemperature } from '../types/types'
7+
8+
import classes from './shared.module.css'
9+
10+
const CpuTemp: React.FC = () => {
11+
12+
const { data, isLoading } = useSocket<isTemperature>("cpuTemp")
13+
14+
return (
15+
<div className={classes.parent}>
16+
<h1>CPU Temperature</h1>
17+
{isLoading && <Spinner />}
18+
{!isLoading && <AreaChartGraph data={data} dataLabel='CPU Temperature' dataX='temp' />}
19+
</div>
20+
)
21+
}
22+
23+
export default CpuTemp

frontend/src/sockets/GpuTemp.tsx

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react'
2+
import AreaChartGraph from '../graphs/AreaChartGraph'
3+
4+
import Spinner from '../shared/Spinner'
5+
import { useSocket } from '../hooks/useSocket'
6+
import { isTemperature } from '../types/types'
7+
8+
import classes from './shared.module.css'
9+
10+
const GpuTemp: React.FC = () => {
11+
12+
const { data, isLoading } = useSocket<isTemperature>("gpuTemp")
13+
14+
return (
15+
<div className={classes.parent}>
16+
<h1>GPU Temperature</h1>
17+
{isLoading && <Spinner />}
18+
{!isLoading && <AreaChartGraph data={data} dataLabel='GPU Temperature' dataX='temp' />}
19+
</div>
20+
)
21+
}
22+
23+
export default GpuTemp

frontend/src/sockets/RamUtil.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const RamUtil: React.FC = () => {
1616
<div className={classes.parent}>
1717
<h1>Ram Utilization</h1>
1818
{isLoading && <Spinner />}
19-
{!isLoading && <AreaChartGraph data={data} dataLabel='RAM utilisation' />}
19+
{!isLoading && <AreaChartGraph data={data} dataLabel='RAM utilisation' dataX='x'/>}
2020
</div>
2121
)
2222
}

frontend/src/types/types.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export interface AreaChartProps {
2-
data: { name: string, x: number }[];
2+
data: { name: string, x: number | string }[];
33
dataLabel : string
4+
dataX: string
45
}
56

67
export interface BarChartProps {
@@ -18,4 +19,9 @@ export interface isRamUtil {
1819
export interface isCpuUtil {
1920
core: number;
2021
load: number;
22+
}
23+
24+
export interface isTemperature {
25+
name: string;
26+
x: number;
2127
}

0 commit comments

Comments
 (0)