如何获取 gearman 中特定类型的排队作业数量?
我有很多 gearman 客户发送了一份作业,比如 job1。
$client = new GearmanClient();
$client->addServer();
$client->doBackground('job1', 'workload');
处理此作业需要 10 秒钟。 我想跟踪在任何给定时间有多少“job1”工作正在等待工人处理。我怎样才能做到这一点?
I have a number of gearman clients sending a job, say job1.
$client = new GearmanClient();
$client->addServer();
$client->doBackground('job1', 'workload');
It takes, say 10 seconds to process this job.
I want to track how many 'job1' jobs are waiting for a worker to work on them at any given time. How can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
为了快速检查,我使用了这个 bash 单行代码:
这将打开与本地主机上运行的 gearman 实例的连接,并发送状态查询。其中包含该实例上作业的名称和数量。然后可以使用
grep
/awk
/wc
等处理该信息以进行报告和警报。我还对显示所有连接的工作人员的 workers 查询执行相同的操作。
睡眠是为了保持连接打开足够长的时间以进行回复。
管理命令的完整列表以及输出的含义位于 http://gearman.org/protocol/ 。只需搜索“管理协议”即可。
For quick checking, I use this bash one-liner:
This opens a connection to a gearman instance running on localhost, and sends the status query. This contains the name and number of jobs on that instance. The information can then be processed with
grep
/awk
/wc
etc. for reporting and alerting.I also do the same with the workers query which shows all connected workers.
The sleep is to keep the connection open long enough for the reply.
The full list of administrative commands, and what the output means is at http://gearman.org/protocol/. Just search for "Administrative Protocol".
为了扩展 d5ve 的答案,添加一个 -w 参数来“超时”你的 netcat 连接,否则你永远不会回到命令提示符。
To expand on d5ve's answer, add a -w parameter to "time out" your netcat connection, otherwise you never get back to a command prompt.
我使用
gearman_top
,它是 mod 的一部分-齿轮工。网站的输出示例:
I use
gearman_top
, which is part of mod-gearman.Example output from the website:
在 Ubuntu 18.04 上,我默认使用 gearman 包安装了
gearadmin
二进制文件。gearadmin --help
可以使用
gearadmin --status
代替 netcat 替代方案:还有一个衬垫:
<代码>同时:;执行 gearadmin --status;睡觉1;完成
On Ubuntu 18.04 I have the
gearadmin
binary installed by default with the gearman package.gearadmin --help
gearadmin --status
can be used instead of the netcat alternative:And a one liner:
while :; do gearadmin --status; sleep 1; done
看起来没有任何直接的方法可以获取此信息。
这里有几个选项。首先,您是否可以在创建作业句柄时获取作业句柄 (搜索“谈到检查状态”),您可以将它们存储在某个中心位置并从任何客户端查询它们。
其次,您可以将 Gearman 服务器设置为使用持久队列,并且然后自己对队列运行查询。这可能是两个选项中更简单、更干净的一个。
It doesn't look like there are any immediate ways to get this information.
Here are a few options. First, if you can grab job handles as you create them (search for "Speaking of checking the status"), you can store them away in some central place and query about them from any client.
Second, you can set your Gearman server to use persistent queues, and then run a query against the queue yourself. This might be the easier and cleaner of the two options.
Gearmand有一个telnet接口可以查询。 (协议的具体细节可以在 gearman 网站上找到 - http://gearman.org/?id=协议)
我在这里使用此代码作为滚动我自己的代码的起点。
https://github.com/liorbk/php/blob/master/GearmanTelnet.php
(这段代码本身就非常好,您应该能够直接使用它)
这是一个不太漂亮的解决方案,但直到有人改进 gearman 管理界面,以便您可以直接通过 PHP 进行对话或为其编写一个插件,您靠你自己
Gearmand has a telnet interface you can query. (the exact details of the protocol can be found on the gearman website - http://gearman.org/?id=protocol )
I used this code here as a starting point for rolling my own.
https://github.com/liorbk/php/blob/master/GearmanTelnet.php
(this code is perfectly good by itself and you should be able to drop use it out of the box)
It's a less than pretty solution but until someone improves gearman admin interface so you can talk directly via PHP or writes a plugin for it, you are on your own