Index: includes/polling/applications/memcached.inc.php
===================================================================
--- includes/polling/applications/memcached.inc.php	(revision 4367)
+++ includes/polling/applications/memcached.inc.php	(working copy)
@@ -9,9 +9,61 @@
     if(strpos($memcached_host, ":"))
     {
 
-      echo("memcached(".$memcached_host.") ");
+      echo(" memcached(".$memcached_host.") ");
+      
+      // These are the keys we expect. If we fall back to the old value-only
+      // data (instead of the new key:value data) we expect them exactly in
+      // this order.
+      $keys = array('accepting_conns', 'auth_cmds', 'auth_errors', 'bytes',
+                    'bytes_read', 'bytes_written', 'cas_badval', 'cas_hits',
+                    'cas_misses', 'cmd_flush', 'cmd_get', 'cmd_set',
+                    'conn_yields', 'connection_structures',
+                    'curr_connections', 'curr_items', 'decr_hits',
+                    'decr_misses', 'delete_hits', 'delete_misses',
+                    'evictions', 'get_hits', 'get_misses', 'incr_hits',
+                    'incr_misses', 'limit_maxbytes', 'listen_disabled_num',
+                    'pid', 'pointer_size', 'rusage_system', 'rusage_user',
+                    'threads', 'time', 'total_connections', 'total_items',
+                    'uptime', 'version');
+                    
+      // Initialise the expected values
+      $values = array();
+      foreach ($keys as $key)
+      {
+        $values[$key] = '0';
+      }
 
-      list ($accepting_conns, $auth_cmds, $auth_errors, $bytes, $bytes_read, $bytes_written, $cas_badval, $cas_hits, $cas_misses, $cmd_flush, $cmd_get, $cmd_set, $conn_yields, $connection_structures, $curr_connections, $curr_items, $decr_hits, $decr_misses, $delete_hits, $delete_misses, $evictions, $get_hits, $get_misses, $incr_hits, $incr_misses, $limit_maxbytes, $listen_disabled_num, $pid, $pointer_size, $rusage_system, $rusage_user, $threads, $time, $total_connections, $total_items, $uptime, $version) = explode("\n", $memcached_data);
+      // Parse the data, first try key:value format
+      $lines = explode("\n", $memcached_data);
+      $fallback_to_values_only = False;
+      foreach ($lines as $line) {
+        // Fall back to values only if we don't see a : separator
+        if (!strstr($line, ':'))
+        {
+          $fallback_to_values_only = True;
+          break;
+        }
+        
+        // Parse key:value line
+        list($key, $value) = explode(':', $line, 2);
+        $values[$key] = $value;
+      }
+
+      if ($fallback_to_values_only)
+      {
+        // See if we got the expected data
+        if (count($keys) != count($lines))
+        {
+          // Skip this one, we don't know how to handle this data
+          echo("<- [skipped, incompatible data received] ");
+          continue;
+        }
+        
+        // Combine keys and values
+        echo("<- [old data format received, please upgrade agent] ");
+        $values = array_combine($keys, $lines);
+      }
+
       $app_id = dbFetchCell("SELECT app_id FROM `applications` WHERE `device_id` = ? AND `app_instance` = ?", array($device['device_id'], $memcached_host));
 
       $rrd_filename  = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-memcached-".safename($memcached_host).".rrd";
@@ -45,8 +97,22 @@
         DS:bytes_written:DERIVE:600:0:125000000000 \
         ".$config['rrd_rra']);
       }
+      
+      // Construct the data
+      $rrd_data = "";
+      $rrd_keys = array('uptime', 'threads', 'rusage_user', 'rusage_system',
+                        'curr_items', 'total_items', 'limit_maxbytes',
+                        'curr_connections', 'total_connections',
+                        'connection_structures', 'bytes', 'cmd_get',
+                        'cmd_set', 'cmd_flush', 'get_hits', 'get_misses',
+                        'evictions', 'bytes_read', 'bytes_written');
+      
+      foreach ($rrd_keys as $key)
+      {
+        $rrd_data .= ":".$values[$key];
+      }
 
-      rrdtool_update($rrd_filename, "N:$uptime:$threads:$rusage_user:$rusage_system:$curr_items:$total_items:$limit_maxbytes:$curr_connections:$total_connections:$connection_structures:$bytes:$cmd_get:$cmd_set:$cmd_flush:$get_hits:$get_misses:$evictions:$bytes_read:$bytes_written");
+      rrdtool_update($rrd_filename, "N".$rrd_data);
     }
 
   }
Index: scripts/agent-local/memcached
===================================================================
--- scripts/agent-local/memcached	(revision 4367)
+++ scripts/agent-local/memcached	(working copy)
@@ -10,4 +10,4 @@
    server = server.split(' ', 2)
    print '<<<app-memcached-'+server[0]+'>>>'
    for stat_name, value in sorted(stats.iteritems()):
-     print value
+     print '%s:%s' % (stat_name, value)