Add host temperature telemetry and history
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { db } from '../db/index.js';
|
||||
import type { CapacityHistory, CapacityQuery, CapacityRange } from '../../capacity.js';
|
||||
import { readTemperatureHistory } from './temperatures.js';
|
||||
|
||||
const windows: Record<CapacityRange, { duration: number; bucketMs: number }> = {
|
||||
'1h': { duration: 3_600_000, bucketMs: 60_000 },
|
||||
@@ -15,10 +16,14 @@ export function readCapacityHistory(query: CapacityQuery, now = Date.now()): Cap
|
||||
const count = duration / bucketMs;
|
||||
const hosts = handle
|
||||
.prepare(
|
||||
`SELECT id,created_at FROM ec_hosts
|
||||
`SELECT id,name,created_at FROM ec_hosts
|
||||
WHERE deleted_at IS NULL ${query.hostId ? 'AND id=?' : ''} ORDER BY id`
|
||||
)
|
||||
.all(...(query.hostId ? [query.hostId] : [])) as { id: string; created_at: string }[];
|
||||
.all(...(query.hostId ? [query.hostId] : [])) as {
|
||||
id: string;
|
||||
name: string;
|
||||
created_at: string;
|
||||
}[];
|
||||
// The primary key bounds each host scan to the selected interval. Aggregate
|
||||
// before crossing the worker boundary; do not return raw heartbeat rows.
|
||||
const samples = handle.prepare(`SELECT
|
||||
@@ -69,5 +74,12 @@ export function readCapacityHistory(query: CapacityQuery, now = Date.now()): Cap
|
||||
point.memoryBytesAvailable = null;
|
||||
}
|
||||
}
|
||||
return { range: query.range, startAt, endAt: now, bucketMs, points };
|
||||
return {
|
||||
range: query.range,
|
||||
startAt,
|
||||
endAt: now,
|
||||
bucketMs,
|
||||
points,
|
||||
temperatures: readTemperatureHistory(query, hosts, startAt, now, bucketMs)
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user