Deploy comment Cat monitoring project
To monitor the code running status in a project, you can use the commented Cat project to monitor the entire project. However, if you deploy cat according to official documents, you will always encounter various problems, the explanation is not clear enough. Now we use a single machine to deploy and run the cat monitoring project.
First, download the entire project from the git page of the project:
Https://github.com/dianping/cat
Go to the directory of the project and run the package installation command:
Mvn clean install-DskipTests (maven required)
After the installation is complete, run the CAT installation plug-in command:
Mvn cat: install
You will be prompted to enter the connection information, account, and password of the mysql database. You may be prompted that the \ data \ appdatas \ cat directory is missing. You can manually add the directory.
Finally, go to the cat-home Directory: cd cat-home and run mvn jetty: run.
You can start it without any error prompts. Enter the address in the browser:
Localhost: 2281 will go to the interface. This interface has instructions to demonstrate the effect and so on. It is useless. Turn it off.
Go to the project, copy the/cat-home/target/cat-alpha-1.3.6-SNAPSHOT.war file to tomcat's webapps, and change the name to: cat. war. The data folder must be in the root directory of the disk where tomcat is located, including:
\ Data \ appdatas \ cat and \ data \ applogs \ cat folders. If they do not exist, create them manually.
The content in the \ data \ appdatas \ cat folder is displayed in mvn cat: install. The client is automatically created. xml, datasources. xml and server. xml file, datasources. xml is the database connection information, which does not need to be modified unless it is changed. xml and server. the number of servers in the xml file is the address of the server. Since I did my experiments on the machine, I only had the address of one machine.
You only need to change the content in the red box to the client. xml file:
The server. xml file is changed to the content in the red box. There are multiple machines, just change it as noted below the red box.
After modification, start tomcat (bin \ startup. bat)
No problem. You can view the logs in the \ data \ applogs \ cat directory as prompted.
Enter http: // localhost: 8080/cat/r in the browser to view the deployed CAT interface. The "real-time" function in the upper left corner is what we need most!
After you click it, you will find that all instances are demo instances. You can view the corresponding code to learn how to use them.
In the test section of the home module of the project, there is a com. dianping. cat. demo. TestStorageMessage class
The code above can find the corresponding effect on our interface.
For example, if sendSQLMsg is used, the monitoring name and method are found in the "Event" monitoring function on the interface.
private void sendSQLMsg(String name, String domain, String method, String serverIp) throws InterruptedException {Transaction t = Cat.newTransaction("SQL", "sql.method");Cat.logEvent("SQL.Method", method);Cat.logEvent("SQL.Database", String.format(JDBC_CONNECTION, serverIp, name));MessageTree tree = Cat.getManager().getThreadLocalMessageTree();((DefaultMessageTree) tree).setDomain(domain);Thread.sleep(500 + new Random().nextInt(1000));int nextInt = new Random().nextInt(3);if (nextInt % 2 == 0) {t.setStatus(Transaction.SUCCESS);} else {t.setStatus(String.valueOf(nextInt));}t.complete();}
The names of the two lines in the Code:
Cat.logEvent("SQL.Method", method);Cat.logEvent("SQL.Database", String.format(JDBC_CONNECTION, serverIp, name));
Therefore, we can easily learn how to use it. Because the Cat project has been started and the entire machine is under monitoring, the project you write has been specified to be monitored by the cat project to achieve real-time monitoring and analyze the implementation effect of our code.
Create a new project, add cat-home \ target \ cat-home-1.3.6-SNAPSHOT \ WEB-INF \ lib in all the jar packages, do not know what useful, which is useless, so it's right to join all the projects.
Compile a class in the project with the following content:
public class MyTest { public static void main(String[] args) { Transaction t = Cat.newTransaction("TEST", "test.method"); Cat.logEvent("Method_test", "good"); Cat.logEvent("Method_event", "bad"); int nextInt = new Random().nextInt(3); if (nextInt % 2 == 0) { t.setStatus(Transaction.SUCCESS); } else { t.setStatus(String.valueOf(nextInt)); } t.complete(); }}
Running, and found that it will soon end! Enter a prompt to view the log.
When the log is opened, the following prompt is displayed:
[07-20 22:05:34.780] [INFO] [DefaultModuleContext] Starting thread(Cat-ModelService-0) ...[07-20 22:10:08.922] [INFO] [DefaultModuleContext] Starting thread(Cat-ModelService-1) ...[07-20 22:20:00.677] [INFO] [DefaultModuleContext] Current working directory is C:\hadoop_java[07-20 22:20:00.699] [INFO] [DefaultClientConfigManager] Global config file(\data\appdatas\cat\client.xml) found.[07-20 22:20:00.700] [INFO] [DefaultClientConfigManager] Can't find app.properties in /META-INF/app.properties[07-20 22:20:00.711] [WARN] [DefaultTransportManager] CAT was DISABLED due to not initialized yet!
The prompt is clear, that is, there is no app. properties file, which is also mentioned in the project description document. This document mainly specifies the monitored Cat project. Because our monitoring project is changed to cat. war to start, so add the META-INF folder under the source code directory, add the app. properties file, the content is very simple:
App. name = cat
This name corresponds to the domain in the browser. If you want to change it to another name, the domain value should also be changed to the corresponding name.
Note: The META-INF folder must be changed to the specified format of the source file.
Running the code again has the following effect: the program will not be automatically closed, indicating that it is under monitoring ......
Check the log. Everything is normal:
[07-20 22:25:58.541] [INFO] [ChannelManager] Connected to CAT server at /127.0.0.1:2280[07-20 22:25:58.543] [INFO] [ChannelManager] success when init CAT server, new active holderactive future :/127.0.0.1:2280 index:0 ip:127.0.0.1 server config:null[07-20 22:25:58.545] [INFO] [DefaultModuleContext] Thread group(cat) created.[07-20 22:25:58.546] [INFO] [DefaultModuleContext] Starting thread(cat-TcpSocketSender-ChannelManager) ...[07-20 22:25:58.546] [INFO] [DefaultModuleContext] Starting thread(cat-TcpSocketSender) ...[07-20 22:25:58.547] [INFO] [DefaultModuleContext] Starting thread(cat-merge-atomic-task) ...[07-20 22:25:58.557] [INFO] [DefaultModuleContext] Starting thread(cat-StatusUpdateTask) ...
Refresh the cat page and find a new Transaction
And two event Events!
At this point, the application cat real-time monitoring system has been deployed successfully, and the rest is to study how the code can better use Cat!
========================================================== ============================
Sometimes you will find that no data is displayed on the Real-time Monitoring page. When you view the log records, you will find a lot of errors that cannot be found at 10.0.0.1: 2280:
In this case, we need to click Login in the upper-right corner and log on with the account and password catadmin. In the "client route" of the last "Global Alarm configuration" in "configuration", we will change it to 127.0.0.1: after 2280, submit and refresh the real-time page, and the data is back!