Calling FMS admin API methods with PHP

There is a rather simple way of getting status info from a running Flash Media Server. This can be used to draw graphs with Cacti for instance.

First make sure the admin API over HTTP is enabled in /opt/adobe/fms/conf/fms.ini

USERS.HTTPCOMMAND_ALLOW = true

Then enable the methods you need or use a keyword “All” in /opt/adobe/fms/conf/Users.xml

<AdminServer>
    <HTTPCommands>
        ...
        <Allow>All</Allow>
        <Deny></Deny>
        <Order>Deny,Allow</Order>
    </HTTPCommands>
</AdminServer>

Here is a working example of how to get the number of active connections with PHP (you need php-XML module to run this).

<?php
$adminUser='admin';
$adminPassw='SuperSecretPassword';

$xml=new DomDocument();
$url="http://localhost:1111/admin/getServerStats?auser=$adminUser&apswd=$adminPassw";
$xml->load($url);
$connected=getTagContents('connected',$xml);

printf("There are currently %d active connections on the server\n",$connected);

function getTagContents($tagName,$dom) {
    $node=$dom->getElementsByTagName($tagName)->item(0);
    return $node->nodeValue;
}
?>

In the example above I just extract a single value out of a returned XML that looks something like this:

<result>
    <level>status</level>
    <code>NetConnection.Call.Success</code>
    <timestamp>Thu 28 Apr 2011 11:59:24 AM EEST</timestamp>
    <data>
        <launchTime>Tue 26 Apr 2011 07:29:32 PM EEST</launchTime>
        <uptime>145792</uptime>
        <cpus>2</cpus>
        <cpu_Usage>0</cpu_Usage>
        <num_cores>1</num_cores>
        <memory_Usage>4</memory_Usage>
        <physical_Mem>98799616</physical_Mem>
        <io>
            <msg_in>1008000</msg_in>
            <msg_out>190805</msg_out>
            <msg_dropped>0</msg_dropped>
            <bytes_in>423676178</bytes_in>
            <bytes_out>3904886327</bytes_out>
            <reads>434063</reads>
            <writes>168869</writes>
            <bw_in>0</bw_in>
            <bw_out>0</bw_out>
            <total_connects>72</total_connects>
            <total_disconnects>69</total_disconnects>
            <connected>3</connected>
            <rtmp_connects>4</rtmp_connects>
            <rtmfp_connects>0</rtmfp_connects>
            <normal_connects>0</normal_connects>
            <virtual_connects>1</virtual_connects>
            <group_connects>3</group_connects>
            <service_connects>0</service_connects>
            <service_requests>0</service_requests>
            <admin_connects>0</admin_connects>
            <debug_connects>0</debug_connects>
            <total_threads>168</total_threads>
            <working_threads>2</working_threads>
            <swf_verification_attempts>0</swf_verification_attempts>
            <swf_verification_exceptions>0</swf_verification_exceptions>
            <swf_verification_failures>0</swf_verification_failures>
            <swf_verification_unsupported_rejects>0</swf_verification_unsupported_rejects>
            <swf_verification_matches>0</swf_verification_matches>
            <swf_verification_remote_misses>0</swf_verification_remote_misses>
            <server_bytes_in>0</server_bytes_in>
            <server_bytes_out>0</server_bytes_out>
            <rtmfp_lookups>0</rtmfp_lookups>
            <rtmfp_remote_lookups>0</rtmfp_remote_lookups>
            <rtmfp_remote_lookup_requests>0</rtmfp_remote_lookup_requests>
            <rtmfp_redirects>0</rtmfp_redirects>
            <rtmfp_remote_redirects>0</rtmfp_remote_redirects>
            <rtmfp_remote_redirect_requests>0</rtmfp_remote_redirect_requests>
            <rtmfp_forwards>0</rtmfp_forwards>
            <rtmfp_remote_forwards>0</rtmfp_remote_forwards>
            <rtmfp_remote_forward_requests>0</rtmfp_remote_forward_requests>
        </io>
    </data>
</result>

If you decide to pull status info from remote servers then keep in mind that it is not the best idea to make the admin API port world-accessible. Also be aware that the password is passed in plain text on the URL!

A better alternative might be to limit admin API calls to localhost and pass the needed values to your monitoring server over SNMP.

FMS edge/origin configuration

Turns out that setting up a simple load balancing solution with FMS servers is quite easy.

On origin server you don’t need to change anything. On the edge servers locate Vhost.xml file (if you are not using vhosts, then it’s /opt/adobe/fms/conf/_defaultRoot_/_defaultVHost_/Vhost.xml.

Locate the mode-tag that looks something like:

<Mode>local</Mode>

and change it to:

<Mode>remote</Mode>

And you need to let the edge server know what is the address of your origin by putting that info into routeentry-tag:

<RouteEntry>*:*;origin.server.address:*</RouteEntry>

Good idea is to turn on the caching on edge servers too. Look for a tag like

<CacheDir enabled=”true” useAppName=”true”>

Restart FMS on edge servers and create a round-robin DNS record that points to your edge servers and you are done.

Compiling Strobe Media Playback using command line

The developers of Strobe Media Playback are rather vague about how to compile the source code. This article tries to list all the steps needed to get a working SWF on any modern OS.

Here is a list of things you will need to make the magic happen:

  • Java JDK 6
  • Apache Ant
  • Adobe Flex SDK 4
  • FlexUnit 4
  • Ant Contrib

First make sure you have Java (JDK 6) installed on your OS.
Next get Apache Ant from http://ant.apache.org/bindownload.cgi (I used v1.8.2 for this article) or if you are running some OS with central software repositories (Linux, FreeBSD, etc), then install using the tools provided with it (yum, pkg_add, apt-get, etc).
When setting up Apache Ant on a Windows machine make sure you add the bin directory to PATH variable of the system.

Then go and download the Strobe Media Playback source from http://sourceforge.net/projects/smp.adobe/files/ (for this article I used v1.5.1). Uncompress the downloaded file and at the root of the uncompressed source directory create the following subdirectories:

./buildtools/
./buildtools/libs/
./buildtools/sdks/
./buildtools/sdks/4.1.0/

Now lets populate the ./buildtools folder with some… umm build tools obviously… duh…

Go and download Flex 4 SDK from http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4 (for this article I used v4.1.0.16076). Uncompress the files into the ./buildtools/sdks/4.1.0/ subdirectory.

Now we’ll need something called ANT Contrib. Version 1.0b3 to be precise. Uncompress the archive and move the ant-contrib-1.0b3.jar file to ./buildtools/libs/

Finally something called FlexUnit… from the download page choose the stable release FlexUnit (4.0 SDK). Uncompress the the archive and move flexUnitTasks-4.0.0.jar to ./buildtools/libs/

If using Windows, then now you can execute the “src\build.bat compile.strobe”.

For unix-like OS-es you need to create a shell script ./src/compile.strobe, like:

#!/bin/bash
BUILD_TOOLS=”..\buildtools”
/usr/bin/ant \
-lib ${BUILD_TOOLS}\sdks\4.1.0\lib \
-lib ${BUILD_TOOLS}\sdks\4.1.0\ant\lib \
-lib ${BUILD_TOOLS}\libs \
compile.strobe

If you don’t have bash, then just tweak the script a bit to match the conventions of your favourite shell.

If you look inside ./src/build.xml, you’ll notice that there are many other build targets besides “compile.strobe”. Haven’t yet worked out how to make them all work… will post an update when I do.

Debug build for Flash Player 10.1