blob: 6f382a85fa997bcf7c5d0f982ca0ce442ac84e66 (
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
import com.typesafe.config.Config
import kamon.status.{StatusPageServer, Status}
trait StatusPage { self: Configuration with ClassLoading with ModuleLoading with Configuration =>
@volatile private var _statusPageServer: Option[StatusPageServer] = None
private val _status = new Status(self._moduleRegistry, self)
// Initial configuration and reconfigures
init(self.config())
self.onReconfigure(newConfig => self.init(newConfig))
/**
* Allows to access internal Kamon status for troubleshooting and displaying purposes. All information returned
* by the Status instance is a immutable snapshot of the current state of a given component.
*/
def status(): Status =
_status
private def init(config: Config): Unit = synchronized {
val isStatusPageEnabled = config.getBoolean("kamon.status.enabled")
if(isStatusPageEnabled) {
val hostname = config.getString("kamon.status.listen.hostname")
val port = config.getInt("kamon.status.listen.port")
_statusPageServer.fold {
// Starting a new server on the configured hostname/port
startServer(hostname, port, self.classLoader())
}(existentServer => {
// If the configuration has changed we will stop the previous version
// and start a new one with the new hostname/port.
if(existentServer.getHostname != hostname || existentServer.getListeningPort != port) {
stopServer()
startServer(hostname, port, self.classLoader())
}
})
} else {
_statusPageServer.foreach(_ => stopServer())
}
}
private def startServer(hostname: String, port: Int, resourceLoader: ClassLoader): Unit = {
val server = new StatusPageServer(hostname, port, resourceLoader, _status)
server.start()
_statusPageServer = Some(server)
}
private def stopServer(): Unit = {
_statusPageServer.foreach(_.stop())
_statusPageServer = None
}
}
|