Developers Blog

Blog > News of the week - 20

on May 19, 2013

Listeners and Munin

After live updates, csv exports, the Tryphon Console provides a new mode to follow our stream(s) listeners count.

Indeed if you have a Munin instance on our infrastructure (who doesn’t ??), you can add a new plugin to monitor your streamings hosted by Tryphon.

After few hours, you will obtain this kind of graph :

If you have several streams on our platform, a total field is automatically added (like on this demo graph).

The munin data are returned directly by the Tryphon Console API. You just need to invoke the good URL :

# To retrieve collected values
$ curl "https://console.tryphon.eu/streams.munin?api_token=YOUR_API_KEY"
my-first-stream.value 19
my-second-stream.value 12
total.value 31

# To retrieve munin config
$ curl "https://console.tryphon.eu/streams.munin?api_token=YOUR_API_KEY&mode=config"

This small wrapper is the only required plugin script to use this API in Munin setup. Specify the API URL (with your api key) in the munin plugin configuration. And enjoy.

Tryphon Boxes and Cucumber

Cucumber is a great tool to specify and test automaticaly if an application gives the expected service.

We’re trying to use this BDD tool for several months (especially on PigeBox and StreamBox). But it’s little harder to test an complete computer than a simple software …

Let’s try this small scenario on StreamBox :

  Scenario: Create a local Ogg/Vorbis stream
    Given I am on /streams/new
    When I fill in the following:
    | Name        | Ogg/Vorbis test |
    | Server      | localhost       |
    | Port        | 8000            |
    | Mount point | test.ogg        |
    | Password    | dummy           |
    And I choose "Ogg/Vorbis"
    And I press "Add"
    Then an ogg stream should respond on "http://streambox.local:8000/test.ogg"

You need to :

And .. you need to roolback your modifications to perform the next test scenario. But rollback a computer isn’t something easy (when you really want to, not by mistake ;)

Hopefully, the Tryphon Boxes can be virtualized for test. And kvm provides a nice way to save and reload a virtual machine status (including memory, disks, cpu, etc …). We can obtain a “fresh” Box after each scenario in one second.

We experienced this mechanism on PigeBox in the past, we’ve improved it this week and we’re now generalizing it on all Boxes.

Munin and Ruby

To create easily munin plugins in Ruby, we created (a long time ago) a small munin gem. To create the Munin API (presented above), we updated this Ruby munin plugin library.

You can create a plugin in few lines :

require 'munin'

class StreamLevels < Munin::Plugin

  graph_attributes "Stream sound level",
    :category => 'Radio',
    :info => 'Streaming audio levels'

  declare_field :peak_level, :label => 'Peak level (dB)', :max => 0
  declare_field :rms_level, :label => 'RMS level (dB)', :max => 0

  # ...

  def retrieve_values
    { :peak_level => stream_stats.peak_level,
      :rms_level  => stream_stats.rms_level }
  end

end

Munin::Plugin will manage for you the munin syntax and required outputs.

QEMU/Kvm and Ruby

The Tryphon Boxes development and validation use heavily virtual machines (see week 15 about continous validation).

We had several pieces of code to control these QEMU / kvm virtual machines. We’re publishing a standalone qemu gem which can control QEMU (or kvm) instances :

qemu = QEMU::Command.new.tap do |qemu|
  qemu.memory = 512
  qemu.disks << "system.disk"
  qemu.disks << "storage.disk"

  # To control VM
  qemu.telnet_port = 4444
  # To see VM screen
  qemu.vnc = ":1"
end

# Start the VM in background
qemu.daemon.start

# Reboot the VM via monitor
qemu.qemu_monitor.reset

# Kill the VM
qemu.daemon.stop

You can create or convert disk images, send commands to VM monitor, etc …