Tideways and xhgui build PHP non-intrusive monitoring platform

Read the full text http://click.aliyun.com/m/23007/
What should we do when we find that an interface in the production environment takes a long time to execute? Do you directly log in to the online machine for single-step debugging? Or do a lot of log and then analyze? Generally, we can divide the analysis process into the following steps:

The MarkDown rendering of the Yunqi community is too bad, and the numbers are misplaced. Let's go to my blog and see Tideways and xhgui to build a PHP non-intrusive monitoring platform

Analysis and development environment

If it is a code problem, it can be detected in the development environment; analyze whether the execution

of the pre-release environment will be slow;

if it is a database or third-party extension problem, it can be checked in the pre-release environment.

Pick a machine from the production environment and analyze the reason for the slow execution of the code;

if it is a problem with the machine, it can be checked in the production environment.

Steps 1, 2, and 3 all need to analyze the code to see which part takes a long time to execute. If you manually check the code line by line, it will easily lead to the loss of users. Most of the time we will use third-party analysis tools tideways or xhprof to quickly find problems. Which tool is better to choose? Although xhprof comes from facebook, it has not been updated for a long time. The official source has shown that This package is abandoned and no longer maintained. Tideways is just the opposite, there have been commercial companies in maintenance, and actively support PHP7. Both extensions are open source. To sum up, I recommend everyone to choose tideways to analyze the code.

The tideways extension can generate detailed execution logs for each request. We can see which part of the program takes the longest time by simply analyzing the logs. Here we can use the UI program of xhprof (logs generated by xhprof and logs generated by tideways). The format is common), although the interaction is not very friendly, it is enough. If you want better visual effects, it is recommended to download xhgui, a Bootstrap-based xhprof UI program.

Before I start building a PHP non-intrusive monitoring platform, I need to explain a few things.

1. How does Tideways make money?
Tideways, a company like Sentry's marketing model, sells storage services + data analysis services.

The tideways.so extension is open source and free to use. But the treadways.so extension can only generate log files, and it takes a long time to sort and analyze the log files after we get them. If you purchase Tideways' service, you can seamlessly store logs to their server, and log in to the background provided by them to see the project code and server operation status. Coupled with various visual chart displays, the experience is very good, and many large companies are willing to pay.

2. Will the code change greatly after installing the extension?
The monitoring method provided by the tideways.so extension is non-intrusive monitoring and will not have any impact on the current project. We only need to add a line of configuration to the Nginx configuration file:

fastcgi_param PHP_VALUE "auto_prepend_file=/home/admin/xhgui/external/header.php";

The meaning of the code: run the PHP script we specified before executing the main program
Specifically how to install this service, I will explain in detail in the second half of the article. Now we need to know that "non-intrusive monitoring" means not changing a single line of project code.

3. Will generating logs for each request affect the service itself?
Generating an execution log for each request from a user has a slight impact on the service. Although the monitoring method provided by the tideways.so extension is non-intrusive and does not affect online projects, the consumption of CPU and memory cannot be ignored. In order to reduce the consumption of memory and CPU, we can control the frequency of generating logs and write rules for generating logs. The default frequency is 1% (1 log is generated every 100 requests, the probability here is not absolute).

If there are multiple servers, only one needs to be monitored. If there are many machines, one can be used in each computer room.

Build a non-intrusive monitoring environment
Read full article http://click.aliyun.com/m/23007/

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326218855&siteId=291194637