diff options
Diffstat (limited to 'kamon-system-metrics/src/main')
3 files changed, 30 insertions, 9 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) } diff --git a/kamon-system-metrics/src/main/scala/kamon/system/sigar/SigarMetricsUpdater.scala b/kamon-system-metrics/src/main/scala/kamon/system/sigar/SigarMetricsUpdater.scala index 69bc00ec..c0da6dc1 100644 --- a/kamon-system-metrics/src/main/scala/kamon/system/sigar/SigarMetricsUpdater.scala +++ b/kamon-system-metrics/src/main/scala/kamon/system/sigar/SigarMetricsUpdater.scala @@ -37,7 +37,8 @@ class SigarMetricsUpdater(refreshInterval: FiniteDuration) extends Actor { LoadAverageMetrics.register(sigar, metricsExtension, logger), MemoryMetrics.register(sigar, metricsExtension, logger), NetworkMetrics.register(sigar, metricsExtension, logger), - ProcessCpuMetrics.register(sigar, metricsExtension, logger)) + ProcessCpuMetrics.register(sigar, metricsExtension, logger), + ULimitMetrics.register(sigar, metricsExtension, logger)) val refreshSchedule = context.system.scheduler.schedule(refreshInterval, refreshInterval, self, UpdateSigarMetrics)(context.dispatcher) diff --git a/kamon-system-metrics/src/main/scala/kamon/system/sigar/ULimitMetrics.scala b/kamon-system-metrics/src/main/scala/kamon/system/sigar/ULimitMetrics.scala new file mode 100644 index 00000000..314c8450 --- /dev/null +++ b/kamon-system-metrics/src/main/scala/kamon/system/sigar/ULimitMetrics.scala @@ -0,0 +1,20 @@ +package kamon.system.sigar + +import akka.event.LoggingAdapter +import kamon.metric.GenericEntityRecorder +import kamon.metric.instrument.InstrumentFactory +import org.hyperic.sigar.Sigar + +class ULimitMetrics(sigar: Sigar, instrumentFactory: InstrumentFactory, logger: LoggingAdapter) extends GenericEntityRecorder(instrumentFactory) with SigarMetric { + val pid = sigar.getPid + val openFiles = histogram("open-files") + + def update(): Unit = { + openFiles.record(sigar.getProcFd(pid).getTotal) + } +} + +object ULimitMetrics extends SigarMetricRecorderCompanion("ulimit") { + def apply(sigar: Sigar, instrumentFactory: InstrumentFactory, logger: LoggingAdapter): ULimitMetrics = + new ULimitMetrics(sigar, instrumentFactory, logger) +}
\ No newline at end of file |