İzleme ve günlükleme

FastAPI ile Üretime AI Dağıtımı

Matt Eckerle

Software and Data Engineering Leader

Neden izleme ve günlükleme?

 

  • Üretimde hata ayıklanmaz
  • Uygulama yöneticisi basit bir sağlık kontrolü ister
  • Zamanla kilit metrikleri kaydet

İzleme ve günlükleme yazılımı

FastAPI ile Üretime AI Dağıtımı

Özel günlüklemeyi ayarlama

 

 

  • uvicorn hata kaydedicisini yükle

 

  • Uygulama başlatmada özel günlükler ekle

 

  • Uç noktalara özel günlükler ekle
from fastapi import FastAPI
import logging

logger = logging.getLogger(
    'uvicorn.error'
)

app = FastAPI() logger.info("App is running!")
@app.get('/') async def main(): logger.debug('GET /') return 'ok'
FastAPI ile Üretime AI Dağıtımı

Model yüklendiğinde günlükleme

from fastapi import FastAPI
import logging
import joblib 

logger = logging.getLogger('uvicorn.error')

model = joblib.load('penguin_classifier.pkl') logger.info("Penguin classifier loaded successfully.") app = FastAPI()
FastAPI ile Üretime AI Dağıtımı

Middleware ile işlem süresini günlükleme

from fastapi import FastAPI, Request
import logging
import time
logger = logging.getLogger('uvicorn.error')
app = FastAPI()

@app.middleware("http")
async def log_process_time(request: Request, call_next):
    start_time = time.perf_counter()
    response = await call_next(request)
    process_time = time.perf_counter() - start_time
    logger.info(f"Process time was {process_time} seconds.")
    return response
1 https://fastapi.tiangolo.com/tutorial/middleware/
FastAPI ile Üretime AI Dağıtımı

Günlükleme seviyesini ayarlama

 

Python günlükleme seviyeleri

uvicorn main:app --log-level debug
FastAPI ile Üretime AI Dağıtımı

İzleme

 

from fastapi import FastAPI

app = FastAPI()

@app.get("/health") async def get_health(): return {"status": "OK"}

 

 

 

  • "İyiyim!"
FastAPI ile Üretime AI Dağıtımı

Model parametrelerini izlemeyle paylaşma

from fastapi import FastAPI
import joblib

model = joblib.load(
    'penguin_classifier.pkl'
)
app = FastAPI()

@app.get("/health") async def get_health(): params = model.get_params() return {"status": "OK", "params": params}

 

 

 

 

 

  • "İyiyim!"
  • "Hakkımda bazı ilginç bilgiler!"
FastAPI ile Üretime AI Dağıtımı

Hadi pratik yapalım!

FastAPI ile Üretime AI Dağıtımı

Preparing Video For Download...