diff --git a/x-pack/plugins/apm/server/routes/metrics/by_agent/shared/memory/index.ts b/x-pack/plugins/apm/server/routes/metrics/by_agent/shared/memory/index.ts index d0e84211ef455..714ac5cdf38d1 100644 --- a/x-pack/plugins/apm/server/routes/metrics/by_agent/shared/memory/index.ts +++ b/x-pack/plugins/apm/server/routes/metrics/by_agent/shared/memory/index.ts @@ -44,8 +44,16 @@ const chartBase: ChartBase = { }; export const percentSystemMemoryUsedScript = { - lang: 'expression', - source: `1 - doc['${METRIC_SYSTEM_FREE_MEMORY}'] / doc['${METRIC_SYSTEM_TOTAL_MEMORY}']`, + lang: 'painless', + source: ` + if(doc.containsKey('${METRIC_SYSTEM_FREE_MEMORY}') && doc.containsKey('${METRIC_SYSTEM_TOTAL_MEMORY}')){ + double freeMemoryValue = doc['${METRIC_SYSTEM_FREE_MEMORY}'].value; + double totalMemoryValue = doc['${METRIC_SYSTEM_TOTAL_MEMORY}'].value; + return 1 - freeMemoryValue / totalMemoryValue + } + + return null; + `, } as const; export const percentCgroupMemoryUsedScript = {