rabbitmq的监控
·
rabbiqmq搭建完成后,可通过web来对rabbitmq的某些指标进行监控,不过在此不予讨论。
在rabbirmq的web监控页面提供了http api监控文档。网址就是http://IP:15672/api/ 将ip换成自身主机的ip地址。
通过curl对rabbitmq进行监控,如下:
[root@crq720 ~]# curl -i -u guest:guest 'http://localhost:15672/api/overview'
HTTP/1.1 200 OK
Server: MochiWeb/1.1 WebMachine/1.10.0 (never breaks eye contact)
Date: Tue, 19 Jul 2016 00:59:30 GMT
Content-Type: application/json
Content-Length: 1300
Cache-Control: no-cache
{"management_version":"3.2.3","statistics_level":"fine","exchange_types":[{"name":"fanout","description":"AMQP fanout exchange, as per the AMQP specification","enabled":true},{"name":"direct","description":"AMQP direct exchange, as per the AMQP specification","enabled":true},{"name":"headers","description":"AMQP headers exchange, as per the AMQP specification","enabled":true},{"name":"topic","description":"AMQP topic exchange, as per the AMQP specification","enabled":true}],"rabbitmq_version":"3.2.3","erlang_version":"R14B04","erlang_full_version":"Erlang R14B04 (erts-5.8.5) [source] [64-bit] [rq:1] [async-threads:30] [kernel-poll:true]","message_stats":{},"queue_totals":{"messages":0,"messages_details":{"rate":0.0},"messages_ready":0,"messages_ready_details":{"rate":0.0},"messages_unacknowledged":0,"messages_unacknowledged_details":{"rate":0.0}},"object_totals":{"consumers":0,"queues":1,"exchanges":15,"connections":0,"channels":0},"node":"rabbit@crq720","statistics_db_node":"rabbit@crq720","listeners":[{"node":"rabbit@crq720","protocol":"amqp","ip_address":"::","port":5672}],"contexts":[{"node":"rabbit@crq720","description":"RabbitMQ Management","path":"/","port":15672},{"node":"rabbit@crq720","description":"Redirect to port 15672","path":"/","port":55672,"ignore_in_use":true}]}
如上所示,使用curl -i -u guest:guest ‘http://localhost:15672/api/overview‘得到的是rabbitmq的web页面的overview的信息。
[root@crq720 ~]# curl -i -u guest:guest 'http://localhost:15672/api/queues/%2Fudc_host/udc_queue'
HTTP/1.1 200 OK
Server: MochiWeb/1.1 WebMachine/1.10.0 (never breaks eye contact)
Date: Tue, 19 Jul 2016 01:05:08 GMT
Content-Type: application/json
Content-Length: 787
Cache-Control: no-cache
{"memory":13704,"messages":0,"messages_details":{"rate":0.0},"messages_ready":0,"messages_ready_details":{"rate":0.0},"messages_unacknowledged":0,"messages_unacknowledged_details":{"rate":0.0},"idle_since":"2016-06-28 8:01:57","policy":"","exclusive_consumer_tag":"","consumers":0,"backing_queue_status":{"q1":0,"q2":0,"delta":["delta","undefined",0,"undefined"],"q3":0,"q4":0,"len":0,"pending_acks":0,"target_ram_count":"infinity","ram_msg_count":0,"ram_ack_count":0,"next_seq_id":0,"persistent_count":0,"avg_ingress_rate":0.0,"avg_egress_rate":0.0,"avg_ack_ingress_rate":0.0,"avg_ack_egress_rate":0.0},"status":"running","incoming":[],"deliveries":[],"consumer_details":[],"name":"udc_queue","vhost":"/udc_host","durable":true,"auto_delete":false,"arguments":{},"node":"rabbit@crq720"}
如上所示,使用curl -i -u guest:guest ‘http://localhost:15672/api/queues/%2Fudc_host/udc_queue‘所得到的是Virtual host为/udc_host,quene为udc_queue的queue信息。在此/在url中的转义字符为%2F。
如上,可通过crul获得想要监控的信息,想监控更多内容,就去查API文档吧。
在此我最想说的是我通过curl获取的信息,太难看,如果显示的效果是树状形式就好了,可惜我并没有找到curl的信息格式化的内容,在此,我便使用了python脚本来进行监控:
import sys, json, urllib, base64, socket,httplib
server = '172.16.17.128'
port = '15672'
vhost = '/udc_host'
username = 'guest'
password = 'guest'
queue_name = 'udc_queue'
conn = httplib.HTTPConnection(server, port)
path = "/api/queues/%s/%s" % (urllib.quote(vhost, safe=""),
queue_name)
method = "GET"
credentials = base64.b64encode("%s:%s" % (username, password))
conn.request(method, path, "",
{"Content-Type" : "application/json",
"Authorization" : "Basic " + credentials})
response = conn.getresponse()
resp_payload = json.loads(response.read())
resp_payload = json.dumps(resp_payload,indent = 4)
print resp_payload
如上代码是根据书籍《rabbitmq in action》进行修改的,在此,简化了些代码,方便理解。如上的代码片段显示效果如下:
{
"node": "rabbit@crq720",
"auto_delete": false,
"deliveries": [],
"idle_since": "2016-06-28 8:01:57",
"messages_unacknowledged": 0,
"consumers": 0,
"durable": true,
"arguments": {},
"memory": 13704,
"exclusive_consumer_tag": "",
"messages_ready_details": {
"rate": 0.0
},
"status": "running",
"messages_details": {
"rate": 0.0
},
"vhost": "/udc_host",
"consumer_details": [],
"messages_unacknowledged_details": {
"rate": 0.0
},
"incoming": [],
"name": "udc_queue",
"policy": "",
"backing_queue_status": {
"q1": 0,
"q3": 0,
"q2": 0,
"q4": 0,
"avg_ack_egress_rate": 0.0,
"ram_msg_count": 0,
"ram_ack_count": 0,
"len": 0,
"persistent_count": 0,
"target_ram_count": "infinity",
"next_seq_id": 0,
"delta": [
"delta",
"undefined",
0,
"undefined"
],
"pending_acks": 0,
"avg_ack_ingress_rate": 0.0,
"avg_egress_rate": 0.0,
"avg_ingress_rate": 0.0
},
"messages": 0,
"messages_ready": 0
}
在此以树状形式展现更方便自己选取监控指标,也方便改写代码在nagios和collectd中进行监控。
更多推荐
所有评论(0)