मॉनिटरिंग और लॉगिंग

FastAPI के साथ प्रोडक्शन में AI डिप्लॉय करना

Matt Eckerle

Software and Data Engineering Leader

मॉनिटरिंग और लॉगिंग क्यों?

 

  • प्रोडक्शन में डिबग नहीं कर सकते
  • ऐप सुपरवाइज़र को सरल हेल्थ चेक चाहिए
  • समय के साथ मुख्य मेट्रिक्स लॉग करें

मॉनिटरिंग और लॉगिंग सॉफ्टवेयर

FastAPI के साथ प्रोडक्शन में AI डिप्लॉय करना

कस्टम लॉगिंग सेट करना

 

 

  • uvicorn एरर लॉगर लोड करें

 

  • ऐप स्टार्टअप पर कस्टम लॉग जोड़ें

 

  • एंडपॉइंट्स पर कस्टम लॉग जोड़ें
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 के साथ प्रोडक्शन में AI डिप्लॉय करना

मॉडल लोड होने पर लॉग करना

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 के साथ प्रोडक्शन में AI डिप्लॉय करना

मिडलवेयर से प्रोसेस समय लॉग करना

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 के साथ प्रोडक्शन में AI डिप्लॉय करना

लॉगिंग लेवल सेट करना

 

Python लॉगिंग लेवल्स

uvicorn main:app --log-level debug
FastAPI के साथ प्रोडक्शन में AI डिप्लॉय करना

मॉनिटरिंग

 

from fastapi import FastAPI

app = FastAPI()

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

 

 

 

  • "I'm ok!"
FastAPI के साथ प्रोडक्शन में AI डिप्लॉय करना

मॉनिटरिंग के साथ मॉडल पैरामीटर्स साझा करना

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}

 

 

 

 

 

  • "I'm ok!"
  • "Here are some fun facts about me!"
FastAPI के साथ प्रोडक्शन में AI डिप्लॉय करना

अभ्यास करते हैं!

FastAPI के साथ प्रोडक्शन में AI डिप्लॉय करना

Preparing Video For Download...