mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-06-25 06:21:58 +00:00
parent
47d0882090
commit
fb1978a40b
@ -53,7 +53,7 @@ class Status(models.Model):
|
|||||||
|
|
||||||
def save(self, force_insert=False, force_update=False, using=None,
|
def save(self, force_insert=False, force_update=False, using=None,
|
||||||
update_fields=None):
|
update_fields=None):
|
||||||
self.terminal.set_alive(ttl=120)
|
self.terminal.set_alive(ttl=60 * 3)
|
||||||
return self.save_to_cache()
|
return self.save_to_cache()
|
||||||
|
|
||||||
def save_to_cache(self):
|
def save_to_cache(self):
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import time
|
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.db import models
|
from django.db import models
|
||||||
@ -11,6 +9,7 @@ from common.utils import get_logger, lazyproperty
|
|||||||
from orgs.utils import tmp_to_root_org
|
from orgs.utils import tmp_to_root_org
|
||||||
from terminal.const import TerminalType as TypeChoices
|
from terminal.const import TerminalType as TypeChoices
|
||||||
from users.models import User
|
from users.models import User
|
||||||
|
from .status import Status
|
||||||
from ..session import Session
|
from ..session import Session
|
||||||
|
|
||||||
logger = get_logger(__file__)
|
logger = get_logger(__file__)
|
||||||
@ -23,7 +22,7 @@ class TerminalStatusMixin:
|
|||||||
|
|
||||||
@lazyproperty
|
@lazyproperty
|
||||||
def last_stat(self):
|
def last_stat(self):
|
||||||
return self.status_set.order_by('date_created').last()
|
return Status.get_terminal_latest_stat(self)
|
||||||
|
|
||||||
@lazyproperty
|
@lazyproperty
|
||||||
def load(self):
|
def load(self):
|
||||||
@ -32,11 +31,10 @@ class TerminalStatusMixin:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def is_alive(self):
|
def is_alive(self):
|
||||||
if not self.last_stat:
|
key = self.ALIVE_KEY.format(self.id)
|
||||||
return False
|
return cache.get(key, False)
|
||||||
return time.time() - self.last_stat.date_created.timestamp() < 150
|
|
||||||
|
|
||||||
def set_alive(self, ttl=120):
|
def set_alive(self, ttl=60 * 3):
|
||||||
key = self.ALIVE_KEY.format(self.id)
|
key = self.ALIVE_KEY.format(self.id)
|
||||||
cache.set(key, True, ttl)
|
cache.set(key, True, ttl)
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
import time
|
|
||||||
from itertools import groupby
|
from itertools import groupby
|
||||||
|
|
||||||
from common.utils import get_logger
|
from common.utils import get_logger
|
||||||
@ -40,7 +39,7 @@ class ComputeLoadUtil:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def compute_load(cls, stat):
|
def compute_load(cls, stat):
|
||||||
if not stat or time.time() - stat.date_created.timestamp() > 150:
|
if not stat:
|
||||||
return ComponentLoad.offline
|
return ComponentLoad.offline
|
||||||
system_status_values = cls._compute_system_stat_status(stat).values()
|
system_status_values = cls._compute_system_stat_status(stat).values()
|
||||||
if ComponentLoad.critical in system_status_values:
|
if ComponentLoad.critical in system_status_values:
|
||||||
|
Loading…
Reference in New Issue
Block a user