@@ -20,6 +20,7 @@ package org.jitsi.jibri
20
20
import org.jitsi.jibri.config.Config
21
21
import org.jitsi.jibri.config.XmppCredentials
22
22
import org.jitsi.jibri.health.EnvironmentContext
23
+ import org.jitsi.jibri.metrics.JibriMetrics
23
24
import org.jitsi.jibri.selenium.CallParams
24
25
import org.jitsi.jibri.service.JibriService
25
26
import org.jitsi.jibri.service.JibriServiceStatusHandler
@@ -30,14 +31,6 @@ import org.jitsi.jibri.service.impl.SipGatewayJibriService
30
31
import org.jitsi.jibri.service.impl.SipGatewayServiceParams
31
32
import org.jitsi.jibri.service.impl.StreamingJibriService
32
33
import org.jitsi.jibri.service.impl.StreamingParams
33
- import org.jitsi.jibri.statsd.ASPECT_BUSY
34
- import org.jitsi.jibri.statsd.ASPECT_ERROR
35
- import org.jitsi.jibri.statsd.ASPECT_START
36
- import org.jitsi.jibri.statsd.ASPECT_STOP
37
- import org.jitsi.jibri.statsd.JibriStatsDClient
38
- import org.jitsi.jibri.statsd.TAG_SERVICE_LIVE_STREAM
39
- import org.jitsi.jibri.statsd.TAG_SERVICE_RECORDING
40
- import org.jitsi.jibri.statsd.TAG_SERVICE_SIP_GATEWAY
41
34
import org.jitsi.jibri.status.ComponentBusyStatus
42
35
import org.jitsi.jibri.status.ComponentHealthStatus
43
36
import org.jitsi.jibri.status.ComponentState
@@ -99,40 +92,23 @@ class JibriManager : StatusPublisher<Any>() {
99
92
private var pendingIdleFunc: () -> Unit = {}
100
93
private var serviceTimeoutTask: ScheduledFuture <* >? = null
101
94
102
- private val enableStatsD: Boolean by config {
103
- " JibriConfig::enableStatsD" { Config .legacyConfigSource.enabledStatsD!! }
104
- " jibri.stats.enable-stats-d" .from(Config .configSource)
105
- }
106
-
107
- private val statsdHost: String by config {
108
- " jibri.stats.host" .from(Config .configSource)
109
- }
110
-
111
- private val statsdPort: Int by config {
112
- " jibri.stats.port" .from(Config .configSource)
113
- }
114
-
115
95
private val singleUseMode: Boolean by config {
116
96
" JibriConfig::singleUseMode" { Config .legacyConfigSource.singleUseMode!! }
117
97
" jibri.single-use-mode" .from(Config .configSource)
118
98
}
119
99
120
- val statsDClient: JibriStatsDClient ? = if (enableStatsD) {
121
- JibriStatsDClient (statsdHost, statsdPort)
122
- } else {
123
- null
124
- }
100
+ val jibriMetrics = JibriMetrics ()
125
101
126
102
/* *
127
103
* Note: should only be called if the instance-wide lock is held (i.e. called from
128
104
* one of the synchronized methods)
129
105
* TODO: instead of the synchronized decorators, use a synchronized(this) block
130
106
* which we can also use here
131
107
*/
132
- private fun throwIfBusy () {
108
+ private fun throwIfBusy (sinkType : RecordingSinkType ) {
133
109
if (busy()) {
134
110
logger.info(" Jibri is busy, can't start service" )
135
- statsDClient?.incrementCounter( ASPECT_BUSY , TAG_SERVICE_RECORDING )
111
+ jibriMetrics.requestWhileBusy(sinkType )
136
112
throw JibriBusyException ()
137
113
}
138
114
}
@@ -148,7 +124,7 @@ class JibriManager : StatusPublisher<Any>() {
148
124
environmentContext : EnvironmentContext ? = null,
149
125
serviceStatusHandler : JibriServiceStatusHandler ? = null
150
126
) {
151
- throwIfBusy()
127
+ throwIfBusy(RecordingSinkType . FILE )
152
128
logger.info(" Starting a file recording with params: $fileRecordingRequestParams " )
153
129
val service = FileRecordingJibriService (
154
130
FileRecordingParams (
@@ -158,7 +134,7 @@ class JibriManager : StatusPublisher<Any>() {
158
134
serviceParams.appData?.fileRecordingMetadata
159
135
)
160
136
)
161
- statsDClient?.incrementCounter( ASPECT_START , TAG_SERVICE_RECORDING )
137
+ jibriMetrics.start( RecordingSinkType . FILE )
162
138
startService(service, serviceParams, environmentContext, serviceStatusHandler)
163
139
}
164
140
@@ -174,9 +150,9 @@ class JibriManager : StatusPublisher<Any>() {
174
150
serviceStatusHandler : JibriServiceStatusHandler ? = null
175
151
) {
176
152
logger.info(" Starting a stream with params: $serviceParams $streamingParams " )
177
- throwIfBusy()
153
+ throwIfBusy(RecordingSinkType . STREAM )
178
154
val service = StreamingJibriService (streamingParams)
179
- statsDClient?.incrementCounter( ASPECT_START , TAG_SERVICE_LIVE_STREAM )
155
+ jibriMetrics.start( RecordingSinkType . STREAM )
180
156
startService(service, serviceParams, environmentContext, serviceStatusHandler)
181
157
}
182
158
@@ -188,15 +164,15 @@ class JibriManager : StatusPublisher<Any>() {
188
164
serviceStatusHandler : JibriServiceStatusHandler ? = null
189
165
) {
190
166
logger.info(" Starting a SIP gateway with params: $serviceParams $sipGatewayServiceParams " )
191
- throwIfBusy()
167
+ throwIfBusy(RecordingSinkType . GATEWAY )
192
168
val service = SipGatewayJibriService (
193
169
SipGatewayServiceParams (
194
170
sipGatewayServiceParams.callParams,
195
171
sipGatewayServiceParams.callLoginParams,
196
172
sipGatewayServiceParams.sipClientParams
197
173
)
198
174
)
199
- statsDClient?.incrementCounter( ASPECT_START , TAG_SERVICE_SIP_GATEWAY )
175
+ jibriMetrics.start( RecordingSinkType . GATEWAY )
200
176
return startService(service, serviceParams, environmentContext, serviceStatusHandler)
201
177
}
202
178
@@ -219,7 +195,7 @@ class JibriManager : StatusPublisher<Any>() {
219
195
when (it) {
220
196
is ComponentState .Error -> {
221
197
if (it.error.scope == ErrorScope .SYSTEM ) {
222
- statsDClient?.incrementCounter( ASPECT_ERROR , JibriStatsDClient .getTagForService(jibriService ))
198
+ jibriMetrics.error(jibriService.getSinkType( ))
223
199
publishStatus(ComponentHealthStatus .UNHEALTHY )
224
200
}
225
201
stopService()
@@ -270,7 +246,7 @@ class JibriManager : StatusPublisher<Any>() {
270
246
logger.info(" No service active, ignoring stop" )
271
247
return
272
248
}
273
- statsDClient?.incrementCounter( ASPECT_STOP , JibriStatsDClient .getTagForService(currentService ))
249
+ jibriMetrics.stop(currentService.getSinkType( ))
274
250
logger.info(" Stopping the current service" )
275
251
serviceTimeoutTask?.cancel(false )
276
252
// Note that this will block until the service is completely stopped
@@ -309,3 +285,10 @@ class JibriManager : StatusPublisher<Any>() {
309
285
}
310
286
}
311
287
}
288
+
289
+ private fun JibriService.getSinkType () = when (this ) {
290
+ is FileRecordingJibriService -> RecordingSinkType .FILE
291
+ is StreamingJibriService -> RecordingSinkType .GATEWAY
292
+ is SipGatewayJibriService -> RecordingSinkType .GATEWAY
293
+ else -> throw IllegalArgumentException (" JibriService of unsupported type: ${JibriService ::class .java.name} " )
294
+ }
0 commit comments