Skip to content

Commit 36dc201

Browse files
authored
ref: Refactor statistics code and json format. (#452)
* stats: Removes unnecessary levels from the stats json. * ref: Migrate stats to getStats().
1 parent 4b47d13 commit 36dc201

File tree

8 files changed

+105
-263
lines changed

8 files changed

+105
-263
lines changed

src/main/java/org/jitsi/jicofo/FocusManager.java

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ public int getConferenceCount()
704704
return conferences.size();
705705
}
706706

707-
public int getNonHealthCheckConferenceCount()
707+
private int getNonHealthCheckConferenceCount()
708708
{
709709
return (int)conferences.values().stream()
710710
.filter(JitsiMeetConferenceImpl::includeInStatistics)
@@ -740,11 +740,54 @@ public JitsiMeetServices getJitsiMeetServices()
740740

741741
public JSONObject getStats()
742742
{
743-
JSONObject json = new JSONObject();
743+
// We want to avoid exposing unnecessary hierarchy levels in the stats,
744+
// so we'll merge stats from different "child" objects here.
745+
JSONObject stats = jitsiMeetServices.getStats();
746+
stats.put("total_participants", statistics.totalParticipants.get());
747+
stats.put("total_conferences_created", statistics.totalConferencesCreated.get());
748+
stats.put("conferences", getNonHealthCheckConferenceCount());
749+
750+
// Calculate the number of participants and conference size distribution
751+
int numParticipants = 0;
752+
int largestConferenceSize = 0;
753+
int[] conferenceSizes = new int[22];
754+
for (JitsiMeetConference conference : getConferences())
755+
{
756+
if (!conference.includeInStatistics())
757+
{
758+
continue;
759+
}
760+
int confSize = conference.getParticipantCount();
761+
// getParticipantCount only includes endpoints with allocated media
762+
// channels, so if a single participant is waiting in a meeting
763+
// they wouldn't be counted. In stats, calling this a conference
764+
// with size 0 would be misleading, so we add 1 in this case to
765+
// properly show it as a conference of size 1. (If there really
766+
// weren't any participants in there at all, the conference
767+
// wouldn't have existed in the first place).
768+
if (confSize == 0)
769+
{
770+
confSize = 1;
771+
}
772+
numParticipants += confSize;
773+
largestConferenceSize = Math.max(largestConferenceSize, confSize);
744774

745-
json.put("services", jitsiMeetServices.getStats());
775+
int conferenceSizeIndex = confSize < conferenceSizes.length
776+
? confSize
777+
: conferenceSizes.length - 1;
778+
conferenceSizes[conferenceSizeIndex]++;
779+
}
780+
781+
stats.put("largest_conference", largestConferenceSize);
782+
stats.put("participants", numParticipants);
783+
JSONArray conferenceSizesJson = new JSONArray();
784+
for (int size : conferenceSizes)
785+
{
786+
conferenceSizesJson.add(size);
787+
}
788+
stats.put("conference_sizes", conferenceSizesJson);
746789

747-
return json;
790+
return stats;
748791
}
749792

750793
/**

src/main/java/org/jitsi/jicofo/JitsiMeetServices.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,23 @@ public JSONObject getStats()
466466
JSONObject json = new JSONObject();
467467

468468
json.put("bridge_selector", bridgeSelector.getStats());
469+
JigasiDetector jigasiDetector = getJigasiDetector();
470+
if (jigasiDetector != null)
471+
{
472+
json.put("jigasi_detector", jigasiDetector.getStats());
473+
}
474+
475+
JibriDetector jibriDetector = getJibriDetector();
476+
if (jibriDetector != null)
477+
{
478+
json.put("jibri_detector", jibriDetector.getStats());
479+
}
480+
481+
JibriDetector sipJibriDetector = getSipJibriDetector();
482+
if (sipJibriDetector != null)
483+
{
484+
json.put("sip_jibri_detector", sipJibriDetector.getStats());
485+
}
469486

470487
return json;
471488
}

src/main/java/org/jitsi/jicofo/bridge/BridgeSelector.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -753,10 +753,12 @@ public int getOperationalBridgeCount()
753753

754754
public JSONObject getStats()
755755
{
756-
JSONObject json = new JSONObject();
756+
// We want to avoid exposing unnecessary hierarchy levels in the stats,
757+
// so we'll merge stats from different "child" objects here.
758+
JSONObject stats = bridgeSelectionStrategy.getStats();
759+
stats.put("bridge_count", getBridgeCount());
760+
stats.put("operational_bridge_count", getOperationalBridgeCount());
757761

758-
json.put("strategy", bridgeSelectionStrategy.getStats());
759-
760-
return json;
762+
return stats;
761763
}
762764
}

src/main/java/org/jitsi/jicofo/jigasi/JigasiDetector.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import org.jitsi.jicofo.*;
2424
import org.jitsi.jicofo.xmpp.*;
25+
import org.json.simple.*;
2526
import org.jxmpp.jid.*;
2627

2728
import java.util.*;
@@ -350,4 +351,13 @@ public int getJigasiTranscriberCount()
350351
{
351352
return (int) instances.stream().filter(i -> supportTranscription(i)).count();
352353
}
354+
355+
public JSONObject getStats()
356+
{
357+
JSONObject stats = new JSONObject();
358+
stats.put("sip_count", getJigasiSipCount());
359+
stats.put("transcriber_count", getJigasiTranscriberCount());
360+
361+
return stats;
362+
}
353363
}

src/main/java/org/jitsi/jicofo/recording/jibri/JibriDetector.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.jitsi.jicofo.*;
2525
import org.jitsi.jicofo.xmpp.*;
2626
import org.jitsi.osgi.*;
27+
import org.json.simple.*;
2728
import org.jxmpp.jid.*;
2829

2930
/**
@@ -186,4 +187,11 @@ private void notifyJibriStatus(Jid jibriJid, boolean available)
186187
logger.warn("No EventAdmin!");
187188
}
188189
}
190+
191+
public JSONObject getStats()
192+
{
193+
JSONObject stats = new JSONObject();
194+
stats.put("count", getInstanceCount());
195+
return stats;
196+
}
189197
}

src/main/java/org/jitsi/jicofo/recording/jibri/JibriStats.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.jitsi.eventadmin.*;
2020
import org.jitsi.osgi.*;
2121
import org.jitsi.utils.logging.*;
22+
import org.json.simple.*;
2223
import org.osgi.framework.*;
2324

2425
/**
@@ -130,4 +131,14 @@ public int getTotalRecordingFailures()
130131
{
131132
return totalRecordingFailures;
132133
}
134+
135+
public JSONObject getStats()
136+
{
137+
JSONObject stats = new JSONObject();
138+
stats.put("total_live_streaming_failures", getTotalLiveStreamingFailures());
139+
stats.put("total_recording_failures", getTotalRecordingFailures());
140+
stats.put("total_sip_call_failures", getTotalSipCallFailures());
141+
142+
return stats;
143+
}
133144
}

src/main/java/org/jitsi/jicofo/rest/Statistics.java

Lines changed: 6 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -15,70 +15,19 @@
1515
*/
1616
package org.jitsi.jicofo.rest;
1717

18-
import org.jitsi.jicofo.*;
19-
import org.jitsi.jicofo.recording.jibri.*;
20-
import org.jitsi.jicofo.stats.*;
2118
import org.jitsi.jicofo.util.*;
2219
import org.json.simple.*;
2320

2421
import javax.inject.*;
2522
import javax.ws.rs.*;
2623
import javax.ws.rs.core.*;
2724

28-
import static org.jitsi.xmpp.extensions.colibri.ColibriStatsExtension.*;
29-
3025
/**
3126
* Adds statistics REST endpoint exposes some internal Jicofo stats.
3227
*/
3328
@Path("/stats")
3429
public class Statistics
3530
{
36-
/**
37-
* The current number of jitsi-videobridge instances.
38-
*/
39-
public static final String BREWERY_JVB_COUNT = "brewery_jvb_count";
40-
41-
/**
42-
* The current number of jitsi-videobridge instances that are operational
43-
* (not failed).
44-
*/
45-
public static final String BREWERY_JVB_OPERATIONAL_COUNT = "brewery_jvb_operational_count";
46-
47-
/**
48-
* The current number of jigasi instances that support SIP.
49-
*/
50-
public static final String BREWERY_JIGASI_SIP_COUNT = "brewery_jigasi_sip_count";
51-
52-
/**
53-
* The current number of jigasi instances that support transcription.
54-
*/
55-
public static final String BREWERY_JIGASI_TRANSCRIBER_COUNT = "brewery_jigasi_transcriber_count";
56-
57-
/**
58-
* The current number of jibri instances for streaming.
59-
*/
60-
public static final String BREWERY_JIBRI_COUNT = "brewery_jibri_count";
61-
62-
/**
63-
* The current number of jibri instances for SIP.
64-
*/
65-
public static final String BREWERY_JIBRI_SIP_COUNT = "brewery_jibri_sip_count";
66-
67-
/**
68-
* How many times the live streaming has failed to start so far.
69-
*/
70-
public static final String TOTAL_LIVE_STREAMING_FAILURES = "total_live_streaming_failures";
71-
72-
/**
73-
* How many times the recording has failed to start so far.
74-
*/
75-
public static final String TOTAL_RECORDING_FAILURES = "total_recording_failures";
76-
77-
/**
78-
* How many times a SIP call has failed to start so far.
79-
*/
80-
public static final String TOTAL_SIP_CALL_FAILURES = "total_sip_call_failures";
81-
8231
@Inject
8332
protected FocusManagerProvider focusManagerProvider;
8433

@@ -93,41 +42,13 @@ public class Statistics
9342
@Produces(MediaType.APPLICATION_JSON)
9443
public String getStats()
9544
{
96-
FocusManager focusManager = focusManagerProvider.get();
97-
JibriStats jibriStats = jibriStatsProvider.get();
98-
99-
JicofoStatisticsSnapshot snapshot
100-
= JicofoStatisticsSnapshot.generate(focusManager, jibriStats);
101-
JSONObject json = new JSONObject();
102-
json.put(CONFERENCES, snapshot.numConferences);
103-
json.put(LARGEST_CONFERENCE, snapshot.largestConferenceSize);
104-
json.put(TOTAL_CONFERENCES_CREATED, snapshot.totalConferencesCreated);
105-
json.put(PARTICIPANTS, snapshot.numParticipants);
106-
json.put(TOTAL_PARTICIPANTS, snapshot.totalNumParticipants);
107-
json.put(BREWERY_JVB_COUNT, snapshot.bridgeCount);
108-
json.put(BREWERY_JVB_OPERATIONAL_COUNT, snapshot.operationalBridgeCount);
109-
json.put(BREWERY_JIGASI_SIP_COUNT, snapshot.jigasiSipCount);
110-
json.put(BREWERY_JIGASI_TRANSCRIBER_COUNT, snapshot.jigasiTranscriberCount);
111-
json.put(BREWERY_JIBRI_COUNT, snapshot.jibriCount);
112-
json.put(BREWERY_JIBRI_SIP_COUNT, snapshot.sipJibriCount);
113-
json.put(TOTAL_LIVE_STREAMING_FAILURES, snapshot.totalLiveStreamingFailures);
114-
json.put(TOTAL_RECORDING_FAILURES, snapshot.totalRecordingFailures);
115-
json.put(TOTAL_SIP_CALL_FAILURES, snapshot.totalSipCallFailures);
116-
JSONArray conferenceSizesJson = new JSONArray();
117-
for (int size : snapshot.conferenceSizes)
118-
{
119-
conferenceSizesJson.add(size);
120-
}
121-
json.put(CONFERENCE_SIZES, conferenceSizesJson);
45+
JSONObject stats = new JSONObject();
12246

123-
// XXX we have this top-down approach of populating the stats in various
124-
// places in the bridge and thought to bring it over here. It'll bring
125-
// proper name spacing of the various stats, but we'll have to type a
126-
// bit more in dd to access said stats. For example the bridge selection
127-
// strategy stats will be available under
128-
// focus.services.selector.strategy.*
129-
json.put("focus", focusManager.getStats());
47+
// We want to avoid exposing unnecessary hierarchy levels in the stats,
48+
// so we merge the FocusManager and Jibri stats in the root object.
49+
stats.putAll(focusManagerProvider.get().getStats());
50+
stats.putAll(jibriStatsProvider.get().getStats());
13051

131-
return json.toJSONString();
52+
return stats.toJSONString();
13253
}
13354
}

0 commit comments

Comments
 (0)