Configure nginx to support rrdcgi

Source: Internet
Author: User
Tags rrd install perl

Configure nginx to support rrdcgi

I started to load the monitoring chart on the web interface. I used rrdrool graph to generate the chart, but I found that only the chart can be generated. So I tried rrdcgi and thought it was possible to plot the image. The result was still to create an image, and html was used to load the image. Finally, we found that the ganglia chart extracts the images generated in the temporary directory, uses php to generate headers, and then deletes the images. However, by the way, I learned how to configure the CGI program in nginx and remember it.

RRDCGI usage

First, write graph. cgi.

#!/usr/local/bin/rrdcgi <RRD::GRAPH      /services/cgi-bin/load.png      --imginfo ''      --lazy --title="load"      --start 1382666836 --end 1382677047      --width 705 --height 245      --alt-autoscale          DEF:load=/services/rrds/yin-arch_ac101eb8/load.rrd:load:AVERAGE          HRULE:1#ff0000:"warning value"      AREA:load#3d3d3d:load>

The syntax is almost the same as that of rrdgraph. There is nothing to say about it. This will generate an html code called

First, create a soft connection rrdgraph under webroot. The src of the image points to the rrdgraph folder, which is actually a soft connection, point to/services/cgi-bin/to facilitate nginx configuration.

How can I directly verify the plot in shell?

sudo rrdcgi graph.cgi < /dev/null(offline mode: enter name=value pairs on standard input)Content-Type: text/htmlContent-Length: 53 

Obviously, this image file load.png is obtained. Move the cgi file to the/services/cgi-bin/directory for standby.

Configuration supported by nginx for rrdcgi

First, install perl and use the following libraries: (The following versions may be too old and can be searched and installed directly on the CPAN website)

wget http://www.cpan.org/modules/by-module/FCGI/FCGI-0.67.tar.gztar -zxf FCGI-0.67.tar.gzcd FCGI-0.67perl Makefile.PLmake && make installcd ..wget http://search.cpan.org/CPAN/authors/id/G/GB/GBJK/FCGI-ProcManager-0.18.tar.gztar -zxf FCGI-ProcManager-0.18.tar.gzcd FCGI-ProcManager-0.18perl Makefile.PLmake && make installcd ..wget http://search.cpan.org/CPAN/authors/id/I/IN/INGY/IO-All-0.39.tar.gztar zxf IO-All-0.39.tar.gzcd IO-All-0.39perl Makefile.PLmake && make install

Install the nginx-fcgi script:

wget http://hily.me/blog/wp-content/uploads/2010/01/nginx-fcgi.txtmv nginx-fcgi.txt /usr/sbin/nginx-fcgichmod +x /usr/sbin/nginx-fcgi

If you do not need to run nginx-fcgi in sudo mode, comment out the following in the nginx-fcgi script:

if ( $> == “0″ ) {print “\n\tERROR\tRunning as a root!\n”;print “\tSuggested not to do so !!!\n\n”;exit 1;}

Start nginx-fcgi:

sudo nginx-fcgi -l /var/log/nginx/nginx-fcgi.log -pid /var/run/nginx-fcgi.pid -S /var/run/nginx-fcgi.sock

Note that you must add nginx account permissions for the socket; otherwise, the cgi operation fails. Create nginx-fcgi script command configuration and copy the template directly from fastcgi_params:

cp /etc/nginx/fastcgi_params /etc/nginx/nginx_fcgi_params

Remove the tail:

# PHP only, required if PHP was built with –enable-force-cgi-redirectfastcgi_param  REDIRECT_STATUS    200;

The final cgi site Configuration:

    location / {        root   /webroot;        index  index.html index.htm;    }    location ~ ^/cgi-bin/.*\.cgi$    {        fastcgi_index  index.cgi;        fastcgi_param  SCRIPT_FILENAME    /services$fastcgi_script_name;        include        nginx_fcgi_params;        fastcgi_read_timeout    5m;        fastcgi_pass   unix:/var/run/nginx-fcgi.sock;    }

Restart nginx. Access address: http: // 192.168.216.145/cgi-bin/graph. cgi

The figure already exists.

Reference

Http://oss.oetiker.ch/rrdtool/doc/rrdcgi.en.html

Http://wiki.qpsmtpd.org/doku.php? Id = resources: statistics: rrdcgi-sample

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.