aboutsummaryrefslogtreecommitdiff
path: root/kamon-core/src/main/scala/kamon/metric/Histogram.scala
diff options
context:
space:
mode:
authorIvan Topolnjak <ivantopo@gmail.com>2017-06-11 10:02:22 +0200
committerIvan Topolnjak <ivantopo@gmail.com>2017-06-11 10:02:22 +0200
commite8d3e612dcf0fa396a25920a23f108f6ab8c2e61 (patch)
treee1d702aa2eabbfabc9690a5cdc3ca6ac59ae69b9 /kamon-core/src/main/scala/kamon/metric/Histogram.scala
parentde3e823cec6ec12d551f568b73d2ad1061944222 (diff)
downloadKamon-e8d3e612dcf0fa396a25920a23f108f6ab8c2e61.tar.gz
Kamon-e8d3e612dcf0fa396a25920a23f108f6ab8c2e61.tar.bz2
Kamon-e8d3e612dcf0fa396a25920a23f108f6ab8c2e61.zip
separate metrics from instruments and add default instrument for metrics
Diffstat (limited to 'kamon-core/src/main/scala/kamon/metric/Histogram.scala')
-rw-r--r--kamon-core/src/main/scala/kamon/metric/Histogram.scala21
1 files changed, 12 insertions, 9 deletions
diff --git a/kamon-core/src/main/scala/kamon/metric/Histogram.scala b/kamon-core/src/main/scala/kamon/metric/Histogram.scala
index 12111b83..1af55479 100644
--- a/kamon-core/src/main/scala/kamon/metric/Histogram.scala
+++ b/kamon-core/src/main/scala/kamon/metric/Histogram.scala
@@ -13,25 +13,26 @@
* =========================================================================================
*/
-package kamon.metric
+package kamon
+package metric
import java.nio.ByteBuffer
-import com.typesafe.scalalogging.StrictLogging
import kamon.util.MeasurementUnit
import org.HdrHistogram.{AtomicHistogramExtension, ZigZag}
+import org.slf4j.LoggerFactory
trait Histogram {
+ def unit: MeasurementUnit
def dynamicRange: DynamicRange
- def measurementUnit: MeasurementUnit
def record(value: Long): Unit
def record(value: Long, times: Long): Unit
}
-class HdrHistogram(name: String, tags: Map[String, String], val measurementUnit: MeasurementUnit, val dynamicRange: DynamicRange)
- extends AtomicHistogramExtension(dynamicRange) with SnapshotableHistogram with StrictLogging {
+private[kamon] class HdrHistogram(name: String, tags: Map[String, String], val unit: MeasurementUnit, val dynamicRange: DynamicRange)
+ extends AtomicHistogramExtension(dynamicRange) with Histogram {
def record(value: Long): Unit =
tryRecord(value, 1)
@@ -44,12 +45,12 @@ class HdrHistogram(name: String, tags: Map[String, String], val measurementUnit:
recordValueWithCount(value, count)
} catch {
case anyException: Throwable ⇒
- logger.warn(s"Failed to store value [$value] in histogram [$name]. You might need to change " +
- "your dynamic range configuration for this instrument.", anyException)
+ HdrHistogram.logger.warn(s"Failed to store value [$value] in histogram [$name]. You might need to change " +
+ "your dynamic range configuration for this instrument.", anyException)
}
}
- override def snapshot(): MetricDistribution = {
+ def snapshot(): MetricDistribution = {
val buffer = HdrHistogram.tempSnapshotBuffer.get()
val counts = countsArray()
val countsLimit = counts.length()
@@ -95,7 +96,7 @@ class HdrHistogram(name: String, tags: Map[String, String], val measurementUnit:
val distribution = new ZigZagCountsDistribution(totalCount, minIndex, maxIndex, ByteBuffer.wrap(zigZagCounts),
protectedUnitMagnitude(), protectedSubBucketHalfCount(), protectedSubBucketHalfCountMagnitude())
- MetricDistribution(name, tags, measurementUnit, dynamicRange, distribution)
+ MetricDistribution(name, tags, unit, dynamicRange, distribution)
}
private class ZigZagCountsDistribution(val count: Long, minIndex: Int, maxIndex: Int, zigZagCounts: ByteBuffer,
@@ -199,6 +200,8 @@ class HdrHistogram(name: String, tags: Map[String, String], val measurementUnit:
}
object HdrHistogram {
+ private val logger = LoggerFactory.getLogger(classOf[HdrHistogram])
+
// TODO: move this to some object pool might be better, or at
private val tempSnapshotBuffer = new ThreadLocal[ByteBuffer] {
override def initialValue(): ByteBuffer = ByteBuffer.allocate(33792)