Skip to content

Instantly share code, notes, and snippets.

View codemation's full-sized avatar

Joshua Jamison codemation

View GitHub Profile
$ 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.
import datetime, psutil
import asyncio
from fastapi import FastAPI
from easycharts import ChartServer
from easyschedule import EasyScheduler
scheduler = EasyScheduler()
server = FastAPI()
every_minute = '* * * * *'
@codemation
codemation / update_chart.py
Created July 6, 2021 12:30
updating_chart
@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()
)
@codemation
codemation / chart_setup.py
Created July 6, 2021 12:21
Chart Creation
# 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(
@codemation
codemation / monitor_body.py
Last active July 6, 2021 12:14
monitor body
scheduler = EasyScheduler()
server = FastAPI()
every_minute = '* * * * *'
@server.on_event('startup')
async def setup():
asyncio.create_task(scheduler.start())
server.charts = await ChartServer.create(
server,
@codemation
codemation / monitor_depends.py
Created July 6, 2021 11:53
easy charts - dependencies
import datetime, psutil
import asyncio
from fastapi import FastAPI
from easycharts import ChartServer
from easyschedule import EasyScheduler
@codemation
codemation / hello.py
Created June 22, 2021 07:41
hello dev 0
from fastapi import FastAPI
app = FastAPI()
@app.get('/')
async def hello_api():
return "hello world"
@codemation
codemation / basic.py
Created June 11, 2021 22:16
hello world fastapi app
from fastapi import FastAPI
app = FastAPI()
@app.get('/')
async def hello_world():
return "Hello World!"
@codemation
codemation / main.py
Last active May 4, 2021 13:00
fastapi_no_auth
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')
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