diff --git a/src/main/java/org/jitsi/jicofo/Bridge.java b/src/main/java/org/jitsi/jicofo/Bridge.java index 4a038a0a16..da98208799 100644 --- a/src/main/java/org/jitsi/jicofo/Bridge.java +++ b/src/main/java/org/jitsi/jicofo/Bridge.java @@ -51,6 +51,24 @@ class Bridge */ private static final String STAT_NAME_VIDEO_STREAMS = "videostreams"; + /** + * The name of the stat used by jitsi-videobridge to indicate the current + * upload bitrate in Kbps. + * video streams. This should match + * {@code VideobridgeStatistics.BITRATE_UPLOAD}, but is defined separately + * to avoid depending on the {@code jitsi-videobridge} maven package. + */ + private static final String STAT_NAME_BITRATE_UP = "bit_rate_upload"; + + /** + * The name of the stat used by jitsi-videobridge to indicate the current + * download bitrate in Kbps. + * video streams. This should match + * {@code VideobridgeStatistics.BITRATE_DOWNLOAD}, but is defined separately + * to avoid depending on the {@code jitsi-videobridge} maven package. + */ + private static final String STAT_NAME_BITRATE_DOWN = "bit_rate_download"; + /** * The name of the stat used by jitsi-videobridge to indicate its region. * This should match {@code VideobridgeStatistics.REGION}, but is defined @@ -101,6 +119,11 @@ class Bridge */ private int videoStreamCountDiff = 0; + /** + * The last reported bitrate in Kbps. + */ + private int lastReportedBitrateKbps = 0; + /** * Holds bridge version (if known - not all bridge version are capable of * reporting it). @@ -154,6 +177,13 @@ void setStats(ColibriStatsExtension stats) setVideoStreamCount(videoStreamCount); } + Integer bitrateUpKbps = stats.getValueAsInt(STAT_NAME_BITRATE_UP); + Integer bitrateDownKbps = stats.getValueAsInt(STAT_NAME_BITRATE_DOWN); + if (bitrateUpKbps != null && bitrateDownKbps != null) + { + lastReportedBitrateKbps = bitrateDownKbps + bitrateUpKbps; + } + setIsOperational(!Boolean.valueOf(stats.getValueAsString( JigasiDetector.STAT_NAME_SHUTDOWN_IN_PROGRESS))); } @@ -249,7 +279,8 @@ private void verifyFailureThreshold() } /** - * The least value is returned the least the bridge is loaded. + * The least value is returned the least the bridge is loaded. Currently + * we use the bitrate to estimate load. *

* {@inheritDoc} */ @@ -268,8 +299,7 @@ else if (!meOperational && otherOperational) return 1; } - return this.getEstimatedVideoStreamCount() - - o.getEstimatedVideoStreamCount(); + return this.lastReportedBitrateKbps - o.lastReportedBitrateKbps; } private int getEstimatedVideoStreamCount() diff --git a/src/test/java/org/jitsi/jicofo/BridgeSelectorTest.java b/src/test/java/org/jitsi/jicofo/BridgeSelectorTest.java index 5b44baa9b9..b48a2fb8d4 100644 --- a/src/test/java/org/jitsi/jicofo/BridgeSelectorTest.java +++ b/src/test/java/org/jitsi/jicofo/BridgeSelectorTest.java @@ -295,13 +295,16 @@ private void testFailureResetThreshold( BridgeSelector.DEFAULT_FAILURE_RESET_THRESHOLD); } - ExtensionElement createJvbStats(int videoStreamCount) + ExtensionElement createJvbStats(int bitrate) { ColibriStatsExtension statsExtension = new ColibriStatsExtension(); statsExtension.addStat( new ColibriStatsExtension.Stat( - VideobridgeStatistics.VIDEOSTREAMS, "" + videoStreamCount)); + VideobridgeStatistics.BITRATE_DOWNLOAD, bitrate)); + statsExtension.addStat( + new ColibriStatsExtension.Stat( + VideobridgeStatistics.BITRATE_UPLOAD, bitrate)); return statsExtension; }