fix: 终端列表指标数值保留一位小数

pull/7214/head
Michael Bai 2021-11-17 18:54:32 +08:00 committed by Jiangjie.Bai
parent 096b2cf8b8
commit dac45f234a
1 changed files with 10 additions and 0 deletions

View File

@ -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)