Skip to content

Commit 2ae042c

Browse files
committed
updates
1 parent 842ad0d commit 2ae042c

4 files changed

Lines changed: 61 additions & 55 deletions

File tree

backend/resource_monitor.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,24 +378,26 @@ def get_process_metrics(self) -> Dict[str, Any]:
378378
"""Get top processes by CPU and memory"""
379379
processes = []
380380

381-
for proc in psutil.process_iter(['pid', 'name', 'cpu_percent', 'memory_percent']):
381+
for proc in psutil.process_iter(['pid', 'name', 'cpu_percent', 'memory_percent', 'memory_info', 'status']):
382382
try:
383383
pinfo = proc.info
384384
if pinfo['cpu_percent'] > 0 or pinfo['memory_percent'] > 0:
385385
processes.append({
386386
'pid': pinfo['pid'],
387387
'name': pinfo['name'],
388388
'cpu_percent': pinfo['cpu_percent'],
389-
'memory_percent': pinfo['memory_percent']
389+
'memory_percent': pinfo['memory_percent'],
390+
'memory_mb': pinfo['memory_info'].rss / (1024 * 1024) if pinfo.get('memory_info') else 0,
391+
'status': pinfo.get('status', 'unknown')
390392
})
391393
except:
392394
pass
393395

394-
# Sort by CPU usage and get top 10
396+
# Sort by CPU usage and get top 20
395397
processes.sort(key=lambda x: x['cpu_percent'], reverse=True)
396398

397399
return {
398-
"top_cpu": processes[:5],
400+
"top_cpu": processes[:20],
399401
"total_processes": len(processes),
400402
"running": len([p for p in processes if p['cpu_percent'] > 0])
401403
}

backend/server.py

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,7 +2293,7 @@ async def get_system_status(current_user: dict = Depends(get_current_user)):
22932293
"gpu": resource_monitor.get_gpu_metrics(),
22942294
"disk": resource_monitor.get_disk_metrics(),
22952295
"network": resource_monitor.get_network_metrics(),
2296-
"processes": resource_monitor.get_top_processes()
2296+
"processes": resource_monitor.get_process_metrics().get('top_cpu', [])
22972297
}
22982298

22992299
# Format for API compatibility
@@ -2398,29 +2398,27 @@ async def get_system_status(current_user: dict = Depends(get_current_user)):
23982398
boot_time = psutil.boot_time()
23992399
uptime = int(time.time() - boot_time)
24002400

2401-
# Get top processes - skip for performance
2401+
# Get top processes
24022402
processes = []
2403-
# Skip process enumeration for now to improve performance
2404-
# This was causing significant delays in the API response
2405-
# try:
2406-
# for proc in psutil.process_iter(['pid', 'name', 'cpu_percent', 'memory_info', 'status']):
2407-
# try:
2408-
# pinfo = proc.info
2409-
# processes.append({
2410-
# 'pid': pinfo['pid'],
2411-
# 'name': pinfo['name'],
2412-
# 'cpu_percent': pinfo['cpu_percent'] or 0,
2413-
# 'memory_mb': pinfo['memory_info'].rss / (1024 * 1024) if pinfo['memory_info'] else 0,
2414-
# 'status': pinfo['status']
2415-
# })
2416-
# except (psutil.NoSuchProcess, psutil.AccessDenied):
2417-
# pass
2418-
#
2419-
# # Sort by CPU usage and take top 10
2420-
# processes.sort(key=lambda x: x['cpu_percent'], reverse=True)
2421-
# processes = processes[:10]
2422-
# except Exception as e:
2423-
# print(f"Error getting processes: {e}")
2403+
try:
2404+
for proc in psutil.process_iter(['pid', 'name', 'cpu_percent', 'memory_info', 'status']):
2405+
try:
2406+
pinfo = proc.info
2407+
processes.append({
2408+
'pid': pinfo['pid'],
2409+
'name': pinfo['name'],
2410+
'cpu_percent': pinfo['cpu_percent'] or 0,
2411+
'memory_mb': pinfo['memory_info'].rss / (1024 * 1024) if pinfo['memory_info'] else 0,
2412+
'status': pinfo['status']
2413+
})
2414+
except (psutil.NoSuchProcess, psutil.AccessDenied):
2415+
pass
2416+
2417+
# Sort by CPU usage and take top 20
2418+
processes.sort(key=lambda x: x['cpu_percent'], reverse=True)
2419+
processes = processes[:20]
2420+
except Exception as e:
2421+
print(f"Error getting processes: {e}")
24242422

