Skip to content

Commit 86691c6

Browse files
committed
Text metrics
1 parent 4aef9d3 commit 86691c6

File tree

6 files changed

+40
-16
lines changed

6 files changed

+40
-16
lines changed

dashboard/src/components/DeviceCard.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,9 @@ const DeviceCard = ({ device }: { device: Device }) => {
402402
try {
403403
await fetch(`http://${ip}:5959/ping`);
404404
fabricate.update(stateKey, true);
405-
} catch (err) { /* It isn't available */ }
405+
} catch (err) {
406+
/* It isn't available */
407+
}
406408
};
407409

408410
return DeviceCardContainer()

dashboard/src/components/MetricGraph.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,20 @@ const GraphView = () => fabricate('Row')
8484
width: '100%',
8585
height: `${GRAPH_HEIGHT}px`,
8686
}))
87-
.onUpdate((el, { metricHistory, monitorData: { minValue, maxValue } }) => {
87+
.onUpdate((el, { metricHistory, monitorData: { type, minValue, maxValue } }) => {
8888
if (!metricHistory.length) return;
8989

90+
// Show no point for non-number data
91+
if (type !== 'number') return;
92+
9093
// Average into buckets
9194
const copy = [...metricHistory];
9295
const buckets = [];
9396
while (copy.length) {
9497
const points = copy.splice(0, BUCKET_SIZE);
9598
const avgIndex = Math.floor(points.length / 2);
9699
buckets.push({
100+
// @ts-expect-error handled with 'type'
97101
value: points.reduce((acc, [, value]) => acc + value, 0) / points.length,
98102
timestamp: points[avgIndex][0],
99103
dateTime: new Date(points[avgIndex][0]).toISOString(),

dashboard/src/components/controls/MonitorControls.ts

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,33 @@ const fetchMetric = async (state: AppState, metric: string, setProp: SetPropFunc
2929
);
3030
const { message: newHistory } = res;
3131

32-
// Aggregate values
33-
const minValue = metric.includes('Perc')
34-
? 0
35-
: newHistory.reduce(
36-
(acc: number, [, value]: MetricPoint) => (value < acc ? value : acc),
37-
9999999,
38-
);
39-
const maxValue = metric.includes('Perc')
40-
? 100
41-
: newHistory.reduce(
42-
(acc: number, [, value]: MetricPoint) => (value > acc ? value : acc),
43-
0,
44-
);
32+
const type: AppState['monitorData']['type'] = Array.isArray(newHistory[0][1]) ? 'array' : 'number';
33+
setProp('type', type);
34+
35+
let minValue;
36+
let maxValue;
37+
38+
if (type === 'number') {
39+
// Aggregate values
40+
minValue = metric.includes('Perc')
41+
? 0
42+
: newHistory.reduce(
43+
// @ts-expect-error handled with 'type'
44+
(acc: number, [, value]: MetricPoint) => (value < acc ? value : acc),
45+
9999999,
46+
);
47+
maxValue = metric.includes('Perc')
48+
? 100
49+
: newHistory.reduce(
50+
// @ts-expect-error handled with 'type'
51+
(acc: number, [, value]: MetricPoint) => (value > acc ? value : acc),
52+
0,
53+
);
54+
} else if (type === 'array') {
55+
// Just show the data in the maxValue label
56+
[, maxValue] = newHistory.slice(-1);
57+
}
58+
4559
const minTime = shortDateTime(newHistory[0][0]);
4660
const maxTime = shortDateTime(newHistory[newHistory.length - 1][0]);
4761

dashboard/src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export const INITIAL_STATE: AppState = {
5858
maxValue: 99999,
5959
minTime: 0,
6060
maxTime: 99999,
61+
type: 'number',
6162
},
6263
};
6364

dashboard/src/pages/FleetPage.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ const FleetPage = () => {
105105
if (!fleet.length) return;
106106

107107
updateLayout(el, state);
108+
109+
// FIXME: Each DeviceCard should load its own apps after IP tests are done
108110
fetchApps(state);
109111
}, ['fleet']);
110112
};

dashboard/src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export type DataPoint = {
3737
};
3838

3939
/** Raw metric point */
40-
export type MetricPoint = [number, number];
40+
export type MetricPoint = [number, number | string[]];
4141

4242
/** monitor plugin configuration */
4343
export type MonitorPlugin = {
@@ -102,6 +102,7 @@ export type AppState = {
102102
maxValue: number;
103103
minTime: number;
104104
maxTime: number;
105+
type: 'array' | 'number';
105106
};
106107
};
107108

0 commit comments

Comments
 (0)