diff options
author | Alexey Noskov <alexey.noskov@gmail.com> | 2015-09-26 18:03:15 +0300 |
---|---|---|
committer | Alexey Noskov <alexey.noskov@gmail.com> | 2015-09-26 20:49:38 +0300 |
commit | c4b58f26f43f3767633d9c06c9a65d6549093e35 (patch) | |
tree | 661b573c77357acffb99881a34a3e547808c670b /kamon-system-metrics/src/main/scala/kamon/system | |
parent | 6e07de4432c587a10c2ee27a5289898c722d0078 (diff) | |
download | Kamon-c4b58f26f43f3767633d9c06c9a65d6549093e35.tar.gz Kamon-c4b58f26f43f3767633d9c06c9a65d6549093e35.tar.bz2 Kamon-c4b58f26f43f3767633d9c06c9a65d6549093e35.zip |
! system-metrics: Fix heap metrics update
Don't store reference to MemoryUsage object: it's immutable, instead store function extracting it from MemoryMXBean
Diffstat (limited to 'kamon-system-metrics/src/main/scala/kamon/system')
-rw-r--r-- | kamon-system-metrics/src/main/scala/kamon/system/jmx/MemoryUsageMetrics.scala | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/kamon-system-metrics/src/main/scala/kamon/system/jmx/MemoryUsageMetrics.scala b/kamon-system-metrics/src/main/scala/kamon/system/jmx/MemoryUsageMetrics.scala index ef9d47a6..41681459 100644 --- a/kamon-system-metrics/src/main/scala/kamon/system/jmx/MemoryUsageMetrics.scala +++ b/kamon-system-metrics/src/main/scala/kamon/system/jmx/MemoryUsageMetrics.scala @@ -32,13 +32,13 @@ import scala.collection.convert.WrapAsScala class MemoryUsageMetrics(instrumentFactory: InstrumentFactory, beansWithNames: Iterable[MemoryUsageWithMetricName]) extends GenericEntityRecorder(instrumentFactory) { beansWithNames.foreach { - case MemoryUsageWithMetricName(name, bean) ⇒ + case MemoryUsageWithMetricName(name, beanFun) ⇒ gauge(name + "-used", Memory.Bytes, () ⇒ { - bean.getUsed + beanFun().getUsed }) gauge(name + "-max", Memory.Bytes, () ⇒ { - val max = bean.getMax + val max = beanFun().getMax // .getMax can return -1 if the max is not defined. if (max >= 0) max @@ -46,7 +46,7 @@ class MemoryUsageMetrics(instrumentFactory: InstrumentFactory, }) gauge(name + "-committed", Memory.Bytes, () ⇒ { - bean.getCommitted + beanFun().getCommitted }) } } @@ -54,9 +54,9 @@ class MemoryUsageMetrics(instrumentFactory: InstrumentFactory, /** * Objects of this kind may be passed to instances of [[MemoryUsageMetrics]] for data collection. * @param metricName The sanitized name for a metric. - * @param bean The data source for metrics. + * @param beanFun Function returning the data source for metrics. */ -private[jmx] final case class MemoryUsageWithMetricName(metricName: String, bean: MemoryUsage) +private[jmx] final case class MemoryUsageWithMetricName(metricName: String, beanFun: () ⇒ MemoryUsage) /** * Memory Pool metrics, as reported by JMX: @@ -79,7 +79,7 @@ object MemoryUsageMetrics extends JmxSystemMetricRecorderCompanion("jmx-memory") def apply(instrumentFactory: InstrumentFactory): MemoryUsageMetrics = new MemoryUsageMetrics(instrumentFactory, - MemoryUsageWithMetricName("non-heap", memoryMXBean.getNonHeapMemoryUsage) :: - MemoryUsageWithMetricName("heap", memoryMXBean.getHeapMemoryUsage) :: + MemoryUsageWithMetricName("non-heap", () ⇒ memoryMXBean.getNonHeapMemoryUsage) :: + MemoryUsageWithMetricName("heap", () ⇒ memoryMXBean.getHeapMemoryUsage) :: usagesWithNames) } |