aboutsummaryrefslogtreecommitdiff
path: root/kamon-core/src/main/scala/kamon/standalone/KamonStandalone.scala
blob: 490bc127145271872e8fc6b2db42df1b4d17ec29 (plain) (blame)
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
package kamon.standalone

import akka.actor.ActorSystem
import com.typesafe.config.Config
import kamon.Kamon
import kamon.metric.UserMetrics
import kamon.metric.instrument.{ Gauge, MinMaxCounter, Counter, Histogram }

import scala.concurrent.duration.FiniteDuration

trait KamonStandalone {
  private[kamon] def system: ActorSystem

  def registerHistogram(name: String, precision: Histogram.Precision, highestTrackableValue: Long): Histogram =
    Kamon(UserMetrics)(system).registerHistogram(name, precision, highestTrackableValue)

  def registerHistogram(name: String): Histogram =
    Kamon(UserMetrics)(system).registerHistogram(name)

  def registerCounter(name: String): Counter =
    Kamon(UserMetrics)(system).registerCounter(name)

  def registerMinMaxCounter(name: String, precision: Histogram.Precision, highestTrackableValue: Long,
    refreshInterval: FiniteDuration): MinMaxCounter =
    Kamon(UserMetrics)(system).registerMinMaxCounter(name, precision, highestTrackableValue, refreshInterval)

  def registerMinMaxCounter(name: String): MinMaxCounter =
    Kamon(UserMetrics)(system).registerMinMaxCounter(name)

  def registerGauge(name: String)(currentValueCollector: Gauge.CurrentValueCollector): Gauge =
    Kamon(UserMetrics)(system).registerGauge(name)(currentValueCollector)

  def registerGauge(name: String, precision: Histogram.Precision, highestTrackableValue: Long,
    refreshInterval: FiniteDuration)(currentValueCollector: Gauge.CurrentValueCollector): Gauge =
    Kamon(UserMetrics)(system).registerGauge(name, precision, highestTrackableValue, refreshInterval)(currentValueCollector)

  def removeHistogram(name: String): Unit =
    Kamon(UserMetrics)(system).removeHistogram(name)

  def removeCounter(name: String): Unit =
    Kamon(UserMetrics)(system).removeCounter(name)

  def removeMinMaxCounter(name: String): Unit =
    Kamon(UserMetrics)(system).removeMinMaxCounter(name)

  def removeGauge(name: String): Unit =
    Kamon(UserMetrics)(system).removeGauge(name)
}

object KamonStandalone {

  def buildFromConfig(config: Config): KamonStandalone = buildFromConfig(config, "kamon-standalone")

  def buildFromConfig(config: Config, actorSystemName: String): KamonStandalone = new KamonStandalone {
    val system: ActorSystem = ActorSystem(actorSystemName, config)
  }
}

object EmbeddedKamonStandalone extends KamonStandalone {
  private[kamon] lazy val system = ActorSystem("kamon-standalone")
}