Using Cacti to monitor PHP

Source: Internet
Author: User
Tags php introduction

Cacti is not a stranger to the OPS, probably the most used monitoring tool now. Internet-related companies may use cacti to monitor the state of the server and the load of some software.

Now the site with the most back-end technology may be PHP, whether nginx or LIGHTTPD, today's load capacity is very strong, in a lot of cattle people's efforts, load tens of thousands of to 100,000 concurrent is not uncommon. However, this is in the case of complete static, plus PHP will be greatly reduced efficiency. So in fact, a dynamic site load capacity bottlenecks are often on top of PHP.

Many articles on the internet cacti how to monitor the number of nginx concurrency, but there is no information on how to monitor the working status of php article, I searched Google Baidu A circle, also did not find a Chinese monitoring php introduction article, so no idle nothing, a simple transformation of a template, Used to monitor the work of PHP-FPM. I believe many people in the country may have used it long ago, but have no time to say it.

The so-called transformation, that is not my original. The original author address
http://forums.cacti.net/viewtopic.php?f=12&t=41580
After I downloaded this template and tried it, I found it was not so easy to use, and needed support from modules like Fcgi::client and Lwp::useragent in Perl, which would be a headache for people unfamiliar with Perl and CPAN. This script in the Perl language also has security implications because he uses fcgi: CLIENT.PM module to directly access the PHP-FPM 9000 port, which requires your php-fpm monitoring in a other than the 127.0.0.1 of the other IP, so if you need to monitor the computer room, you will have to listen to PHP-FPM on an extranet IP, unless you specify PHP-FPM access IP or Users to do VPN. However, I think most companies do not have this technical strength, second, if more than the computer room, transformation configuration is also a very troublesome thing, change the wrong will give others to leave a 9000 port loophole, people directly frame an nginx point to PHP can do bad things.

So it took 5 minutes to modify the template slightly and rewrite the fetch script with the shell. PHP-FPM status monitoring to the Nginx, from the Web Access, not only support the cross-room visit, no need to expose 9000 ports on any IP address, Changes to the php-fpm.conf file are minimal, the only one is the need to retrofit Nginx, plus a configuration similar to the monitoring nginx. and requires curl support on the cacti server, but installing curl with yum or apt-get seems much simpler than installing the module with CPAN. The principle and the use of cacti monitoring nginx is the same. So, if you have done nginx monitoring, using this template is very simple.

However, this script also has a problem, that is, if you use a nginx with upstream back end to hang multiple php-fpm load balancing, may produce data inaccuracy problem. In this case, you can access the above connection, using the original direct access to the 9000 port way.

Tell me a few steps to use this script:

1. You need to change a line in the php-fpm.conf file
Locate Pm.status_path =/status and remove the preceding comment semicolon. Save exit

2. Open nginx.conf File
Add the following paragraph to the server{} paragraph, and be careful not to conflict with your Nginx status monitoring redirect path, and if it conflicts, modify the settings in the PHP-FPM and the settings in Nginx
Include Fastcgi_params;
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_param script_filename $fastcgi _script_name;
}

Save exit

3. Restart the PHP-FPM and restart the Nginx
Try to access http://yourserver/status to see if you can get php-fpm information, as normal, should appear as follows

Pool:www
Process Manager:dynamic
Start time:16/jun/2012:01:28:33 +0800
Start since:67269
Accepted conn:4526202
Listen queue:0
Max Listen queue:0
Listen Queue len:0
Idle processes:174
Active processes:1
Total processes:175
Max Active processes:23
Max Children reached:0

4. Upload the extracted shell script from the attachment to the Cacti/scripts folder of the cacti server. and give executable permissions. Perform a test to see if you can get to the PHP-FPM state.
./cacti_check_php-fpm.sh 114.xxx.xxx.xxx 80/status

5. Import the XML template in the attachment into cacti, and then create a new diagram on the device, you will see a php-fpm fastcgi status template, use it to create, and fill in the server IP port and path on it, refer to the test command line to write.

In the actual test, support PHP 5.3.8 and above, 5.3.8 before the PHP version is not tested, if there is a problem can modify the grep part of the script, a total of no more than 15 lines of the script, simple, a look at the understanding.

Monitor the effect.


        • This article is from: Linux Tutorial Network

Using Cacti to monitor PHP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.