我希望能够查询gearman服务器,以确定我运行的工作人员有多少个实例(基本上,我希望确保RunTaskA可用,如果没有处理这些任务的工作人员,则确保RunTaskB可用,我希望能够发出警报。
有办法这样做吗?
另外:如果您知道PHP查询gearman服务器的方法,那么Mad道具。
编辑:我知道PHP扩展是本地可用的,但我并不是在寻找任务提交扩展,我需要一些东西来查询gearman服务器,看看有多少工作人员在为特定的任务服务。
发布于 2010-05-27 18:30:21
class Waps_Gearman_Server {
/**
* @var string
*/
protected $host = "127.0.0.1";
/**
* @var int
*/
protected $port = 4730;
/**
* @param string $host
* @param int $port
*/
public function __construct($host=null,$port=null){
if( !is_null($host) ){
$this->host = $host;
}
if( !is_null($port) ){
$this->port = $port;
}
}
/**
* @return array | null
*/
public function getStatus(){
$status = null;
$handle = fsockopen($this->host,$this->port,$errorNumber,$errorString,30);
if($handle!=null){
fwrite($handle,"status\n");
while (!feof($handle)) {
$line = fgets($handle, 4096);
if( $line==".\n"){
break;
}
if( preg_match("~^(.*)[ \t](\d+)[ \t](\d+)[ \t](\d+)~",$line,$matches) ){
$function = $matches[1];
$status['operations'][$function] = array(
'function' => $function,
'total' => $matches[2],
'running' => $matches[3],
'connectedWorkers' => $matches[4],
);
}
}
fwrite($handle,"workers\n");
while (!feof($handle)) {
$line = fgets($handle, 4096);
if( $line==".\n"){
break;
}
// FD IP-ADDRESS CLIENT-ID : FUNCTION
if( preg_match("~^(\d+)[ \t](.*?)[ \t](.*?) : ?(.*)~",$line,$matches) ){
$fd = $matches[1];
$status['connections'][$fd] = array(
'fd' => $fd,
'ip' => $matches[2],
'id' => $matches[3],
'function' => $matches[4],
);
}
}
fclose($handle);
}
return $status;
}
}发布于 2010-06-03 10:59:47
为了快速检查,我使用了这个bash一行:
# (echo status ; sleep 0.1) | netcat 127.0.0.1 4730这将打开与运行在localhost上的gearman实例的连接,并发送"status“查询。这包含了该实例上作业的名称和数量。然后,这些信息可与grep/awk/wc等一起处理,以便进行报告和报警。
我还对“工人”查询进行了同样的操作,该查询显示所有连接的工作人员。
# (echo workers ; sleep 0.1) | netcat 127.0.0.1 4730睡眠是为了保持连接打开足够长的时间来回复。
管理命令的完整列表,以及输出在http://gearman.org/index.php?id=protocol上意味着什么,只需搜索“管理协议”
发布于 2011-04-29 21:40:23
要扩展d5ve的答案,因为netcat将坐在套接字上等待,您可以添加一个-w参数,其最大运行秒数为秒数。因此,如果您正在查询本地主机:
# (echo status ; sleep 0.1) | netcat 127.0.0.1 4730 -w 1..。否则,您将永远无法回到命令提示符。
https://stackoverflow.com/questions/2752431
复制相似问题