1
2
3
4
5
6
7
8
9
10
11
const levels = {operational: 0, degraded: 1, outage: 2};
export function overallStatus(components) {
if (!components.length) return "unknown";
if (components.some(component => !(component.status in levels))) throw new Error("Invalid status");
return components.reduce((worst, component) => levels[component.status] > levels[worst] ? component.status : worst, "operational");
}
export function uptime(successful, total) {
if (!Number.isInteger(total) || !Number.isInteger(successful) || total < 0 || successful < 0 || successful > total) throw new Error("Invalid counts");
return total === 0 ? null : Number((successful / total * 100).toFixed(2));
}