add machine uptime
This commit is contained in:
parent
d4035de4d6
commit
ed8a51af46
3 changed files with 215 additions and 137 deletions
|
|
@ -5,7 +5,28 @@ const settingsLoader = require('../settings-loader')
|
||||||
|
|
||||||
const db = require('../db')
|
const db = require('../db')
|
||||||
|
|
||||||
const CONSIDERED_UP = 30000
|
const CONSIDERED_UP_SECS = 30
|
||||||
|
|
||||||
|
function machinesLastPing () {
|
||||||
|
const sql = `select name, min(extract(epoch from (now() - machine_events.created))) as age
|
||||||
|
from machine_events, devices
|
||||||
|
where machine_events.device_id = devices.device_id
|
||||||
|
group by name`
|
||||||
|
|
||||||
|
return db.any(sql)
|
||||||
|
.then(r => {
|
||||||
|
const downRows = r.filter(row => row.age > CONSIDERED_UP_SECS)
|
||||||
|
if (downRows.length === 0) return 'All machines are up'
|
||||||
|
|
||||||
|
if (downRows.length === 1) {
|
||||||
|
const row = downRows[0]
|
||||||
|
const age = moment.duration(row.age, 'seconds')
|
||||||
|
return `${row.name} down for ${age.humanize()}`
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'Multiple machines down'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function status () {
|
function status () {
|
||||||
const sql = `select extract(epoch from (now() - created)) as age
|
const sql = `select extract(epoch from (now() - created)) as age
|
||||||
|
|
@ -14,12 +35,12 @@ function status () {
|
||||||
order by created desc
|
order by created desc
|
||||||
limit 1`
|
limit 1`
|
||||||
|
|
||||||
return db.oneOrNone(sql, ['ping'])
|
return Promise.all([db.oneOrNone(sql, ['ping']), machinesLastPing()])
|
||||||
.then(row => {
|
.then(([statusRow, machineStatus]) => {
|
||||||
if (!row) return {up: false, lastPing: null}
|
if (!statusRow) return {up: false, lastPing: null, machineStatus}
|
||||||
|
|
||||||
const age = moment.duration(row.age, 'seconds')
|
const age = moment.duration(statusRow.age, 'seconds')
|
||||||
const up = age.asMilliseconds() < CONSIDERED_UP
|
const up = statusRow.age < CONSIDERED_UP_SECS
|
||||||
const lastPing = age.humanize()
|
const lastPing = age.humanize()
|
||||||
|
|
||||||
return settingsLoader.loadLatest()
|
return settingsLoader.loadLatest()
|
||||||
|
|
@ -31,7 +52,7 @@ function status () {
|
||||||
bid: parseFloat(ratesRec.rates.bid),
|
bid: parseFloat(ratesRec.rates.bid),
|
||||||
ask: parseFloat(ratesRec.rates.ask)
|
ask: parseFloat(ratesRec.rates.ask)
|
||||||
}]
|
}]
|
||||||
return {up, lastPing, rates}
|
return {up, lastPing, rates, machineStatus}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
308
public/elm.js
308
public/elm.js
File diff suppressed because one or more lines are too long
|
|
@ -154,6 +154,7 @@ p {
|
||||||
|
|
||||||
.lamassuAdminTxTable .lamassuAdminNumberColumn {
|
.lamassuAdminTxTable .lamassuAdminNumberColumn {
|
||||||
text-align: right;
|
text-align: right;
|
||||||
|
width: 10em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.lamassuAdminTxTable .lamassuAdminDirectionColumn {
|
.lamassuAdminTxTable .lamassuAdminDirectionColumn {
|
||||||
|
|
@ -180,6 +181,14 @@ p {
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.lamassuAdminTxTable tbody .lamassuAdminTxDate {
|
||||||
|
width: 10em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lamassuAdminTxTable tbody .lamassuAdminTxAddress {
|
||||||
|
width: 25em;
|
||||||
|
}
|
||||||
|
|
||||||
.lamassuAdminTxTable thead {
|
.lamassuAdminTxTable thead {
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue