-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkamon-test2.sc
71 lines (45 loc) · 1.82 KB
/
kamon-test2.sc
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
68
69
70
71
import $ivy.`io.kamon::kamon-core:2.1.0`
import $ivy.`io.kamon::kamon-prometheus:2.1.0`
// import $ivy.`io.kamon::kamon-system-metrics:2.0.1`
import $ivy.`com.typesafe:config:1.3.1`
import scala.collection.JavaConverters._
import com.typesafe.config.{Config, ConfigFactory, ConfigParseOptions}
import kamon.Kamon
import kamon.prometheus.PrometheusReporter
def parseOption(): ConfigParseOptions = {
val classloader = Thread.currentThread().getContextClassLoader
if (classloader eq null) throw new RuntimeException("No ClassLoader for current thread")
ConfigParseOptions.defaults()
.setClassLoader(classloader)
}
val options: ConfigParseOptions = parseOption()
val defaultConfig = ConfigFactory.load("kamon")
def parseString(input: String): Config = ConfigFactory.parseString(input, options).resolve().withFallback(defaultConfig)
val configText = """
kamon {
metric.tick-interval = 10 seconds
modules.prometheus-reporter.enabled = false
prometheus.start-embedded-http-server = false
system-metrics {
#sigar is enabled by default
sigar-enabled = true
#jmx related metrics are enabled by default
jmx-enabled = true
}
}
"""
val config = parseString(configText)
Kamon.init(config)
val reporter = new PrometheusReporter
Kamon.registerModule("PrometheusReporter", reporter)
val counter = Kamon.counter("default-value").withoutTags()
counter.increment(11)
val time = 10
(0 to time).map{ i =>
Thread.sleep(1010)
// println(s"setting ${Kamon.status().settings()}")
// println(s"status ${Kamon.status().moduleRegistry()} ${Kamon.status().metricRegistry()} ${Kamon.status().instrumentation()}")
println(s"$i ${reporter.scrapeData()}")
counter.increment()
i
}