Skip to content

Commit

Permalink
Create /stats route
Browse files Browse the repository at this point in the history
  • Loading branch information
BattlefieldDuck committed Mar 12, 2024
1 parent 4d87ba0 commit 9bba416
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
23 changes: 23 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,28 @@ def render_terms():
return html_content


@app.route("/stats")
def render_stats():
"""
Statistics Requests
---
tags:
- Statistics Endpoint
responses:
200:
description: Success
"""
db = MasterServer.get_db()

# Get a list of collection names in the database
collection_names = db.list_collection_names()

# Create a dictionary to store collection counts
collection_counts = {
name.lower(): db[name].count_documents({}) for name in collection_names}

return collection_counts


if __name__ == '__main__':
app.run(debug=True)
13 changes: 9 additions & 4 deletions protocols/MasterServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@
class MasterServer(ABC):
def __init__(self, key: str) -> None:
self._key = key
uri = os.getenv('DATABASE_URL')
self.client = MongoClient(uri)
self.db = self.client['MasterServer']
self.db = self.get_db()
self.collection = self.db[key]

@staticmethod
def get_db():
uri = os.getenv('DATABASE_URL')
client = MongoClient(uri)
db = client['MasterServer']
return db

@property
def key(self):
return self._key
Expand All @@ -29,7 +34,7 @@ def job(self):
pass

@abstractmethod
def find(self, *, host: str, port: int):
def find(self, *, host: str, port: int) -> dict:
pass

def run(self):
Expand Down

0 comments on commit 9bba416

Please sign in to comment.