1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
package kamon.metric.instrument
import java.util.concurrent.TimeUnit
import com.typesafe.config.Config
import kamon.metric.instrument.Histogram.DynamicRange
import scala.concurrent.duration.FiniteDuration
case class InstrumentCustomSettings(lowestDiscernibleValue: Option[Long], highestTrackableValue: Option[Long],
precision: Option[Int], refreshInterval: Option[FiniteDuration]) {
def combine(that: InstrumentSettings): InstrumentSettings =
InstrumentSettings(
DynamicRange(
lowestDiscernibleValue.getOrElse(that.dynamicRange.lowestDiscernibleValue),
highestTrackableValue.getOrElse(that.dynamicRange.highestTrackableValue),
precision.getOrElse(that.dynamicRange.precision)),
refreshInterval.orElse(that.refreshInterval))
}
object InstrumentCustomSettings {
import scala.concurrent.duration._
def fromConfig(config: Config): InstrumentCustomSettings =
InstrumentCustomSettings(
if (config.hasPath("lowest-discernible-value")) Some(config.getLong("lowest-discernible-value")) else None,
if (config.hasPath("highest-trackable-value")) Some(config.getLong("highest-trackable-value")) else None,
if (config.hasPath("precision")) Some(InstrumentSettings.parsePrecision(config.getString("precision"))) else None,
if (config.hasPath("refresh-interval")) Some(config.getDuration("refresh-interval", TimeUnit.NANOSECONDS).nanos) else None)
}
case class InstrumentSettings(dynamicRange: DynamicRange, refreshInterval: Option[FiniteDuration])
object InstrumentSettings {
def readDynamicRange(config: Config): DynamicRange =
DynamicRange(
config.getLong("lowest-discernible-value"),
config.getLong("highest-trackable-value"),
parsePrecision(config.getString("precision")))
def parsePrecision(stringValue: String): Int = stringValue match {
case "low" ⇒ 1
case "normal" ⇒ 2
case "fine" ⇒ 3
case other ⇒ sys.error(s"Invalid precision configuration [$other] found, valid options are: [low|normal|fine].")
}
}
case class DefaultInstrumentSettings(histogram: InstrumentSettings, minMaxCounter: InstrumentSettings, gauge: InstrumentSettings)
object DefaultInstrumentSettings {
def fromConfig(config: Config): DefaultInstrumentSettings = {
import scala.concurrent.duration._
val histogramSettings = InstrumentSettings(InstrumentSettings.readDynamicRange(config.getConfig("histogram")), None)
val minMaxCounterSettings = InstrumentSettings(InstrumentSettings.readDynamicRange(config.getConfig("min-max-counter")),
Some(config.getDuration("min-max-counter.refresh-interval", TimeUnit.NANOSECONDS).nanos))
val gaugeSettings = InstrumentSettings(InstrumentSettings.readDynamicRange(config.getConfig("gauge")),
Some(config.getDuration("gauge.refresh-interval", TimeUnit.NANOSECONDS).nanos))
DefaultInstrumentSettings(histogramSettings, minMaxCounterSettings, gaugeSettings)
}
}
|