adaptai / projects /oui-max /tools /health.py
ADAPT-Chase's picture
Add files using upload-large-folder tool
fbf3c28 verified
"""
id: health
title: System Health (unsafe)
author: admin
description: Check Open WebUI, Ollama, network, disk, and DB connectivity.
version: 0.1.0
license: Proprietary
"""
import subprocess
import os
import sqlite3
import json
class Tools:
def check(self) -> dict:
out = {}
# Open WebUI API
try:
p = subprocess.run(
["bash", "-lc", "curl -sf http://127.0.0.1:17500/api/config"],
capture_output=True,
text=True,
timeout=5,
)
out["open_webui"] = (
json.loads(p.stdout) if p.returncode == 0 else {"error": p.stderr}
)
except Exception as e:
out["open_webui"] = {"error": str(e)}
# Ollama tags
try:
p = subprocess.run(
["bash", "-lc", "curl -sf http://127.0.0.1:21434/api/tags"],
capture_output=True,
text=True,
timeout=5,
)
out["ollama"] = (
json.loads(p.stdout) if p.returncode == 0 else {"error": p.stderr}
)
except Exception as e:
out["ollama"] = {"error": str(e)}
# Disk usage
try:
p = subprocess.run(
["bash", "-lc", "df -h /data | tail -n1"],
capture_output=True,
text=True,
timeout=5,
)
out["disk"] = p.stdout.strip()
except Exception as e:
out["disk"] = str(e)
# DB connectivity
try:
db = os.environ.get(
"WEBUI_DB",
"/data/adaptai/migrate/vast/workspace-vast1-2/webui/webui.db",
)
con = sqlite3.connect(db)
cur = con.cursor()
cur.execute("select count(*) from tool")
out["db_tool_count"] = cur.fetchone()[0]
con.close()
except Exception as e:
out["db"] = str(e)
return out