Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Server Stats #823

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions r2r/main/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ def _ensure_authenticated(self):
def health(self) -> dict:
return self._make_request("GET", "health")

def server_stats(self) -> dict:
self._ensure_authenticated()
return self._make_request("GET", "server_stats")

def update_prompt(
self,
name: str = "default_system",
Expand Down
27 changes: 27 additions & 0 deletions r2r/main/api/routes/management/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# TODO - Cleanup the handling for non-auth configurations
from datetime import datetime, timezone

import psutil
from fastapi import Depends
from pydantic import BaseModel

Expand All @@ -21,13 +24,37 @@
class ManagementRouter(BaseRouter):
def __init__(self, engine: R2REngine):
super().__init__(engine)
self.start_time = datetime.now(timezone.utc)
self.setup_routes()

def setup_routes(self):
@self.router.get("/health")
async def health_check():
return {"response": "ok"}

@self.router.get("/server_stats")
@self.base_endpoint
async def server_stats(
auth_user=(
Depends(self.engine.providers.auth.auth_wrapper)
if self.engine.providers.auth
else None
),
):
if not auth_user.is_superuser:
raise R2RException(
"Only an authorized user can call the `server_stats` endpoint.",
403,
)
return {
"start_time": self.start_time.isoformat(),
"uptime_seconds": (
datetime.now(timezone.utc) - self.start_time
).total_seconds(),
"cpu_usage": psutil.cpu_percent(),
"memory_usage": psutil.virtual_memory().percent,
}

@self.router.post("/update_prompt")
@self.base_endpoint
async def update_prompt_app(
Expand Down
1 change: 0 additions & 1 deletion r2r/pipes/ingestion/chunking_pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ async def _run_logic(

try:
iteration = 0
print("item.data = ", item.data)
async for chunk in self.chunking_provider.chunk(item.data):
yield Fragment(
id=generate_id_from_label(f"{item.id}-{iteration}"),
Expand Down
Loading