Skip to content

Commit 697a326

Browse files
authored
Fix crash in memory metric calculations (#257)
1 parent d40ff60 commit 697a326

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

newrelic/samplers/memory_usage.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727

2828
@data_source_generator(name="Memory Usage")
2929
def memory_usage_data_source():
30-
yield ("Memory/Physical", physical_memory_used())
31-
yield ("Memory/Physical/%d" % (PID), physical_memory_used())
32-
33-
yield (
34-
"Memory/Physical/Utilization",
35-
physical_memory_used() / total_physical_memory(),
36-
)
37-
yield (
38-
"Memory/Physical/Utilization/%d" % (PID),
39-
physical_memory_used() / total_physical_memory(),
30+
memory = physical_memory_used()
31+
total_memory = total_physical_memory()
32+
memory_utilization = (
33+
(memory / total_memory) if None not in (memory, total_memory) else None
4034
)
35+
36+
yield ("Memory/Physical", memory)
37+
yield ("Memory/Physical/%d" % (PID), memory)
38+
39+
yield ("Memory/Physical/Utilization", memory_utilization)
40+
yield ("Memory/Physical/Utilization/%d" % (PID), memory_utilization)

0 commit comments

Comments
 (0)