async fetch to limit load
This commit is contained in:
Binary file not shown.
2
main.py
2
main.py
@@ -107,7 +107,7 @@ def check_and_log_overages():
|
||||
db.add(event)
|
||||
db.commit()
|
||||
db.close()
|
||||
time.sleep(10)
|
||||
time.sleep(60)
|
||||
|
||||
threading.Thread(target=check_and_log_overages, daemon=True).start()
|
||||
|
||||
|
||||
BIN
wall_messages.db
BIN
wall_messages.db
Binary file not shown.
@@ -236,27 +236,49 @@
|
||||
const cpu = parseInt(document.getElementById('cpuLimit').value, 10);
|
||||
const ram = parseInt(document.getElementById('ramLimit').value, 10);
|
||||
const disk = parseInt(document.getElementById('diskLimit').value, 10);
|
||||
console.log(cpu, ram, disk);
|
||||
const requestBody = JSON.stringify({
|
||||
cpu_threshold: cpu,
|
||||
ram_threshold: ram,
|
||||
disk_threshold: disk
|
||||
});
|
||||
console.log(requestBody);
|
||||
|
||||
await fetch('/limits', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: requestBody
|
||||
}).then(async (response) => {
|
||||
if (response.ok) {
|
||||
try {
|
||||
const limits = await response.json();
|
||||
document.getElementById('cpuLimit').value = limits.cpu;
|
||||
document.getElementById('ramLimit').value = limits.ram;
|
||||
document.getElementById('diskLimit').value = limits.disk;
|
||||
document.getElementById('cpuLimitValue').textContent = limits.cpu + '%';
|
||||
document.getElementById('ramLimitValue').textContent = limits.ram + '%';
|
||||
document.getElementById('diskLimitValue').textContent = limits.disk + '%';
|
||||
} catch (e) {
|
||||
console.error('Error fetching limits:', e);
|
||||
// fallback: set to 50 if error
|
||||
document.getElementById('cpuLimit').value = 50;
|
||||
document.getElementById('ramLimit').value = 50;
|
||||
document.getElementById('diskLimit').value = 50;
|
||||
document.getElementById('cpuLimitValue').textContent = '50%';
|
||||
document.getElementById('ramLimitValue').textContent = '50%';
|
||||
document.getElementById('diskLimitValue').textContent = '50%';
|
||||
}
|
||||
} else {
|
||||
console.error('Error updating limits:', response.statusText);
|
||||
}
|
||||
}).catch(error => {
|
||||
console.error('Error updating limits:', error);
|
||||
});
|
||||
};
|
||||
|
||||
window.onload = function() {
|
||||
fetchStats();
|
||||
setInterval(fetchStats, 5000); // Fetch every 5 seconds
|
||||
setInterval(fetchStats, 15000); // Fetch every 5 seconds
|
||||
fetchLimits();
|
||||
setupLimitSliders();
|
||||
setInterval(fetchLimits, 5000); // Fetch limits every 5 seconds
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user