260707_2
This commit is contained in:
@@ -103,6 +103,19 @@ async def list_company_projects(company_id: int) -> list[dict[str, Any]]:
|
||||
return [_project_row(row) for row in await cursor.fetchall()]
|
||||
|
||||
|
||||
async def list_all_projects() -> list[dict[str, Any]]:
|
||||
pool = get_db_pool()
|
||||
async with pool.acquire() as connection, connection.cursor(aiomysql.DictCursor) as cursor:
|
||||
await cursor.execute(
|
||||
"""SELECT p.id, p.name, p.region, p.status, p.updated_at, p.created_at,
|
||||
u.name AS owner_name, u.email AS owner_email
|
||||
FROM projects p LEFT JOIN users u ON u.id = p.user_id
|
||||
WHERE p.deleted_at IS NULL
|
||||
ORDER BY p.updated_at DESC, p.created_at DESC"""
|
||||
)
|
||||
return [_project_row(row) for row in await cursor.fetchall()]
|
||||
|
||||
|
||||
async def get_user_company(company_id: int | None) -> dict[str, Any] | None:
|
||||
if company_id is None:
|
||||
return None
|
||||
@@ -399,10 +412,23 @@ async def get_system_resources(days: int = 30) -> dict[str, Any]:
|
||||
# 다운샘플링: 조회 구간을 최대 TARGET_POINTS개 시간버킷으로 나눠 평균.
|
||||
# 계측 간격(2분)보다 버킷이 작으면 원본 그대로(버킷=간격) 반환.
|
||||
target_points = 300
|
||||
bucket_seconds = max(120, (days * 86400) // target_points)
|
||||
await cursor.execute(
|
||||
"""SELECT
|
||||
FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(timestamp) / %s) * %s) AS timestamp,
|
||||
"SELECT COUNT(*) AS cnt FROM system_resources WHERE timestamp >= %s",
|
||||
(since,),
|
||||
)
|
||||
row_cnt_res = await cursor.fetchone()
|
||||
row_count = row_cnt_res["cnt"] if row_cnt_res else 0
|
||||
if row_count <= target_points:
|
||||
bucket_seconds = 120
|
||||
else:
|
||||
bucket_seconds = max(120, (days * 86400) // target_points)
|
||||
date_fmt = "%%Y-%%m-%%dT%%H:%%i:%%s"
|
||||
await cursor.execute(
|
||||
f"""SELECT
|
||||
DATE_FORMAT(
|
||||
FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(timestamp) / %s) * %s),
|
||||
'{date_fmt}'
|
||||
) AS timestamp,
|
||||
ROUND(AVG(cpu_usage_percent), 2) AS cpu_usage_percent,
|
||||
ROUND(AVG(memory_usage_percent), 2) AS memory_usage_percent,
|
||||
ROUND(AVG(disk_usage_percent), 2) AS disk_usage_percent,
|
||||
|
||||
Reference in New Issue
Block a user