local-llm-server/llm_server/routes/stats.py

36 lines
968 B
Python
Raw Normal View History

2023-08-21 23:48:06 -06:00
import time
2023-08-21 21:28:52 -06:00
from datetime import datetime
2023-08-21 23:48:06 -06:00
from threading import Semaphore, Thread
2023-08-21 21:28:52 -06:00
2023-08-22 00:26:46 -06:00
from llm_server.opts import concurrent_gens
2023-08-23 01:14:19 -06:00
from llm_server.routes.cache import redis
2023-08-21 21:28:52 -06:00
2023-08-22 23:01:09 -06:00
# proompters_1_min = 0
2023-08-22 00:26:46 -06:00
concurrent_semaphore = Semaphore(concurrent_gens)
2023-08-21 21:28:52 -06:00
start_time = datetime.now()
2023-08-21 23:48:06 -06:00
2023-08-23 01:14:19 -06:00
def get_count():
count = redis.get('proompts')
if count is None:
count = 0
else:
count = int(count)
return count
2023-08-21 23:48:06 -06:00
class SemaphoreCheckerThread(Thread):
2023-08-22 23:01:09 -06:00
proompters_1_min = 0
2023-08-22 23:37:39 -06:00
recent_prompters = {}
2023-08-22 23:01:09 -06:00
2023-08-23 20:33:49 -06:00
def __init__(self):
2023-08-21 23:48:06 -06:00
Thread.__init__(self)
self.daemon = True
def run(self):
while True:
2023-08-22 23:37:39 -06:00
current_time = time.time()
SemaphoreCheckerThread.recent_prompters = {ip: timestamp for ip, timestamp in SemaphoreCheckerThread.recent_prompters.items() if current_time - timestamp <= 60}
SemaphoreCheckerThread.proompters_1_min = len(SemaphoreCheckerThread.recent_prompters)
2023-08-21 23:48:06 -06:00
time.sleep(1)