-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.py
More file actions
71 lines (61 loc) · 2.13 KB
/
app.py
File metadata and controls
71 lines (61 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from flask import Flask, jsonify, render_template_string, request
import psutil
import time
from collections import deque
app = Flask(__name__)
# Uptime ve geçmiş için global değişkenler
start_time = time.time()
history = deque(maxlen=10)
def collect_metrics():
cpu_percent = psutil.cpu_percent(interval=0.5)
memory = psutil.virtual_memory()._asdict()
disk = psutil.disk_usage('/')._asdict()
net = psutil.net_io_counters()._asdict()
uptime = time.time() - start_time
return {
'cpu_percent': cpu_percent,
'memory': memory,
'disk': disk,
'net_io': net,
'uptime_seconds': uptime
}
@app.route('/metrics')
def metrics():
metrics = collect_metrics()
# Geçmişe ekle
history.appendleft({'timestamp': time.strftime('%Y-%m-%d %H:%M:%S'), 'metrics': metrics})
return jsonify(metrics)
@app.route('/history')
def get_history():
return jsonify(list(history))
# Basit HTML dashboard
DASHBOARD_HTML = '''
<html>
<head><title>Server Tracker Dashboard</title></head>
<body>
<h1>Server Performance Dashboard</h1>
<div id="metrics"></div>
<button onclick="refreshMetrics()">Yenile</button>
<script>
async function refreshMetrics() {
const res = await fetch('/metrics');
const data = await res.json();
document.getElementById('metrics').innerHTML = `
<b>CPU:</b> ${data.cpu_percent}%<br>
<b>Bellek:</b> ${data.memory.percent}% (${(data.memory.used/1024/1024).toFixed(1)} MB / ${(data.memory.total/1024/1024).toFixed(1)} MB)<br>
<b>Disk:</b> ${data.disk.percent}% (${(data.disk.used/1024/1024/1024).toFixed(2)} GB / ${(data.disk.total/1024/1024/1024).toFixed(2)} GB)<br>
<b>Ağ (Toplam):</b> ${data.net_io.bytes_sent} gönderildi, ${data.net_io.bytes_recv} alındı<br>
<b>Uptime:</b> ${(data.uptime_seconds/60).toFixed(1)} dakika
`;
}
refreshMetrics();
setInterval(refreshMetrics, 5000);
</script>
</body>
</html>
'''
@app.route('/')
def dashboard():
return render_template_string(DASHBOARD_HTML)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080)