(s)
| 103 | } |
| 104 | |
| 105 | function metrics(s){ |
| 106 | const online = !!(s.online4 || s.online6); |
| 107 | const memPct = s.memory_total ? s.memory_used / s.memory_total * 100 : 0; |
| 108 | const hddPct = s.hdd_total ? s.hdd_used / s.hdd_total * 100 : 0; |
| 109 | const monthIn = Math.max(0, num(s.network_in) - num(s.last_network_in)); |
| 110 | const monthOut = Math.max(0, num(s.network_out) - num(s.last_network_out)); |
| 111 | const traffic = monthIn + monthOut; |
| 112 | const losses = lossValues(s); |
| 113 | const loss = Math.max(...losses); |
| 114 | const lossBadCount = losses.filter(p => p >= 40).length; |
| 115 | const lossWarnCount = losses.filter(p => p >= 30).length; |
| 116 | const blocked = online && losses.every(p => p >= 100); |
| 117 | const resourceCritical = online && (num(s.cpu) >= 90 || memPct >= 90 || hddPct >= 90); |
| 118 | const resourceWarning = online && (num(s.cpu) >= 75 || memPct >= 80 || hddPct >= 85); |
| 119 | const trafficWarning = online && traffic >= 1000 * 1000 * 1000 * 1000; |
| 120 | const lossCritical = online && loss >= 40; |
| 121 | const lossWarning = online && !lossCritical && loss >= 30; |
| 122 | const critical = online && (resourceCritical || blocked || lossCritical); |
| 123 | const warning = online && (resourceWarning || lossWarning); |
| 124 | const rowLevel = !online || critical ? 'critical' : (resourceWarning || lossWarning ? 'warning' : ''); |
| 125 | return { online, memPct, hddPct, monthIn, monthOut, traffic, loss, lossBadCount, lossWarnCount, blocked, resourceCritical, resourceWarning, trafficWarning, lossCritical, lossWarning, critical, warning, alert: critical || warning, highlight: !!rowLevel, rowLevel }; |
| 126 | } |
| 127 | |
| 128 | async function fetchData(){ |
| 129 | try{ |
no test coverage detected