Skip to content

Commit 4ffed05

Browse files
yulin-lisrikanthccv
authored andcommitted
avoid ZeroDevisionError exception when swap memory is 0 (open-telemetry#1345)
* avoid devidedByZero exception when sawp memory is 0 * lint Co-authored-by: Srikanth Chekuri <[email protected]>
1 parent e8676c1 commit 4ffed05

File tree

1 file changed

+3
-1
lines changed
  • instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics

1 file changed

+3
-1
lines changed

instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,9 @@ def _get_system_swap_utilization(
420420
if hasattr(system_swap, metric):
421421
self._system_swap_utilization_labels["state"] = metric
422422
yield Observation(
423-
getattr(system_swap, metric) / system_swap.total,
423+
getattr(system_swap, metric) / system_swap.total
424+
if system_swap.total
425+
else 0,
424426
self._system_swap_utilization_labels.copy(),
425427
)
426428

0 commit comments

Comments
 (0)