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.