prvi poskus
This commit is contained in:
Binary file not shown.
25
compose.yml
Normal file
25
compose.yml
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
db:
|
||||||
|
image: postgres:16
|
||||||
|
environment:
|
||||||
|
POSTGRES_USER: sysmon
|
||||||
|
POSTGRES_PASSWORD: sysmonpass
|
||||||
|
POSTGRES_DB: sysmondb
|
||||||
|
volumes:
|
||||||
|
- db_data:/var/lib/postgresql/data
|
||||||
|
ports:
|
||||||
|
- "5432:5432"
|
||||||
|
|
||||||
|
nuiks-sysmon:
|
||||||
|
image: nuiks-sysmon:latest
|
||||||
|
environment:
|
||||||
|
DATABASE_URL: postgres://sysmon:sysmonpass@db:5432/sysmondb
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
ports:
|
||||||
|
- "8080:8080"
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
db_data:
|
||||||
78
main.py
78
main.py
@@ -13,18 +13,19 @@ import threading
|
|||||||
|
|
||||||
if os.environ.get("DATABASE_URL") == None:
|
if os.environ.get("DATABASE_URL") == None:
|
||||||
os.environ["DATABASE_URL"] = "sqlite:///./wall_messages.db"
|
os.environ["DATABASE_URL"] = "sqlite:///./wall_messages.db"
|
||||||
|
else
|
||||||
|
DATABASE_URL = os.environ["DATABASE_URL"]
|
||||||
|
DATABASE_PASSWORD = os.environ["DATABASE_PASSWORD"]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
cpu_threshold = 80
|
|
||||||
ram_threshold = 80
|
|
||||||
disk_threshold = 80
|
|
||||||
|
|
||||||
cpu_normal = True
|
cpu_normal = True
|
||||||
ram_normal = True
|
ram_normal = True
|
||||||
disk_normal = True
|
disk_normal = True
|
||||||
|
|
||||||
DATABASE_URL = "sqlite:///./wall_messages.db"
|
|
||||||
|
|
||||||
engine = create_engine(DATABASE_URL, connect_args={"check_same_thread": False})
|
engine = create_engine(DATABASE_URL, connect_args={"check_same_thread": False})
|
||||||
SessionLocal = sessionmaker(bind=engine)
|
SessionLocal = sessionmaker(bind=engine)
|
||||||
@@ -79,7 +80,7 @@ def check_and_log_overages():
|
|||||||
cpu_limit = limits.cpu_threshold
|
cpu_limit = limits.cpu_threshold
|
||||||
ram_limit = limits.ram_threshold
|
ram_limit = limits.ram_threshold
|
||||||
disk_limit = limits.disk_threshold
|
disk_limit = limits.disk_threshold
|
||||||
|
print("LIMITS: ",cpu_limit, ram_limit, disk_limit)
|
||||||
cpu = psutil.cpu_percent(interval=0.5)
|
cpu = psutil.cpu_percent(interval=0.5)
|
||||||
ram = psutil.virtual_memory().percent
|
ram = psutil.virtual_memory().percent
|
||||||
disk = psutil.disk_usage('/').percent
|
disk = psutil.disk_usage('/').percent
|
||||||
@@ -115,9 +116,8 @@ def check_and_log_overages():
|
|||||||
|
|
||||||
threading.Thread(target=check_and_log_overages, daemon=True).start()
|
threading.Thread(target=check_and_log_overages, daemon=True).start()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
|
||||||
class Info(BaseModel):
|
class Info(BaseModel):
|
||||||
uptime: datetime.datetime
|
uptime: datetime.datetime
|
||||||
cpu: float
|
cpu: float
|
||||||
@@ -136,46 +136,56 @@ class Thresholds(BaseModel):
|
|||||||
disk_threshold: int
|
disk_threshold: int
|
||||||
|
|
||||||
|
|
||||||
@app.get("/info", response_class=Info)
|
@app.get("/info", response_model=Info)
|
||||||
def get_info():
|
def get_info():
|
||||||
cpu = psutil.cpu_percent(interval=0.5)
|
db = SessionLocal()
|
||||||
ram = psutil.virtual_memory().percent
|
limits = db.query(LimitsModel).first()
|
||||||
disk = psutil.disk_usage('/').percent
|
if not limits:
|
||||||
uptime = time.time() - start_time
|
db.close()
|
||||||
info = Info(
|
raise HTTPException(status_code=404, detail="Limits not found")
|
||||||
uptime=uptime,
|
delta_seconds = int(time.time() - start_time)
|
||||||
cpu=cpu,
|
system_information = Info(
|
||||||
ram=ram,
|
uptime=datetime.datetime.now() - datetime.timedelta(seconds=delta_seconds),
|
||||||
disk=disk,
|
cpu=psutil.cpu_percent(interval=0.5),
|
||||||
cpu_threshold=cpu_threshold,
|
ram=psutil.virtual_memory().percent,
|
||||||
ram_threshold=ram_threshold,
|
disk=psutil.disk_usage('/').percent,
|
||||||
disk_threshold=disk_threshold,
|
cpu_threshold=limits.cpu_threshold,
|
||||||
cpu_normal=cpu <= cpu_threshold,
|
ram_threshold=limits.ram_threshold,
|
||||||
ram_normal=ram <= ram_threshold,
|
disk_threshold=limits.disk_threshold,
|
||||||
disk_normal=disk <= disk_threshold
|
cpu_normal=cpu_normal,
|
||||||
|
ram_normal=ram_normal,
|
||||||
|
disk_normal=disk_normal
|
||||||
)
|
)
|
||||||
return info
|
print(system_information)
|
||||||
|
return system_information
|
||||||
|
|
||||||
@app.get("/limits", response_model=Thresholds)
|
@app.get("/limits", response_model=Thresholds)
|
||||||
def get_limits():
|
def get_limits():
|
||||||
|
db = SessionLocal()
|
||||||
|
limits = db.query(LimitsModel).first()
|
||||||
|
if not limits:
|
||||||
|
db.close()
|
||||||
|
raise HTTPException(status_code=404, detail="Limits not found")
|
||||||
return {
|
return {
|
||||||
"cpu_threshold": cpu_threshold,
|
"cpu_threshold": limits.cpu_threshold,
|
||||||
"ram_threshold": ram_threshold,
|
"ram_threshold": limits.ram_threshold,
|
||||||
"disk_threshold": disk_threshold
|
"disk_threshold": limits.disk_threshold
|
||||||
}
|
}
|
||||||
|
|
||||||
@app.post("/limits")
|
@app.post("/limits")
|
||||||
def set_limits(thresholds: Thresholds):
|
def set_limits(thresholds: Thresholds):
|
||||||
|
print (thresholds)
|
||||||
db = SessionLocal()
|
db = SessionLocal()
|
||||||
limits = db.query(LimitsModel).first()
|
limits = db.query(LimitsModel).first()
|
||||||
|
cpu_threshold = thresholds.cpu_threshold
|
||||||
|
ram_threshold = thresholds.ram_threshold
|
||||||
|
disk_threshold = thresholds.disk_threshold
|
||||||
if limits:
|
if limits:
|
||||||
limits.cpu_threshold = thresholds.cpu_threshold
|
limits.cpu_threshold = cpu_threshold
|
||||||
limits.ram_threshold = thresholds.ram_threshold
|
limits.ram_threshold = ram_threshold
|
||||||
limits.disk_threshold = thresholds.disk_threshold
|
limits.disk_threshold = disk_threshold
|
||||||
db.commit()
|
db.commit()
|
||||||
db.refresh(limits)
|
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"cpu": cpu_threshold,
|
"cpu": cpu_threshold,
|
||||||
"ram": ram_threshold,
|
"ram": ram_threshold,
|
||||||
|
|||||||
BIN
wall_messages.db
BIN
wall_messages.db
Binary file not shown.
@@ -21,20 +21,19 @@
|
|||||||
<div class="stat"><span class="label">CPU Usage:</span> <span class="value" id="cpu">--</span></div>
|
<div class="stat"><span class="label">CPU Usage:</span> <span class="value" id="cpu">--</span></div>
|
||||||
<div class="stat"><span class="label">RAM Usage:</span> <span class="value" id="ram">--</span></div>
|
<div class="stat"><span class="label">RAM Usage:</span> <span class="value" id="ram">--</span></div>
|
||||||
<div class="stat"><span class="label">SSD Usage:</span> <span class="value" id="disk">--</span></div>
|
<div class="stat"><span class="label">SSD Usage:</span> <span class="value" id="disk">--</span></div>
|
||||||
<div class="stat"><span class="label">Uptime:</span> <span class="value" id="uptime">--</span></div>
|
<div class="stat"><span class="label">Up since:</span> <span class="value" id="uptime">--</span></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="container" style="margin-top:24px;">
|
<div class="container" style="margin-top:24px;">
|
||||||
<h1>Limit overages</h1>
|
<h1>Limit overages</h1>
|
||||||
<form id="addMessageForm" style="margin-bottom:16px;">
|
|
||||||
<input type="text" id="newMessage" placeholder="Type a message..." style="width:70%;padding:8px;" required>
|
|
||||||
<button type="submit" class="refresh-btn" style="display:inline-block;margin:0;">Add</button>
|
|
||||||
</form>
|
|
||||||
<ul id="messages" style="list-style:none;padding:0;"></ul>
|
<ul id="messages" style="list-style:none;padding:0;"></ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="container" style="margin-top:24px;">
|
<div class="container" style="margin-top:24px;">
|
||||||
<h1>Resource Limits</h1>
|
<h1>Resource Limits</h1>
|
||||||
|
<script>
|
||||||
|
|
||||||
|
</script>
|
||||||
<div class="stat">
|
<div class="stat">
|
||||||
<span class="label">CPU Limit:</span>
|
<span class="label">CPU Limit:</span>
|
||||||
<input type="range" id="cpuLimit" min="1" max="100" value="50" style="flex:1;margin:0 12px;">
|
<input type="range" id="cpuLimit" min="1" max="100" value="50" style="flex:1;margin:0 12px;">
|
||||||
@@ -53,19 +52,134 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
async function fetchOverages() {
|
||||||
|
try {
|
||||||
|
const res = await fetch('/overages');
|
||||||
|
const data = await res.json();
|
||||||
|
const messages = document.getElementById('messages');
|
||||||
|
// Replace <ul> with a table for better alignment
|
||||||
|
// If table doesn't exist, create it
|
||||||
|
let table = document.getElementById('overagesTable');
|
||||||
|
if (!table) {
|
||||||
|
table = document.createElement('table');
|
||||||
|
table.id = 'overagesTable';
|
||||||
|
table.style.width = '100%';
|
||||||
|
table.style.borderCollapse = 'collapse';
|
||||||
|
table.innerHTML = `
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th style="text-align:left;padding:8px 4px;">ID</th>
|
||||||
|
<th style="text-align:center;padding:8px 4px;">CPU</th>
|
||||||
|
<th style="text-align:center;padding:8px 4px;">RAM</th>
|
||||||
|
<th style="text-align:center;padding:8px 4px;">DISK</th>
|
||||||
|
<th style="text-align:left;padding:8px 4px;">Timestamp</th>
|
||||||
|
<th style="text-align:center;padding:8px 4px;">Action</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody></tbody>
|
||||||
|
`;
|
||||||
|
messages.innerHTML = '';
|
||||||
|
messages.appendChild(table);
|
||||||
|
}
|
||||||
|
const tbody = table.querySelector('tbody');
|
||||||
|
tbody.innerHTML = '';
|
||||||
|
data.forEach(item => {
|
||||||
|
const tr = document.createElement('tr');
|
||||||
|
tr.style.borderBottom = '1px solid #eee';
|
||||||
|
|
||||||
|
// ID
|
||||||
|
const idTd = document.createElement('td');
|
||||||
|
idTd.textContent = `#${item.id}`;
|
||||||
|
idTd.style.padding = '8px 4px';
|
||||||
|
|
||||||
|
// CPU
|
||||||
|
const cpuTd = document.createElement('td');
|
||||||
|
cpuTd.style.textAlign = 'center';
|
||||||
|
cpuTd.style.padding = '8px 4px';
|
||||||
|
cpuTd.textContent = item.cpu === 1 ? '↑' : '↓';
|
||||||
|
cpuTd.style.color = item.cpu === 1 ? 'red' : 'green';
|
||||||
|
|
||||||
|
// RAM
|
||||||
|
const ramTd = document.createElement('td');
|
||||||
|
ramTd.style.textAlign = 'center';
|
||||||
|
ramTd.style.padding = '8px 4px';
|
||||||
|
ramTd.textContent = item.ram === 1 ? '↑' : '↓';
|
||||||
|
ramTd.style.color = item.ram === 1 ? 'red' : 'green';
|
||||||
|
|
||||||
|
// DISK
|
||||||
|
const diskTd = document.createElement('td');
|
||||||
|
diskTd.style.textAlign = 'center';
|
||||||
|
diskTd.style.padding = '8px 4px';
|
||||||
|
diskTd.textContent = item.disk === 1 ? '↑' : '↓';
|
||||||
|
diskTd.style.color = item.disk === 1 ? 'red' : 'green';
|
||||||
|
|
||||||
|
// Timestamp
|
||||||
|
const tsTd = document.createElement('td');
|
||||||
|
const date = new Date(item.timestamp);
|
||||||
|
tsTd.textContent = date.toLocaleString();
|
||||||
|
tsTd.style.padding = '8px 4px';
|
||||||
|
|
||||||
|
// Delete button
|
||||||
|
const delTd = document.createElement('td');
|
||||||
|
delTd.style.textAlign = 'center';
|
||||||
|
delTd.style.padding = '8px 4px';
|
||||||
|
const delBtn = document.createElement('button');
|
||||||
|
delBtn.textContent = 'Delete';
|
||||||
|
delBtn.style.background = '#e74c3c';
|
||||||
|
delBtn.style.color = '#fff';
|
||||||
|
delBtn.style.border = 'none';
|
||||||
|
delBtn.style.borderRadius = '4px';
|
||||||
|
delBtn.style.padding = '4px 12px';
|
||||||
|
delBtn.style.cursor = 'pointer';
|
||||||
|
delBtn.onclick = async () => {
|
||||||
|
await fetch(`/overages/${item.id}`, { method: 'DELETE' });
|
||||||
|
fetchOverages();
|
||||||
|
};
|
||||||
|
delTd.appendChild(delBtn);
|
||||||
|
|
||||||
|
tr.appendChild(idTd);
|
||||||
|
tr.appendChild(cpuTd);
|
||||||
|
tr.appendChild(ramTd);
|
||||||
|
tr.appendChild(diskTd);
|
||||||
|
tr.appendChild(tsTd);
|
||||||
|
tr.appendChild(delTd);
|
||||||
|
|
||||||
|
tbody.appendChild(tr);
|
||||||
|
});
|
||||||
|
// If no data, show a message
|
||||||
|
if (data.length === 0) {
|
||||||
|
const tr = document.createElement('tr');
|
||||||
|
const td = document.createElement('td');
|
||||||
|
td.colSpan = 6;
|
||||||
|
td.style.textAlign = 'center';
|
||||||
|
td.style.padding = '12px';
|
||||||
|
td.textContent = 'No overages.';
|
||||||
|
tr.appendChild(td);
|
||||||
|
tbody.appendChild(tr);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error fetching overages:', e);
|
||||||
|
document.getElementById('messages').innerHTML = '<span style="color:red;">Error loading overages</span>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setInterval(fetchOverages, 5000);
|
||||||
|
window.addEventListener('load', fetchOverages);
|
||||||
|
|
||||||
|
|
||||||
async function fetchStats() {
|
async function fetchStats() {
|
||||||
try {
|
try {
|
||||||
const [cpu, ram, disk, uptime] = await Promise.all([
|
const sysInfo = await fetch('/info');
|
||||||
fetch('/cpu').then(res => res.json()),
|
const data = await sysInfo.json();
|
||||||
fetch('/ram').then(res => res.json()),
|
// Format timestamps
|
||||||
fetch('/disk').then(res => res.json()),
|
data.uptime = formatTimestamp(data.uptime);
|
||||||
fetch('/uptime').then(res => res.json())
|
|
||||||
]);
|
document.getElementById('cpu').textContent = data.cpu + '%';
|
||||||
document.getElementById('cpu').textContent = cpu.cpu_percent + '%';
|
document.getElementById('ram').textContent = data.ram + '%';
|
||||||
document.getElementById('ram').textContent = ram.percent + '%';
|
document.getElementById('disk').textContent = data.disk + '%';
|
||||||
document.getElementById('disk').textContent = disk.percent + '%';
|
document.getElementById('uptime').textContent = data.uptime + ' s';
|
||||||
document.getElementById('uptime').textContent = uptime.uptime_seconds + ' s';
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.error('Error fetching system stats:', e);
|
||||||
document.getElementById('cpu').textContent = 'Error';
|
document.getElementById('cpu').textContent = 'Error';
|
||||||
document.getElementById('ram').textContent = 'Error';
|
document.getElementById('ram').textContent = 'Error';
|
||||||
document.getElementById('disk').textContent = 'Error';
|
document.getElementById('disk').textContent = 'Error';
|
||||||
@@ -81,89 +195,20 @@
|
|||||||
}
|
}
|
||||||
return date.toLocaleString();
|
return date.toLocaleString();
|
||||||
}
|
}
|
||||||
// Wall Messages CRUD
|
|
||||||
async function fetchMessages() {
|
|
||||||
const res = await fetch('/wall');
|
|
||||||
const messages = await res.json();
|
|
||||||
const ul = document.getElementById('messages');
|
|
||||||
ul.innerHTML = '';
|
|
||||||
messages.forEach(msg => {
|
|
||||||
const li = document.createElement('li');
|
|
||||||
li.style.display = 'flex';
|
|
||||||
li.style.justifyContent = 'space-between';
|
|
||||||
li.style.alignItems = 'center';
|
|
||||||
li.style.padding = '8px 0';
|
|
||||||
|
|
||||||
const span = document.createElement('span');
|
|
||||||
span.textContent = formatTimestamp(msg.timestamp) + " " + msg.text;
|
|
||||||
|
|
||||||
const editBtn = document.createElement('button');
|
|
||||||
editBtn.textContent = 'Edit';
|
|
||||||
editBtn.className = 'refresh-btn';
|
|
||||||
editBtn.style.background = '#ffa500';
|
|
||||||
editBtn.style.marginRight = '8px';
|
|
||||||
editBtn.onclick = () => editMessage(msg);
|
|
||||||
|
|
||||||
const delBtn = document.createElement('button');
|
|
||||||
delBtn.textContent = 'Delete';
|
|
||||||
delBtn.className = 'refresh-btn';
|
|
||||||
delBtn.style.background = '#d40000';
|
|
||||||
delBtn.onclick = () => deleteMessage(msg.id);
|
|
||||||
|
|
||||||
const btns = document.createElement('span');
|
|
||||||
btns.appendChild(editBtn);
|
|
||||||
btns.appendChild(delBtn);
|
|
||||||
|
|
||||||
li.appendChild(span);
|
|
||||||
li.appendChild(btns);
|
|
||||||
ul.appendChild(li);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function addMessage(text) {
|
|
||||||
await fetch('/wall', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {'Content-Type': 'application/json'},
|
|
||||||
body: JSON.stringify({text})
|
|
||||||
});
|
|
||||||
fetchMessages();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function deleteMessage(id) {
|
|
||||||
await fetch(`/wall/${id}`, { method: 'DELETE' });
|
|
||||||
fetchMessages();
|
|
||||||
}
|
|
||||||
|
|
||||||
function editMessage(msg) {
|
|
||||||
const newText = prompt('Edit message:', msg.text);
|
|
||||||
if (newText !== null && newText.trim() !== '') {
|
|
||||||
updateMessage(msg.id, newText.trim());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function updateMessage(id, text) {
|
|
||||||
await fetch(`/wall/${id}`, {
|
|
||||||
method: 'PUT',
|
|
||||||
headers: {'Content-Type': 'application/json'},
|
|
||||||
body: JSON.stringify({text})
|
|
||||||
});
|
|
||||||
fetchMessages();
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
// --- Resource Limits Sliders ---
|
// --- Resource Limits Sliders ---
|
||||||
async function fetchLimits() {
|
async function fetchLimits() {
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/limits');
|
const res = await fetch('/limits');
|
||||||
const limits = await res.json();
|
const limits = await res.json();
|
||||||
document.getElementById('cpuLimit').value = limits.cpu;
|
document.getElementById('cpuLimit').value = limits.cpu_threshold;
|
||||||
document.getElementById('ramLimit').value = limits.ram;
|
document.getElementById('ramLimit').value = limits.ram_threshold;
|
||||||
document.getElementById('diskLimit').value = limits.disk;
|
document.getElementById('diskLimit').value = limits.disk_threshold;
|
||||||
document.getElementById('cpuLimitValue').textContent = limits.cpu + '%';
|
document.getElementById('cpuLimitValue').textContent = limits.cpu_threshold + '%';
|
||||||
document.getElementById('ramLimitValue').textContent = limits.ram + '%';
|
document.getElementById('ramLimitValue').textContent = limits.ram_threshold + '%';
|
||||||
document.getElementById('diskLimitValue').textContent = limits.disk + '%';
|
document.getElementById('diskLimitValue').textContent = limits.disk_threshold + '%';
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.error('Error fetching limits:', e);
|
||||||
// fallback: set to 50 if error
|
// fallback: set to 50 if error
|
||||||
document.getElementById('cpuLimit').value = 50;
|
document.getElementById('cpuLimit').value = 50;
|
||||||
document.getElementById('ramLimit').value = 50;
|
document.getElementById('ramLimit').value = 50;
|
||||||
@@ -174,17 +219,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateLimits() {
|
|
||||||
const cpu = parseInt(document.getElementById('cpuLimit').value, 10);
|
|
||||||
const ram = parseInt(document.getElementById('ramLimit').value, 10);
|
|
||||||
const disk = parseInt(document.getElementById('diskLimit').value, 10);
|
|
||||||
await fetch('/limits', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {'Content-Type': 'application/json'},
|
|
||||||
body: JSON.stringify({ cpu, ram, disk })
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function setupLimitSliders() {
|
function setupLimitSliders() {
|
||||||
['cpu', 'ram', 'disk'].forEach(resource => {
|
['cpu', 'ram', 'disk'].forEach(resource => {
|
||||||
const slider = document.getElementById(resource + 'Limit');
|
const slider = document.getElementById(resource + 'Limit');
|
||||||
@@ -198,21 +232,28 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById('addMessageForm').onsubmit = function(e) {
|
async function updateLimits() {
|
||||||
e.preventDefault();
|
const cpu = parseInt(document.getElementById('cpuLimit').value, 10);
|
||||||
const input = document.getElementById('newMessage');
|
const ram = parseInt(document.getElementById('ramLimit').value, 10);
|
||||||
const text = input.value.trim();
|
const disk = parseInt(document.getElementById('diskLimit').value, 10);
|
||||||
if (text) {
|
console.log(cpu, ram, disk);
|
||||||
addMessage(text);
|
const requestBody = JSON.stringify({
|
||||||
input.value = '';
|
cpu_threshold: cpu,
|
||||||
}
|
ram_threshold: ram,
|
||||||
};
|
disk_threshold: disk
|
||||||
|
});
|
||||||
|
console.log(requestBody);
|
||||||
|
|
||||||
|
await fetch('/limits', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {'Content-Type': 'application/json'},
|
||||||
|
body: requestBody
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
fetchStats();
|
fetchStats();
|
||||||
setInterval(fetchStats, 5000); // Fetch every 5 seconds
|
setInterval(fetchStats, 5000); // Fetch every 5 seconds
|
||||||
fetchMessages();
|
|
||||||
setInterval(fetchMessages, 5000); // Fetch messages every 5 seconds
|
|
||||||
fetchLimits();
|
fetchLimits();
|
||||||
setupLimitSliders();
|
setupLimitSliders();
|
||||||
setInterval(fetchLimits, 5000); // Fetch limits every 5 seconds
|
setInterval(fetchLimits, 5000); // Fetch limits every 5 seconds
|
||||||
|
|||||||
Reference in New Issue
Block a user