Skip to content

Commit db2d45c

Browse files
committed
Fan speed, autoreload
1 parent 036bdca commit db2d45c

File tree

4 files changed

+82
-18
lines changed

4 files changed

+82
-18
lines changed

apps/monitor/src/plugins/system-metrics.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,25 @@ const getFrequencyPerc = () => {
4848
}
4949
};
5050

51+
/**
52+
* Get current fan speed.
53+
*
54+
* @returns {number} Fan speed in RPM.
55+
*/
56+
const getFanSpeed = () => {
57+
try {
58+
const speed = parseInt(
59+
execSync('cat /sys/devices/platform/cooling_fan/hwmon/*/fan1_input').toString(),
60+
10,
61+
);
62+
63+
return speed || 0;
64+
} catch (e) {
65+
log.error(e);
66+
return 0;
67+
}
68+
};
69+
5170
/**
5271
* Log metrics for system stats.
5372
*
@@ -69,6 +88,8 @@ module.exports = async (args = {}) => {
6988

7089
const freqPerc = getFrequencyPerc();
7190

91+
const fanSpeed = getFanSpeed();
92+
7293
// Metrics with 'Perc' in the name are treated as a 0-100% range in the dashboard
7394
updateMetrics({
7495
cpu: cpuMinute,
@@ -78,6 +99,7 @@ module.exports = async (args = {}) => {
7899
diskPerc,
79100
tempRaw,
80101
freqPerc,
102+
fanSpeed,
81103
});
82104
} catch (e) {
83105
log.error(e);

dashboard2/src/components/AppArea.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { Fabricate } from 'fabricate.js';
1+
import { Fabricate, FabricateComponent } from 'fabricate.js';
22
import { AppState } from '../types';
33
import StatRow from './StatRow';
44
import AppLoader from './AppLoader';
55
import AppCard from './AppCard';
66
import DeviceMetrics from './DeviceMetrics';
7+
import { fetchMetricNames } from '../services/conduitService';
78

89
declare const fabricate: Fabricate<AppState>;
910

@@ -20,6 +21,38 @@ const NoDeviceLabel = () => fabricate('Text')
2021
}))
2122
.setText('No device selected');
2223

24+
/**
25+
* RefreshProgressBar component.
26+
*
27+
* @returns {FabricateComponent} RefreshProgressBar component.
28+
*/
29+
const RefreshProgressBar = () => {
30+
let handle: NodeJS.Timer;
31+
let progress = 100;
32+
33+
return fabricate('div')
34+
.setStyles(({ palette }) => ({
35+
width: '100%',
36+
height: '5px',
37+
backgroundColor: palette.secondary,
38+
transition: '0.5s',
39+
}))
40+
.onCreate((el, state) => {
41+
handle = setInterval(() => {
42+
el.setStyles({ width: `${progress}%` });
43+
44+
// 30s
45+
progress = Math.max(0, progress - 1.67);
46+
if (progress === 0) {
47+
progress = 100;
48+
49+
fetchMetricNames(state);
50+
}
51+
}, 1000);
52+
})
53+
.onDestroy(() => clearInterval(handle));
54+
};
55+
2356
/**
2457
* AppArea component.
2558
*
@@ -63,6 +96,7 @@ const AppArea = () => {
6396
el.setChildren([
6497
StatRow({ device: selectedDevice }),
6598
fabricate.conditional((s) => !areAppsLoaded(s), AppLoader),
99+
fabricate.conditional(areAppsLoaded, RefreshProgressBar),
66100
fabricate.conditional(areAppsLoaded, DeviceMetrics),
67101
fabricate.conditional(areAppsLoaded, AppCardList),
68102
]);

dashboard2/src/components/DeviceMetrics.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
} from '../types';
55
import Theme from '../theme';
66
import { BUCKET_SIZE } from '../constants';
7-
import { fetchMetric, sendConduitPacket } from '../services/conduitService';
7+
import { fetchMetric, fetchMetricNames } from '../services/conduitService';
88

99
declare const fabricate: Fabricate<AppState>;
1010

@@ -21,6 +21,7 @@ const METRIC_NAME_MAP: Record<string, string> = {
2121
discPerc: 'Disk (%)',
2222
tempRaw: 'Temperature',
2323
freqPerc: 'CPU Frequency (%)',
24+
fanSpeed: 'Fan Speed (RPM)',
2425
};
2526

2627
/**
@@ -175,7 +176,6 @@ const MetricContainer = ({ name } : { name: string }) => fabricate('Column')
175176
border: `solid 2px ${palette.grey6}`,
176177
}))
177178
.setNarrowStyles({
178-
width: '100%',
179179
margin: '10px 0px',
180180
})
181181
.setChildren([
@@ -204,11 +204,7 @@ const DeviceMetrics = () => fabricate('Row')
204204
})
205205
.onCreate(async (el, state) => {
206206
// Get the metrics available, each graph loads its own
207-
fabricate.update({ metricNames: [] });
208-
const {
209-
message: metricNames,
210-
} = await sendConduitPacket(state, { to: 'monitor', topic: 'getMetricNames' });
211-
fabricate.update({ metricNames });
207+
fetchMetricNames(state);
212208
})
213209
.onUpdate(async (el, state, keys) => {
214210
const { selectedDevice, metricNames } = state;

dashboard2/src/services/conduitService.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,16 @@ export const fetchDeviceApps = async (state: AppState, device: Device) => {
138138
*/
139139
export const fetchMetric = async (state: AppState, name: string) => {
140140
const dataKey = fabricate.buildKey('metricData', name);
141-
fabricate.update(
142-
dataKey,
143-
{
144-
buckets: [],
145-
minTime: 0,
146-
maxTime: 0,
147-
minValue: 0,
148-
maxValue: 0,
149-
},
150-
);
141+
// fabricate.update(
142+
// dataKey,
143+
// {
144+
// buckets: [],
145+
// minTime: 0,
146+
// maxTime: 0,
147+
// minValue: 0,
148+
// maxValue: 0,
149+
// },
150+
// );
151151

152152
const res = await sendConduitPacket(
153153
state,
@@ -214,3 +214,15 @@ export const fetchMetric = async (state: AppState, name: string) => {
214214
},
215215
);
216216
};
217+
218+
/**
219+
* Fetch metric names, triggering update of graphs if they are shown.
220+
*
221+
* @param {AppState} state - App state.
222+
*/
223+
export const fetchMetricNames = async (state: AppState) => {
224+
const {
225+
message: metricNames,
226+
} = await sendConduitPacket(state, { to: 'monitor', topic: 'getMetricNames' });
227+
fabricate.update({ metricNames });
228+
};

0 commit comments

Comments
 (0)