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

pull/7214/head
Michael Bai 3 years ago committed by Jiangjie.Bai
parent 096b2cf8b8
commit dac45f234a

@ -55,8 +55,18 @@ class Status(models.Model):
stat = cls(**data) stat = cls(**data)
stat.terminal = terminal stat.terminal = terminal
stat.is_alive = terminal.is_alive stat.is_alive = terminal.is_alive
stat.keep_one_decimal_place()
return stat 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, 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=120)

Loading…
Cancel
Save