vpsFree.cz


by snajpa

April 5, 2020, 7:09 p.m. , updated April 5, 2020, 7:10 p.m.

Minimize, Download, Raw, Embed


root@jitsi-videobridge3:~# cat /opt/jitsi-stats.rb 
#!/usr/bin/env ruby
require 'net/http'
require 'json'

json = Net::HTTP.get(URI('http://localhost:8080/colibri/stats;'))
data = JSON.parse(json)

def yoval(v)
  case v
  when true, false
    v ? 0 : 1
  when Array
    raise ArgumentError, 'array not supported'
  when String
    raise ArgumentError, 'string not supported'
  else
    v
  end
end

into_file = ARGV.length > 0

dst =
  if into_file
    File.open("#{ARGV[0]}.new", 'w')
  else
    STDOUT
  end

data.each do |k, v|
  begin
    param = "jitsi_meet_#{k}"
    value = yoval(v)
  rescue ArgumentError
    next
  end

  dst.puts("# TYPE #{param} gauge")
  dst.puts("#{param} #{value}")
end

if into_file
  dst.close
  File.rename("#{ARGV[0]}.new", ARGV[0])
end
root@jitsi-videobridge3:~# cat /etc/systemd/system/jitsi-stats-collector.service
[Unit]
Description=Collect Jitsi Meet Stats

[Service]
Type=oneshot
ExecStart=/opt/jitsi-stats.rb /var/lib/prometheus/node-exporter/jitsi-meet-stats.prom

root@jitsi-videobridge3:~# cat /etc/systemd/system/jitsi-stats-collector.timer
[Unit]
Description=Collect Jitsi Meet Stats

[Timer]
OnUnitActiveSec=30s
OnBootSec=30s

[Install]
WantedBy=timers.target

root@jitsi-videobridge3:~# apt install ruby prometheus-node-exporter
root@jitsi-videobridge3:~# systemctl enable jitsi-stats-collector.timer
root@jitsi-videobridge3:~# systemctl enable prometheus-node-exporter.service
root@jitsi-videobridge3:~# systemctl start prometheus-node-exporter.service