-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4eeb5ef
commit 122dd62
Showing
12 changed files
with
112 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,6 @@ build-linux: | |
|
||
run-docker: | ||
docker run --name consumer -d consumer | ||
|
||
|
||
.PHONY: run build-local build-linux run-docker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
from fastapi import APIRouter, status | ||
from fastapi import APIRouter, status, BackgroundTasks | ||
from services.log import LoggingBackgroundClass | ||
|
||
router = APIRouter(prefix="", tags=["Health"]) | ||
|
||
|
||
@router.get("/", status_code=status.HTTP_200_OK) | ||
async def health(): | ||
return {"hello": "world"} | ||
async def health(backgound_tasks: BackgroundTasks): | ||
LoggingBackgroundClass() | ||
return {"health": "ok"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import asyncio | ||
import logging | ||
|
||
from core.config import get_settings | ||
from services.statistics import ( | ||
get_cpu_percent, | ||
get_mem_usage, | ||
get_remain_count, | ||
get_avg_exe_time, | ||
) | ||
|
||
|
||
async def backgound_logging_task(): | ||
""" | ||
level,time,cpu,ram,remain_count,avg_exe_time | ||
""" | ||
|
||
settings = get_settings() | ||
|
||
logging.basicConfig() | ||
logger = logging.getLogger("uvicorn.default") | ||
file_handler = logging.handlers.RotatingFileHandler( | ||
filename=settings.log_file, | ||
maxBytes=settings.log_max_bytes, | ||
backupCount=settings.log_backup_count, | ||
) | ||
|
||
formatter = logging.Formatter( | ||
fmt="%(asctime)s,%(message)s", | ||
datefmt="%H:%M:%S", | ||
) | ||
|
||
file_handler.setFormatter(formatter) | ||
|
||
logger.addHandler(file_handler) | ||
|
||
while True: | ||
""" | ||
level,time,cpu,ram,remain_count,avg_exe_time | ||
""" | ||
logger.info( | ||
msg=f"{get_cpu_percent()},{get_mem_usage()},{get_remain_count()},{get_avg_exe_time()}" | ||
) | ||
# print("logging...") | ||
|
||
await asyncio.sleep(settings.log_interval) | ||
|
||
|
||
class LoggingBackgroundClass: | ||
def __init__(self, *args, **kwargs) -> None: | ||
self.task = asyncio.create_task(backgound_logging_task(*args, **kwargs)) |