|
|
|
@ -3,7 +3,6 @@ import time
|
|
|
|
|
import socket |
|
|
|
|
import threading |
|
|
|
|
from django.conf import settings |
|
|
|
|
from django.db.utils import OperationalError |
|
|
|
|
|
|
|
|
|
from common.db.utils import close_old_connections |
|
|
|
|
from common.decorator import Singleton |
|
|
|
@ -45,6 +44,7 @@ class BaseTerminal(object):
|
|
|
|
|
|
|
|
|
|
def start_heartbeat(self): |
|
|
|
|
while True: |
|
|
|
|
try: |
|
|
|
|
heartbeat_data = { |
|
|
|
|
'cpu_load': get_cpu_load(), |
|
|
|
|
'memory_used': get_memory_usage(), |
|
|
|
@ -56,12 +56,11 @@ class BaseTerminal(object):
|
|
|
|
|
status_serializer.validated_data.pop('sessions', None) |
|
|
|
|
terminal = self.get_or_register_terminal() |
|
|
|
|
status_serializer.validated_data['terminal'] = terminal |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
status_serializer.save() |
|
|
|
|
time.sleep(self.interval) |
|
|
|
|
except OperationalError: |
|
|
|
|
except Exception: |
|
|
|
|
close_old_connections() |
|
|
|
|
finally: |
|
|
|
|
time.sleep(self.interval) |
|
|
|
|
|
|
|
|
|
def get_or_register_terminal(self): |
|
|
|
|
terminal = Terminal.objects.filter( |
|
|
|
|