fix: missing machine performance data on the dashboard machine overview page

This commit is contained in:
Sérgio Salgado 2022-02-10 16:05:30 +00:00
parent 4015e23d34
commit d794bca673
2 changed files with 31 additions and 23 deletions

View file

@ -110,11 +110,17 @@ function getMachine (machineId, config) {
else return toMachineObject(r)
})
return Promise.all([queryMachine, dbm.machineEvents(), config])
.then(([machine, events, config]) => {
return Promise.all([queryMachine, dbm.machineEvents(), config, getNetworkHeartbeatByDevice(machineId), getNetworkPerformanceByDevice(machineId)])
.then(([machine, events, config, heartbeat, performance]) => {
const pings = checkPings([machine])
const mergedMachine = {
...machine,
responseTime: _.get('responseTime', heartbeat),
packetLoss: _.get('packetLoss', heartbeat),
downloadSpeed: _.get('downloadSpeed', performance),
}
return addName(pings, events, config)(machine)
return addName(pings, events, config)(mergedMachine)
})
}
@ -234,6 +240,20 @@ function getNetworkHeartbeat () {
.then(res => _.map(_.mapKeys(_.camelCase))(res))
}
function getNetworkPerformanceByDevice (deviceId) {
const sql = `SELECT device_id, download_speed FROM machine_network_performance WHERE device_id = $1`
return db.manyOrNone(sql, [deviceId])
.then(res => _.mapKeys(_.camelCase, _.find(it => it.device_id === deviceId, res)))
}
function getNetworkHeartbeatByDevice (deviceId) {
const sql = `SELECT AVG(average_response_time) AS response_time, AVG(average_packet_loss) AS packet_loss, device_id
FROM machine_network_heartbeat WHERE device_id = $1
GROUP BY device_id`
return db.manyOrNone(sql, [deviceId])
.then(res => _.mapKeys(_.camelCase, _.find(it => it.device_id === deviceId, res)))
}
module.exports = {
getMachineName,
getMachines,