Scout has [such a plugin](https://github.com/scoutapp/scout-plugins/blob/master/php_fpm_status/php_fpm_status.rb), written in Ruby, which might be helpful as a starting point.