24252423
return {
24262424
"cpu": {

src/pages/System.jsx

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -330,25 +330,7 @@ export default function System() {
330330
const maxRetries = 3;
331331
const dataRef = useRef(historicalData);
332332

333-
// Fetch data on mount and interval
334-
useEffect(() => {
335-
fetchHardwareInfo();
336-
fetchDiskIo();
337-
fetchNetworkStats();
338-
339-
if (!autoRefresh) return;
340-
341-
const interval = setInterval(() => {
342-
fetchSystemStatus();
343-
fetchDiskIo();
344-
fetchNetworkStats();
345-
updateHistoricalData();
346-
}, refreshInterval);
347-
348-
return () => clearInterval(interval);
349-
}, [autoRefresh, refreshInterval]);
350-
351-
const fetchHardwareInfo = async () => {
333+
async function fetchHardwareInfo() {
352334
try {
353335
const response = await fetch('/api/v1/system/hardware');
354336
if (!response.ok) {
@@ -373,9 +355,9 @@ export default function System() {
373355
toast.error(errorMsg);
374356
}
375357
}
376-
};
358+
}
377359

378-
const fetchDiskIo = async () => {
360+
async function fetchDiskIo() {
379361
try {
380362
const response = await fetch('/api/v1/system/disk-io');
381363
if (!response.ok) {
@@ -400,9 +382,9 @@ export default function System() {
400382
toast.warning(errorMsg); // Use warning since disk I/O is less critical
401383
}
402384
}
403-
};
385+
}
404386

405-
const fetchNetworkStats = async () => {
387+
async function fetchNetworkStats() {
406388
try {
407389
const response = await fetch('/api/v1/network/status');
408390
if (!response.ok) {
@@ -432,9 +414,9 @@ export default function System() {
432414
toast.warning(errorMsg);
433415
}
434416
}
435-
};
417+
}
436418

437-
const updateHistoricalData = () => {
419+
function updateHistoricalData() {
438420
if (!systemStatus) return;
439421

440422
const timestamp = new Date().toLocaleTimeString();
@@ -475,7 +457,31 @@ export default function System() {
475457

476458
dataRef.current = newData;
477459
setHistoricalData(newData);
478-
};
460+
}
461+
462+
// Populate historical data whenever systemStatus updates
463+
useEffect(() => {
464+
if (systemStatus?.cpu) {
465+
updateHistoricalData();
466+
}
467+
}, [systemStatus]);
468+
469+
// Fetch data on mount and interval
470+
useEffect(() => {
471+
fetchHardwareInfo();
472+
fetchDiskIo();
473+
fetchNetworkStats();
474+
475+
if (!autoRefresh) return;
476+
477+
const interval = setInterval(() => {
478+
fetchSystemStatus();
479+
fetchDiskIo();
480+
fetchNetworkStats();
481+
}, refreshInterval);
482+
483+
return () => clearInterval(interval);
484+
}, [autoRefresh, refreshInterval]);
479485

480486
const handleKillProcess = async (pid) => {
481487
try {

src/utils/validation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ export const isCriticalProcess = (processName) => {
281281
* @returns {object} Warning message details
282282
*/
283283
export const getCriticalProcessWarning = (processName, pid) => {
284-
const impacts = {
284+
const impactMap = {
285285
'ops-center': ['Service downtime', 'Loss of admin access', 'Interrupted user sessions'],
286286
'postgres': ['Database unavailable', 'Data access lost', 'All services affected'],
287287
'redis': ['Cache cleared', 'Session data lost', 'Performance degradation'],
@@ -292,7 +292,7 @@ export const getCriticalProcessWarning = (processName, pid) => {
292292

293293
// Find matching impact list
294294
let impactList = ['Service downtime', 'Potential data loss', 'System instability'];
295-
for (const [key, impacts] of Object.entries(impacts)) {
295+
for (const [key, impacts] of Object.entries(impactMap)) {
296296
if (processName.toLowerCase().includes(key)) {
297297
impactList = impacts;
298298
break;

0 commit comments

Comments
 (0)