This file contains hidden or 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
$ uvicorn --host 0.0.0.0 --port 8220 monitor:server | |
INFO: Started server process [22687] | |
07-06 14:39:36 uvicorn.error INFO Started server process [22687] | |
INFO: Waiting for application startup. | |
07-06 14:39:36 uvicorn.error INFO Waiting for application startup. | |
07-06 14:39:36 EasyRpc-server /ws/charts WARNING Dataset with name cpu already exists | |
07-06 14:39:36 EasyRpc-server /ws/charts WARNING Dataset with name mem already exists | |
07-06 14:39:36 EasyScheduler WARNING resource_monitor next_run_time: 2021-07-06 14:40:00.473144 - default_args: {'args': [], 'kwargs': {}} | |
INFO: Application startup complete. | |
07-06 14:39:36 uvicorn.error INFO Application startup complete. |
This file contains hidden or 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
import datetime, psutil | |
import asyncio | |
from fastapi import FastAPI | |
from easycharts import ChartServer | |
from easyschedule import EasyScheduler | |
scheduler = EasyScheduler() | |
server = FastAPI() | |
every_minute = '* * * * *' |
This file contains hidden or 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
@scheduler(schedule=every_minute) | |
async def resource_monitor(): | |
time_now=datetime.datetime.now().isoformat()[11:19] | |
# updates CPU & MEM datasets with current time | |
await server.charts.update_dataset( | |
'cpu', | |
label=time_now, | |
data=psutil.cpu_percent() | |
) |
This file contains hidden or 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
# set initial sync time | |
time_now=datetime.datetime.now().isoformat()[11:19] | |
await server.charts.create_dataset( | |
'cpu', | |
labels=[time_now], | |
dataset=[psutil.cpu_percent()] | |
) | |
await server.charts.create_dataset( |
This file contains hidden or 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
scheduler = EasyScheduler() | |
server = FastAPI() | |
every_minute = '* * * * *' | |
@server.on_event('startup') | |
async def setup(): | |
asyncio.create_task(scheduler.start()) | |
server.charts = await ChartServer.create( | |
server, |
This file contains hidden or 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
import datetime, psutil | |
import asyncio | |
from fastapi import FastAPI | |
from easycharts import ChartServer | |
from easyschedule import EasyScheduler |
This file contains hidden or 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
from fastapi import FastAPI | |
app = FastAPI() | |
@app.get('/') | |
async def hello_api(): | |
return "hello world" |
This file contains hidden or 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
from fastapi import FastAPI | |
app = FastAPI() | |
@app.get('/') | |
async def hello_world(): | |
return "Hello World!" |
This file contains hidden or 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
from fastapi import FastAPI, APIRouter | |
# import sub modules | |
from finance import finance | |
from hr import hr | |
from marketing import marketing | |
server = FastAPI() | |
@server.on_event('startup') |
This file contains hidden or 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
from fastapi import FastAPI, Request | |
app = FastAPI() | |
@app.middleware("http") | |
async def change_path(request: Request, call_next): | |
# get mutable copy of request | |
request = dict(request) | |
# extract host from headers |