From dac45f234a60e34e29ad6f4795ad804277bebd0f Mon Sep 17 00:00:00 2001 From: Michael Bai Date: Wed, 17 Nov 2021 18:54:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BB=88=E7=AB=AF=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=8C=87=E6=A0=87=E6=95=B0=E5=80=BC=E4=BF=9D=E7=95=99=E4=B8=80?= =?UTF-8?q?=E4=BD=8D=E5=B0=8F=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/terminal/models/status.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/apps/terminal/models/status.py b/apps/terminal/models/status.py index cece6b5ce..bc195d857 100644 --- a/apps/terminal/models/status.py +++ b/apps/terminal/models/status.py @@ -55,8 +55,18 @@ class Status(models.Model): stat = cls(**data) stat.terminal = terminal stat.is_alive = terminal.is_alive + stat.keep_one_decimal_place() return stat + def keep_one_decimal_place(self): + keys = ['cpu_load', 'memory_used', 'disk_used'] + for key in keys: + value = getattr(self, key, 0) + if not isinstance(value, (int, float)): + continue + value = '%.1f' % value + setattr(self, key, float(value)) + def save(self, force_insert=False, force_update=False, using=None, update_fields=None): self.terminal.set_alive(ttl=120)