ACTIVEMQ is a software that every operation and maintenance staff must master, he is one of the lifeblood of the company's operation, so important, then its watchdog is relatively gold. ACTIVEMQ's watchdog is not like that # Ps-ef|grep MQ See process or #netstat-ntpl|grep 61613 so straightforward, because ACTIVEMQ still have a kind of suspended animation, that is " Both the process and the port are in, but the queue is dead ", in which case the current ACTIVEMQ must be restarted.
Then to write a script like this, you need to meet the following conditions:
1) Because MQ is a cluster, there is a master of the points, first we first on the main MQ to determine whether the current machine 61613 port monitoring;
2) If the current machine 61613 port is normal, to add information to MQ, if the information can be successfully added to the corresponding queue, then you can prove that MQ is normal;
3) If the information cannot be added, listen for the 61613 port of the standby MQ.
4) If the 61613 port of the standby MQ is not present, send the mail alarm and restart the main standby MQ process simultaneously;
5) If the 61613 port of the standby MQ is normal, the information queue of the standby MQ is tested properly;
6) If the information queue of the standby MQ is not normal, send the mail alarm and restart the main standby MQ process simultaneously;
The above is the logical idea of our MQ watchdog script, here we write in Python language, why use Python, because Python has a stomp module, this module is stomach activemq failure of the magic weapon!
First of all, this stomp need to be installed manually, he is https://github.com/jasonrbriggs/stomp.py, select "Clone or Download", and then the entire compressed file to the Linux server, After decompression, use the # python setup.py installin the Stomp folder, and then see the following text to prove that stomp has been installed successfully:
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/8B/C4/wKiom1hXxpGjo4PuAABrjibDD8Q123.png "title=" 1.png " alt= "Wkiom1hxxpgjo4puaabrjibdd8q123.png"/>
Then we'll write a simple script for the test queue with the following script:
[email protected] ~]# cat mqtest.py import timeimport sysimport stompclass MyListener (object): Def on_error (self, head ERS, message): Print (' received an error%s '% message) def on_message (self, headers, message): Print (' Rec Eived a message%s '% message ' conn = Stomp. Connection ([' MQ's intranet IP address ', 61613]]) Conn.set_listener (", MyListener ()) Conn.start () Conn.connect (' MQ account ', ' MQ password ') Conn.subscribe (destination= '/queue/chenshuo ', id=1, ack= ' auto ') conn.send (body= ' hello,this is my Test message! ', destination= '/queue/chenshuo ') time.sleep (2) Conn.disconnect ()
In this script, we take MQ's intranet address as the connection address, because it is safe to do so, then we create a queue called "Chenshuo", which transmits a message, the content of the message is
Hello,this is my test message!
To start this script, let's look at the Linux side effect.
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/8B/C0/wKioL1hXyLXC-LSzAAAbV400YRU060.png "title=" 1.png " alt= "Wkiol1hxylxc-lszaaabv400yru060.png"/>
Look again at the Web interface:
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/8B/C0/wKioL1hXyPmhF5LzAACmWtliP6Q997.png "title=" 1.png " alt= "Wkiol1hxypmhf5lzaacmwtlip6q997.png"/>
It can be seen that the Chenshuo queue has been generated, and the number of messages for into row and dequeue is 3 (because I passed two experiments before), and the script above is a successful one.
But this script is just a grass-like, because this message is not "consumer", without consumers, then the three messages will accumulate, and their fate is either deleted or wait for consumers to appear to consume them.
(not to be continued)
This article is from "Life is waiting for Gordo" blog, please make sure to keep this source http://chenx1242.blog.51cto.com/10430133/1884051
ACTIVEMQ Judgment Queue Survival script