Skip to main content
Commitdffc3183f84b
11 lines · 660 BBlameRaw
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));
}