• 使用jolokia api监控ActiveMQ


    jolokia api提供了一种通过HTTP访问JMX获得AMQ后台数据的一种方式,即Restful Api

    #!/usr/bin/env python
    # -*- coding:utf-8 -*-
    import requests
    import json
    import re
    import time
    import sys
    n = 1
    while True:
        queues = requests.get("http://172.16.1.15:8161/api/jolokia/read/org.apache.activemq:type=Broker,brokerName=activemq_server01/Queues",auth=("admin","admin"))
    
        listQueue = json.loads(queues.content)["value"]
    
        for queue in listQueue:
            data = queue['objectName'].encode('unicode-escape').split(r',')[1]
            queueName = data.split(r'=')[1]
            enqueue1 = requests.get("http://172.16.1.15:8161/api/jolokia/read/org.apache.activemq:type=Broker,brokerName=activemq_server01,destinationType=Queue,destinationName="+queueName+"/EnqueueCount",auth=("admin","admin"))
            dequeue1 = requests.get(
                "http://172.16.1.15:8161/api/jolokia/read/org.apache.activemq:type=Broker,brokerName=activemq_server01,destinationType=Queue,destinationName=" + queueName + "/DequeueCount",
                auth=("admin", "admin"))
            queueSize1 = requests.get(
                "http://172.16.1.15:8161/api/jolokia/read/org.apache.activemq:type=Broker,brokerName=activemq_server01,destinationType=Queue,destinationName=" + queueName + "/QueueSize",
                auth=("admin", "admin"))
            consumer1 = requests.get(
                "http://172.16.1.15:8161/api/jolokia/read/org.apache.activemq:type=Broker,brokerName=activemq_server01,destinationType=Queue,destinationName=" + queueName + "/ConsumerCount",
                auth=("admin", "admin"))
            enqueue = json.loads(enqueue1.content)['value']
            dequeue = json.loads(dequeue1.content)['value']
            queueSize = json.loads(queueSize1.content)['value']
            consumer = json.loads(consumer1.content)['value']
    
    
            print("第%d次采集:%-20s 待消费 %-5d 入队量 %-5d 出队量 %-5d 消费者 %-5d"% (n,queueName,queueSize,enqueue,dequeue,consumer))
        n=n+1
        time.sleep(5)
    

      

  • 相关阅读:
    struts2乱码
    修改maven的war包生成路径
    cookie的坑
    linux jps 命令
    (转)如何使VMware ip与本机ip处于同一网段
    springboot + swagger2 学习笔记
    can not find java.util.map java.lang.Double问题
    为什么不写 @RequestParam 也能拿到参数?
    乱码问题
    PostMan的使用注意事项
  • 原文地址:https://www.cnblogs.com/Peter2014/p/8404895.html
Copyright © 2020-2023  润新知