1
1
import os from 'os'
2
2
import si from 'systeminformation'
3
+ import { getGpuTemperature , getCpuTemperature } from 'raspberrypi-sys-info' ;
3
4
4
- import { isCpuUtil , isRamUtil , isSwapUtil , isError } from '../types/types'
5
+ import { isCpuUtil , isRamUtil , isError , isTemp } from '../types/types'
5
6
6
7
let limit : number = 10
7
8
8
9
let idx : number = 0
9
10
10
11
let RAM : isRamUtil [ ] = [ ]
11
- let SWAP : isSwapUtil [ ] = [ ]
12
- let CPU : isCpuUtil [ ] = [ ]
12
+ let SWAP : isRamUtil [ ] = [ ]
13
+ let GPU_TEMP : isTemp [ ] = [ ]
14
+ let CPU_TEMP : isTemp [ ] = [ ]
13
15
14
16
// CALCULATING RAM UTILISATION
15
17
export const calculateRamUtil = ( ) : isRamUtil [ ] => {
@@ -24,14 +26,8 @@ export const calculateRamUtil = (): isRamUtil[] => {
24
26
// convert to MB
25
27
ramUtil = + ( ramUtil / ( 1024 * 1024 ) ) . toFixed ( 2 )
26
28
27
- if ( RAM . length >= limit ) {
28
-
29
- RAM . shift ( )
30
- RAM . push ( { name : `${ idx } sec` , x : ramUtil } )
31
-
32
- } else {
33
- RAM . push ( { name : `${ idx } sec` , x : ramUtil } )
34
- }
29
+ if ( RAM . length >= limit ) RAM . shift ( )
30
+ RAM . push ( { name : `${ idx } sec` , x : ramUtil } )
35
31
36
32
return RAM
37
33
}
@@ -47,14 +43,8 @@ export const calculateSwapUtil = async () => {
47
43
48
44
let freeSwap = swapData . swapfree ;
49
45
50
- if ( SWAP . length >= limit ) {
51
-
52
- SWAP . shift ( )
53
- SWAP . push ( { name : `${ idx } sec` , x : freeSwap } )
54
-
55
- } else {
56
- SWAP . push ( { name : `${ idx } sec` , x : freeSwap } )
57
- }
46
+ if ( SWAP . length >= limit ) SWAP . shift ( )
47
+ SWAP . push ( { name : `${ idx } sec` , x : freeSwap } )
58
48
59
49
return SWAP
60
50
@@ -86,4 +76,48 @@ export const calculateCpuUtil = async (): Promise<isCpuUtil[] | isError> => {
86
76
return { message : error }
87
77
}
88
78
89
- }
79
+ }
80
+
81
+ // CALCULATE GPU TEMPERATURE
82
+ export const getGpuTemp = async ( ) => {
83
+
84
+ idx += 1
85
+
86
+ try {
87
+
88
+ const gpuTemp = await getGpuTemperature ( ) ;
89
+
90
+ if ( GPU_TEMP . length >= limit ) GPU_TEMP . shift ( )
91
+ GPU_TEMP . push ( { name : `${ idx } sec` , temp : + gpuTemp } )
92
+
93
+ return GPU_TEMP
94
+
95
+ } catch ( error : any ) {
96
+
97
+ return { message : error }
98
+
99
+ }
100
+
101
+ }
102
+
103
+ // CALCULATE CPU TEMPERATURE
104
+ export const getCpuTemp = async ( ) => {
105
+
106
+ idx += 1
107
+
108
+ try {
109
+
110
+ const cpuTemp = await getCpuTemperature ( ) ;
111
+
112
+ if ( CPU_TEMP . length >= limit ) CPU_TEMP . shift ( )
113
+ CPU_TEMP . push ( { name : `${ idx } sec` , temp : + cpuTemp } )
114
+
115
+ return CPU_TEMP
116
+
117
+ } catch ( error : any ) {
118
+
119
+ return { message : error }
120
+
121
+ }
122
+
123
+ }
0 commit comments