Monitor the working status of php-fpm with cacti

Source: Internet
Author: User

There are no strangers to cacti O & M personnel. It may be the most widely used monitoring tool. Internet-related companies may use cacti to monitor the server running status and the load of some software.

Currently, php is the most widely used backend technology for websites. No matter nginx or lighttpd, the load capacity is very strong today. With the efforts of many cool people, tens of thousands to 100,000 concurrent loads are not uncommon. However, it is completely static, and adding php will greatly reduce the efficiency. In fact, the load capacity bottleneck of a dynamic website is usually above php.

Many articles on the Internet show you how cacti monitors the number of nginx concurrent jobs. However, I haven't published any articles about how to monitor the working status of php. I searched Google Baidu, I didn't find an introduction to monitoring php in Chinese, so I was not idle. I simply transformed a template to monitor the working conditions of php-fpm. I believe many people in China may have used it for a long time, but they have no time to say it.

The so-called transformation is not my original. Original Author address in
Http://forums.cacti.net/viewtopic.php? F = 12 & amp; t = 41580
After downloading this template, I tried it and found that it was not so easy to use. I needed support from FCGI: Client and LWP: UserAgent modules in perl, this is a headache for people who are not familiar with perl and cpan. This script in perl has security risks because it uses FCGI: Client. the pm module directly accesses the port 9000 of the php-fpm, which requires your php-fpm to be monitored on another IP address except 127.0.0.1. In this way, if you need cross-Data Center monitoring, it is necessary to monitor the php-fpm on an Internet IP address unless you specify the php-fpm access IP address or make a VPN. However, I think most companies do not possess this technical strength. Second, if there are more data centers, it is also very troublesome to modify configurations, if you make a mistake, you will be given a 9000 Port vulnerability, and someone else will direct an nginx to php to do something bad.

So it took 5 minutes to slightly modify the template and use shell to overwrite the script. Jump php-fpm status monitoring to nginx, get from the web page, both support cross-Data Center access, without exposing port 9000 on any IP address, the minimum change to the php-fpm.conf file, the only one is to modify nginx and add a configuration item similar to monitoring nginx. It also requires curl support on the cacti server, but installing curl with yum or apt-get seems much easier than installing the module with cpan. The principle is the same as monitoring nginx with cacti. Therefore, if you have done nginx monitoring, it is very easy to use this template.

However, this script also has a problem, that is, if you use nginx to mount multiple php-fpm load balancing servers with the upstream backend, data may be inaccurate. In this way, you can access the above connection by directly accessing port 9000 in the original version.

To use this script, perform the following steps:

1. You need to change the line in the php-fpm.conf File
Find pm. status_path =/status, and remove the comment semicolon. Save and exit

2. Open the nginx. conf file
Add the following section to the server {} segment. Be sure not to conflict with the redirection path of your nginx status monitoring. If the redirection path conflicts, modify the settings in php-fpm and nginx at the same time.
Include fastcgi_params;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_param SCRIPT_FILENAME $ fastcgi_script_name;
}

Save and exit

3. Restart php-fpm and nginx
Access http: // yourserver/status to check whether php-fpm information can be obtained.

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 shell script extracted from the attachment to the cacti/scripts folder of the cacti server. And grant the executable permission. Run the test to check whether the php-fpm status can be obtained.
Cacti_check_php-fpm.sh 114. xxx 80/status

5. import the xml template in the attachment to cacti, and then you will see a php-fpm fastcgi status template when creating a new graph on the device. Use it to create the template, and fill in the server IP port and path, you can refer to the test command line to write.

In actual tests, php 5.3.8 and later versions are supported. php versions earlier than 5.3.8 are not tested. If any problem exists, modify the grep part of the script. A total of 15 lines of scripts are supported, easy to understand.

Monitoring results.


 

Related Article

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.