avoid ZeroDevisionError exception when swap memory is 0 (#1345)

* avoid devidedByZero exception when sawp memory is 0

* lint

Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
This commit is contained in:
Yulin Li
2022-09-28 02:11:32 +08:00
committed by GitHub
parent fc98f0832e
commit 9d8228f82f

View File

@ -420,7 +420,9 @@ class SystemMetricsInstrumentor(BaseInstrumentor):
if hasattr(system_swap, metric):
self._system_swap_utilization_labels["state"] = metric
yield Observation(
getattr(system_swap, metric) / system_swap.total,
getattr(system_swap, metric) / system_swap.total
if system_swap.total
else 0,
self._system_swap_utilization_labels.copy(),
)