add hardware statistics collection to StorageCollector and API endpoints

This commit is contained in:
Lloyd
2025-11-29 23:03:15 +00:00
parent 748ecf33b3
commit 52e4f6bef5
2 changed files with 27 additions and 4 deletions

View File

@@ -64,6 +64,11 @@ class StorageCollector:
self.disallowed_packet_types = set()
else:
self.disallowed_packet_types = set()
# Initialize hardware stats collector
from .hardware_stats import HardwareStatsCollector
self.hardware_stats = HardwareStatsCollector()
logger.info("Hardware stats collector initialized")
def _get_live_stats(self) -> dict:
"""Get live stats from RepeaterHandler"""
@@ -228,3 +233,19 @@ class StorageCollector:
def delete_advert(self, advert_id: int) -> bool:
return self.sqlite_handler.delete_advert(advert_id)
def get_hardware_stats(self) -> Optional[dict]:
"""Get current hardware statistics"""
try:
return self.hardware_stats.get_stats()
except Exception as e:
logger.error(f"Error getting hardware stats: {e}")
return None
def get_hardware_processes(self) -> Optional[list]:
"""Get current process summary"""
try:
return self.hardware_stats.get_processes_summary()
except Exception as e:
logger.error(f"Error getting hardware processes: {e}")
return None

View File

@@ -249,8 +249,9 @@ class APIEndpoints:
"""Get comprehensive hardware statistics"""
try:
# Get hardware stats from storage collector
if hasattr(self.daemon_instance, 'storage_collector') and self.daemon_instance.storage_collector:
stats = self.daemon_instance.storage_collector.get_hardware_stats()
storage = self._get_storage()
if storage:
stats = storage.get_hardware_stats()
if stats:
return self._success(stats)
else:
@@ -267,8 +268,9 @@ class APIEndpoints:
"""Get summary of top processes"""
try:
# Get process stats from storage collector
if hasattr(self.daemon_instance, 'storage_collector') and self.daemon_instance.storage_collector:
processes = self.daemon_instance.storage_collector.get_hardware_processes()
storage = self._get_storage()
if storage:
processes = storage.get_hardware_processes()
if processes:
return self._success(processes)
else: