Class: Bipbip::Plugin::JanusRtpbroadcast

Inherits:
Bipbip::Plugin show all
Defined in:
lib/bipbip/plugin/janus_rtpbroadcast.rb

Instance Attribute Summary

Attributes inherited from Bipbip::Plugin

#config, #frequency, #metric_group, #name, #tags

Instance Method Summary collapse

Methods inherited from Bipbip::Plugin

factory, factory_from_plugin, #initialize, #metrics_names, #run, #source_identifier

Methods included from InterruptibleSleep

#interrupt_sleep, #interruptible_sleep

Constructor Details

This class inherits a constructor from Bipbip::Plugin

Instance Method Details

#metrics_schemaObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/bipbip/plugin/janus_rtpbroadcast.rb', line 5

def metrics_schema
  [
    { name: 'mountpoint_count', type: 'gauge', unit: 'Mountpoints' },
    { name: 'stream_count', type: 'gauge', unit: 'Streams' },
    { name: 'streams_listener_count', type: 'gauge', unit: 'Listeners' },
    { name: 'streams_waiter_count', type: 'gauge', unit: 'Waiters' },
    { name: 'streams_bandwidth', type: 'gauge', unit: 'b/s' },
    { name: 'streams_zero_fps_count', type: 'gauge', unit: 'Streams' },
    { name: 'streams_zero_bitrate_count', type: 'gauge', unit: 'Streams' },
    { name: 'streams_packet_loss_audio_max', type: 'gauge', unit: '%' },
    { name: 'streams_packet_loss_audio_avg', type: 'gauge', unit: '%' },
    { name: 'streams_packet_loss_audio_count', type: 'counter', unit: 'Packets' },
    { name: 'streams_packet_loss_video_max', type: 'gauge', unit: '%' },
    { name: 'streams_packet_loss_video_avg', type: 'gauge', unit: '%' },
    { name: 'streams_packet_loss_video_count', type: 'counter', unit: 'Packets' }
  ]
end

#monitorObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/bipbip/plugin/janus_rtpbroadcast.rb', line 23

def monitor
  data = _fetch_data
  mountpoints = data['data']['list']
  streams = mountpoints.map { |mp| mp['streams'] }.flatten

  packet_loss_audio_avg = streams.count.nonzero? ? streams.map { |s| s['stats']['audio']['packet-loss-rate'] || 0 }.reduce(0, :+) / streams.count : 0
  packet_loss_video_avg = streams.count.nonzero? ? streams.map { |s| s['stats']['video']['packet-loss-rate'] || 0 }.reduce(0, :+) / streams.count : 0

  {
    'mountpoint_count' => mountpoints.count,
    'stream_count' => streams.count,
    'streams_listener_count' => streams.map { |s| s['webrtc-endpoint']['listeners'] }.reduce(0, :+),
    'streams_waiter_count' => streams.map { |s| s['webrtc-endpoint']['waiters'] }.reduce(0, :+),
    'streams_bandwidth' => streams.map { |s| (s['stats']['video']['bitrate'] || 0) + (s['stats']['audio']['bitrate'] || 0) }.reduce(0, :+),
    'streams_zero_fps_count' => streams.count { |s| (s['frame']['fps']).zero? },
    'streams_zero_bitrate_count' => streams.count { |s| s['stats']['video']['bitrate'].nil? || (s['stats']['video']['bitrate']).zero? },
    'streams_packet_loss_audio_max' => streams.map { |s| (s['stats']['audio']['packet-loss-rate'] || 0) * 100 }.max,
    'streams_packet_loss_audio_avg' => packet_loss_audio_avg * 100,
    'streams_packet_loss_audio_count' => streams.map { |s| (s['stats']['audio']['packet-loss-count'] || 0) }.reduce(0, :+),
    'streams_packet_loss_video_max' => streams.map { |s| (s['stats']['video']['packet-loss-rate'] || 0) * 100 }.max,
    'streams_packet_loss_video_avg' => packet_loss_video_avg * 100,
    'streams_packet_loss_video_count' => streams.map { |s| (s['stats']['video']['packet-loss-count'] || 0) }.reduce(0, :+)
  }
end