Use nginx-rrd in CentOS to monitor the number of nginx shards

Source: Internet
Author: User
Tags rrd rrdtool

You can use monitoring programs such as cacti and nagios to monitor nginx servers, but sometimes it is not that complicated. You can use nginx-rrd to monitor connections and requests.

First, compile and install nginx. Pay attention to loading the stub_status module. The stub_status module in Nginx is mainly used to view some Nginx status information.
This module is not compiled into Nginx by default. If you want to use this module, you must specify

 
 
  1. tarxzvfnginx-1.2.0.tar.gz
  2. cdnginx-1.2.0
  3. ./configure--prefix=/usr/local/nginx--with-http_stub_status_module
  4. make&&makeinstall

Install the relevant perl and rrdtool rpm packages in yum

 
 
  1. yuminstallperlrrdtoolperl-libwww-perllibwww-perlperl-rrdtool
After confirming that rrdtool and corresponding perl are installed, start to install nginx-rrd
 
 
  1. Tarzxvfnginx-rrd-0.1.4.tgz
  2. Cdnginx-rrd-0.1.4
  3. Cp-pusr/sbin/*/usr/sbin // copy the master program file to/usr/sbin.
  4. Cp-petc/nginx-rrd.conf/etc // copy the configuration file to/etc
  5. Create nginx-rrd directory
  6. Mkdir/usr/local/nginx/html/rrd
  7. Cphtml/index. php/usr/local/nginx/html
Here, we recommend you change the default access password WCO in the index. php file.

Edit/etc/nginx-rrd.conf

 
 
  1. vim/etc/nginx-rrd.conf
  2. #####################################################
  3. #
  4. #dirwhererrddatabasesarestored
  5. RRD_DIR="/usr/local/nginx/html/rrd";
  6. #dirwherepngimagesarepresented
  7. WWW_DIR="/usr/local/nginx/html";
  8. #processnicelevel
  9. NICE_LEVEL="-19";
  10. #bindir
  11. BIN_DIR="/usr/sbin";
  12. #serverstotest
  13. #server_utl;server_name
  14. SERVERS_URL="http://www.linuxom.com/nginx_status;www.linuxom.com"

Multiple virtual hosts can be separated by spaces in SERVERS_URL. The front part is the address of nginx_status, followed by the Domain Name of the monitored host.

Check whether the installed nginx contains the stub_status module.

 
 
  1. /usr/local/nginx/sbin/nginx-V
  2. nginxversion:Nginx/1.2.0
  3. configurearguments:--with-http_stub_status_module

Confirm that the stub_status module is supported and edit and modify nginx. conf.

 
 
  1. Vim/usr/local/nginx/conf/nginx. conf
  2. // Add the following content to server {}:
  3. Location /{
  4. Roothtml;
  5. Indexindex.phpindex.htmlindex.htm;
  6. Location/nginx_status {
  7. Stub_statuson; // This option parameter is supported by the stub_status module during compilation. If it is not compiled, a warning will be generated when nginx is started.
  8. Access_logoff;
  9. }
  10. }
  11. # Error_page404/404.html;
  12. # Redirectservererrorpagestothestaticpage/50x.html
  13. #
  14. Error_page500502503504/50x.html;
  15. Location =/50x.html {
  16. Roothtml;
  17. }
  18. # ProxythePHPscriptstoApachelisteningon127.0.0.1: 80
  19. #
  20. # Location ~ \. Php $ {
  21. # Proxy_passhttp: // 127.0.0.1;
  22. #}
  23. # PassthePHPscriptstoFastCGIserverlisteningon127.0.0.1: 9000
  24. #
  25. // Remove the annotation of the following content, which is supported by php. Note the file path.
  26. Location ~ \. Php $ {
  27. Roothtml;
  28. Fastcgi_pass127.0.0.1: 9000;
  29. Fastcgi_indexindex.php;
  30. Fastcgi_paramSCRIPT_FILENAME/usr/local/nginx/html $ fastcgi_script_name;
  31. Includefagi_params;
  32. }

Restart Nginx Server

 
 
  1. /usr/local/nginx/sbin/nginx-sreload

Set timed data collection

 
 
  1. crontab-e
  2. *****root/usr/sbin/nginx-collect
  3. */10****root/usr/sbin/nginx-graph
Access page http: // domain name/index. php, the number of nginx connections such

The number of nginx requests is as follows:

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.