fix(netdata-dashboard): add missing utility functions to API
Added utility functions that views depend on: - formatKB() - Format kilobytes with automatic unit conversion (KB/MB/GB/TB) - getStatusClass() - Return CSS class based on percentage thresholds (good: <50%, info: 50-74%, warning: 75-89%, critical: >=90%) - getTempClass() - Return CSS class based on temperature in Celsius (good: <60°C, info: 60-69°C, warning: 70-79°C, critical: >=80°C) Resolves "API.formatKB is not a function", "API.getStatusClass is not a function", and "API.getTempClass is not a function" errors. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
d1346aae0e
commit
f2fc384586
@ -128,6 +128,33 @@ function formatUptime(seconds) {
|
||||
return parts.join(' ') || '0m';
|
||||
}
|
||||
|
||||
function formatKB(kb) {
|
||||
if (!kb || kb === 0) return '0 KB';
|
||||
var units = ['KB', 'MB', 'GB', 'TB'];
|
||||
var i = 0;
|
||||
var size = kb;
|
||||
while (size >= 1024 && i < units.length - 1) {
|
||||
size = size / 1024;
|
||||
i++;
|
||||
}
|
||||
return size.toFixed(2) + ' ' + units[i];
|
||||
}
|
||||
|
||||
function getStatusClass(percent) {
|
||||
if (percent >= 90) return 'critical';
|
||||
if (percent >= 75) return 'warning';
|
||||
if (percent >= 50) return 'info';
|
||||
return 'good';
|
||||
}
|
||||
|
||||
function getTempClass(temp) {
|
||||
if (!temp) return 'good';
|
||||
if (temp >= 80) return 'critical';
|
||||
if (temp >= 70) return 'warning';
|
||||
if (temp >= 60) return 'info';
|
||||
return 'good';
|
||||
}
|
||||
|
||||
return baseclass.extend({
|
||||
// System stats
|
||||
getStats: callStats,
|
||||
@ -175,5 +202,8 @@ return baseclass.extend({
|
||||
|
||||
// Utility functions
|
||||
formatBytes: formatBytes,
|
||||
formatUptime: formatUptime
|
||||
formatKB: formatKB,
|
||||
formatUptime: formatUptime,
|
||||
getStatusClass: getStatusClass,
|
||||
getTempClass: getTempClass
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user