commit ded28ab88eac811ce1e03eecd3b6079655d532b5 Author: George Date: Thu Sep 17 18:07:47 2026 +0530 feat : --FAST API AGENT diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c595e04 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +venv/ +.env +__pycache__/ +*.pyc +.pytest_cache/ +.vscode/ +.idea/ \ No newline at end of file diff --git a/feat.txt b/feat.txt new file mode 100644 index 0000000..b7706ff --- /dev/null +++ b/feat.txt @@ -0,0 +1,39 @@ +| Area | What to show | Why it matters | +| -------------------- | -------------------------------------------- | ------------------------------------------- | +| Node status | Up/down, PostgreSQL service state, uptime | Tells you whether the node is reachable | +| CPU | Current %, load average | Detects compute saturation | +| Memory | Used/free RAM, swap | Finds memory pressure | +| Disk | Used %, free GB, IOPS, read/write latency | Disk issues can kill DB performance | +| Network | RX/TX, latency, packet loss | Important for distributed replication | +| Connections | Active, idle, total, max connections | Prevents connection exhaustion | +| Sessions | Current sessions, user, DB, client IP | Shows who is connected | +| Transactions | TPS, commits, rollbacks | Measures workload and failures | +| Query performance | Avg query time, slow queries, top queries | Finds performance bottlenecks | +| Long-running queries | Query, PID, runtime, user | Long queries often cause locks/bloat | +| Locks | Waiting locks, blocking PID, blocked query | Critical for troubleshooting stalls | +| Deadlocks | Count and recent deadlocks | Shows transaction contention | +| Cache | Buffer cache hit ratio | Indicates memory efficiency | +| Tables | Size, rows, scans, inserts, updates, deletes | Shows table activity | +| Indexes | Usage, unused indexes, index size | Helps optimize queries/storage | +| WAL | WAL generated, retained, archived | Important for replication and recovery | +| Checkpoints | Checkpoint frequency/duration | Too many checkpoints hurt performance | +| Vacuum | Last vacuum/autovacuum, failures | Prevents table bloat | +| Analyze | Last analyze, stats freshness | Needed for query planner accuracy | +| Bloat | Table/index bloat | Excess bloat wastes space and slows queries | +| Replication | Status, lag, slot status | Essential for HA/multi-master | +| Replication slots | Active/inactive, retained WAL | Inactive slots can fill disk | +| Backup | Last backup, status, duration | Tells you whether recovery is possible | +| Disk growth | Database/table/WAL growth trend | Helps capacity planning | +| Errors | PostgreSQL errors/warnings | Shows immediate operational issues | +| Security | Failed logins, unusual connections | Useful for security monitoring | + + + + + + +Using my uploaded photo, show me what I would have looked like around 1985. Preserve my identity, facial features, skin tone, age, and recognizable appearance. Reimagine my hair, clothing, accessories, and surroundings with bold, unmistakably mid-1980s styling—expressive silhouettes, statement accessories, layered details, distinctive colors, and textures. Make it feel like a genuine 1985 photograph with analog grain, faded color, direct flash, and subtle softness. Add a period-accurate 1980s red-orange date stamp in the lower corner. No recognizable posters. No modern objects or text. + + + + diff --git a/instructions.txt b/instructions.txt new file mode 100644 index 0000000..e5e8824 --- /dev/null +++ b/instructions.txt @@ -0,0 +1,18 @@ +|==================================================| +|FIND VENV READING LOCATION AND OTHER INFO ABT VENV| +|==================================================| +which python +which pip + +python --version + +pip show psycopg2 +pip show psycopg2-binary + +pip freeze | grep psycopg + + + +deactivate + +source /home/george/Desktop/PROJECT26/psqlDB/venv/bin/activate \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..037c23c --- /dev/null +++ b/main.py @@ -0,0 +1,128 @@ +import os +import uvicorn +from dotenv import load_dotenv +from fastapi import FastAPI,Depends, Header, HTTPException, status +import psycopg2 +from jwt import ExpiredSignatureError, InvalidTokenError +import jwt +load_dotenv() +app = FastAPI() + +SECRET_KEY = os.getenv("SECRET_KEY") +ALGORITHM = os.getenv("ALGORITHM", "HS256") + + + + +def verify_token( + authorization: str = Header(None), +): + + if not authorization: + raise HTTPException( + status_code=status.HTTP_401_UNAUTHORIZED, + detail="Authorization header missing", + headers={ + "WWW-Authenticate": "Bearer" + }, + ) + + parts = authorization.split() + + if len(parts) != 2: + raise HTTPException( + status_code=status.HTTP_401_UNAUTHORIZED, + detail="Invalid Authorization header", + ) + + scheme = parts[0] + token = parts[1] + + if scheme.lower() != "bearer": + raise HTTPException( + status_code=status.HTTP_401_UNAUTHORIZED, + detail="Authorization scheme must be Bearer", + ) + + try: + + payload = jwt.decode( + token, + SECRET_KEY, + algorithms=[ALGORITHM], + ) + + return payload + + except ExpiredSignatureError: + + raise HTTPException( + status_code=status.HTTP_401_UNAUTHORIZED, + detail="Token expired", + ) + + except InvalidTokenError: + + raise HTTPException( + status_code=status.HTTP_401_UNAUTHORIZED, + detail="Invalid token", + ) + + + + + + +@app.get("/") +def root(): + return {"message": "PostgreSQL Agent is running"} + + + +if __name__ == "__main__": + host = os.getenv("HOST", "127.0.0.1") + port = int(os.getenv("PORT", 9000)) + + uvicorn.run( + "main:app", + host=host, + port=port, + reload=True + ) + + + +DB_CONFIG = { + "host": "172.16.10.178", + "port": 5444, + "dbname": "postgres", + "user": "postgres", + "password": "postgres", + "connect_timeout": 3, +} + +NODE_NAME = "node3" + + +@app.get("/node/status") +def node_status(token_data=Depends(verify_token)): + + try: + conn = psycopg2.connect(**DB_CONFIG) + + conn.close() + + return { + "node": NODE_NAME, + "online": True, + "status": "online" + } + + except Exception as e: + + return { + "node": NODE_NAME, + "online": False, + "status": "offline", + "error": str(e) + } \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..968d729 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,14 @@ +annotated-doc==0.0.5 +annotated-types==0.8.0 +anyio==4.15.1 +click==8.5.0 +fastapi==0.141.1 +h11==0.16.0 +idna==3.19 +pydantic==2.13.5 +pydantic_core==2.46.5 +python-dotenv==1.2.3 +starlette==1.6.0 +typing-inspection==0.4.4 +typing_extensions==4.16.0 +uvicorn==0.53.0