remove old import
This commit is contained in:
@@ -27,6 +27,8 @@ from app.auth.security import get_admin_user, get_password_hash, create_access_t
|
||||
from app.services.audit import audit_service
|
||||
from app.config import settings
|
||||
from app.services.query_utils import apply_sorting, tokenized_ilike_filter, paginate_with_total
|
||||
from app.utils.exceptions import handle_database_errors, safe_execute
|
||||
from app.utils.logging import app_logger
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -304,7 +306,8 @@ async def system_health(
|
||||
disk_available = free_gb > 1.0 # 1GB minimum
|
||||
if not disk_available:
|
||||
alerts.append(f"Low disk space: {free_gb:.1f}GB remaining")
|
||||
except:
|
||||
except (OSError, ImportError) as e:
|
||||
app_logger.warning(f"Could not check disk space: {str(e)}")
|
||||
disk_available = True
|
||||
|
||||
# Check memory (simplified)
|
||||
@@ -331,7 +334,8 @@ async def system_health(
|
||||
active_sessions = db.query(User).filter(
|
||||
User.last_login > datetime.now(timezone.utc) - timedelta(hours=24)
|
||||
).count()
|
||||
except:
|
||||
except Exception as e:
|
||||
app_logger.warning(f"Could not query active sessions: {str(e)}")
|
||||
active_sessions = 0
|
||||
|
||||
# Check last backup
|
||||
@@ -346,7 +350,8 @@ async def system_health(
|
||||
last_backup = latest_backup.name
|
||||
if backup_age.days > 7:
|
||||
alerts.append(f"Last backup is {backup_age.days} days old")
|
||||
except:
|
||||
except (OSError, FileNotFoundError) as e:
|
||||
app_logger.warning(f"Could not check backup status: {str(e)}")
|
||||
alerts.append("Unable to check backup status")
|
||||
|
||||
# Application uptime
|
||||
@@ -398,8 +403,8 @@ async def system_statistics(
|
||||
if os.path.exists(db_path):
|
||||
size_bytes = os.path.getsize(db_path)
|
||||
db_size = f"{size_bytes / (1024*1024):.1f} MB"
|
||||
except:
|
||||
pass
|
||||
except (OSError, ValueError) as e:
|
||||
app_logger.warning(f"Could not get database size: {str(e)}")
|
||||
|
||||
# Check for recent backups
|
||||
last_backup = "Not found"
|
||||
@@ -410,8 +415,8 @@ async def system_statistics(
|
||||
if backup_files:
|
||||
latest_backup = max(backup_files, key=lambda p: p.stat().st_mtime)
|
||||
last_backup = latest_backup.name
|
||||
except:
|
||||
pass
|
||||
except (OSError, FileNotFoundError) as e:
|
||||
app_logger.warning(f"Could not check for recent backups: {str(e)}")
|
||||
|
||||
# Application uptime
|
||||
uptime_seconds = int(time.time() - APPLICATION_START_TIME)
|
||||
@@ -437,8 +442,8 @@ async def system_statistics(
|
||||
"description": f"Customer {customer.first} {customer.last} added",
|
||||
"timestamp": datetime.now(timezone.utc).isoformat()
|
||||
})
|
||||
except:
|
||||
pass
|
||||
except Exception as e:
|
||||
app_logger.warning(f"Could not get recent activity: {str(e)}")
|
||||
|
||||
return SystemStats(
|
||||
total_customers=total_customers,
|
||||
|
||||
Reference in New Issue
Block a user