Difference between revisions of "Nginx: Monitoring Statistics"

From OnnoWiki
Jump to navigation Jump to search
(New page: This script is very easy to install and configure. You can use following steps to get pretty stats graph for your nginx-powered server: Modify your nginx config file and add following loc...)
 
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
This script is very easy to install and configure. You can use following steps to get pretty stats graph for your nginx-powered server:
+
Script untuk monitoring statistics Nginx relatif mudah di instalasi dan di konfigurasi. Kita perlu melakukan langkah berikut untuk memperoleh gambar statistik dari server nginx.
  
Modify your nginx config file and add following location to it:
+
Ubah konfigurasi file ngix dan tambahkan kalimat berikut
 +
 
 +
vi /etc/nginx/sites-enabled/default
  
 
  http {
 
  http {
+
 
server {
+
    server {
listen SOME.IP.ADD.RESS;
+
      listen SOME.IP.ADD.RESS;
+
     
location /nginx_status {
+
      location /nginx_status {
stub_status on;
+
        stub_status on;
access_log  off;
+
        access_log  off;
allow SOME.IP.ADD.RESS;
+
        allow SOME.IP.ADD.RESS;
deny all;
+
        deny all;
}
+
        }
+
   
}
+
    }
+
 
 
  }
 
  }
  
Test your config file with following command:
+
Test file konfigurasi
 +
 
 +
/etc/init.d/nginx stop
 +
/usr/sbin/nginx -t
 +
 
 +
the configuration file /etc/nginx/nginx.conf syntax is ok
 +
configuration file /etc/nginx/nginx.conf test is successful
 +
 
  
# /your/installation/sbin/nginx -t
+
Jika ada error tentang stub_status, check nginx. Nginx harusnya di konfigurasi dengan —-with-http_stub_status_module. Jika semua OK menggunakan shell lakukan test
  2006/04/29 04:24:36 [info] 31676#0: the configuration file /opt/nginx/conf/nginx.conf syntax is ok
+
   
  2006/04/29 04:24:36 [info] 31676#0: the configuration file /opt/nginx/conf/nginx.conf was tested successfully
+
  # GET http://hostname.anda/nginx_status
  
#
+
  Active connections: 1
# If you will get error about stub_status directive, check your nginx – it should be configured with —-with-http_stub_status_module option. If your configuration is OK, you can restart nginx and test it:
 
# GET http://your-domain.com/nginx_status
 
  Active connections: 1492
 
 
  server accepts handled requests
 
  server accepts handled requests
2124355 2124355 8278635
+
  1 1 1
  Reading: 6 Writing: 405 Waiting: 1081
+
  Reading: 0 Writing: 1 Waiting: 0
Download  perl script: rrd_nginx.pl and make it executable with
+
 
 +
Download  perl script: rrd_nginx.pl dan jadikan executable
 +
 
 +
cd /usr/local/src/
 +
wget http://kovyrin.net/files/mrtg/rrd_nginx.pl.txt
 +
mv rrd_nginx.pl.txt rrd_nginx.pl
 +
chmod +x rrd_nginx.pl
 +
 
 +
Install rrd tools
 +
 
 +
apt-get install rrdcollect rrdtool rrdtool-tcl librrds-perl libgd-gd2-perl wget
  
  # chmod +x rrd_nginx.pl
+
  mkdir /var/lib/nginx/rrd
  Change settings in rrd_nginx.pl to let script know where it will save rrd-base and images:
+
  mkdir /var/lib/nginx/rrd/html
 +
 
 +
Ubah setting di rrd_nginx.pl agar script tahu dimana menyimpan rrd-base dan image
 +
 
 +
vi /usr/local/src/rrd_nginx.pl
  
 
  #!/usr/bin/perl
 
  #!/usr/bin/perl
 
  use RRDs;
 
  use RRDs;
 
  use LWP::UserAgent;
 
  use LWP::UserAgent;
 
+
 
  # define location of rrdtool databases
 
  # define location of rrdtool databases
  my $rrd = ‘/opt/rrd’;
+
  my $rrd = ‘/var/lib/nginx/rrd’;
 
  # define location of images
 
  # define location of images
  my $img = ‘/opt/rrd/html’;
+
  my $img = ‘/var/lib/nginx/rrd/html’;
 
  # define your nginx stats URL
 
  # define your nginx stats URL
  my $URL = “http://your-domain.com/nginx_status”;
+
  my $URL = “http://hostname.anda/nginx_status”;
 +
 
 +
Selanjutnya setup cron
  
Last step is to insert following string to /etc/crontab file and to restart cron daemon:
+
crontab -e
  
  * *     * * *  root    /some/path/rrd_nginx.pl When all preparations will be finished, you get  images in your $img directory:
+
  0 * * * * /usr/local/src/rrd_nginx.pl
  
 +
Jika semua persiapan telah dilakukan dengan baik maka kita akan melihat image di folder
  
 +
/var/lib/nginx/rrd/html
  
 
==Referensi==
 
==Referensi==

Latest revision as of 16:58, 22 February 2011

Script untuk monitoring statistics Nginx relatif mudah di instalasi dan di konfigurasi. Kita perlu melakukan langkah berikut untuk memperoleh gambar statistik dari server nginx.

Ubah konfigurasi file ngix dan tambahkan kalimat berikut

vi /etc/nginx/sites-enabled/default 
http {
  …
    server {
      listen SOME.IP.ADD.RESS;
      …
      location /nginx_status {
        stub_status on;
        access_log   off;
        allow SOME.IP.ADD.RESS;
        deny all;
        }
    …
    }
  …
}

Test file konfigurasi

/etc/init.d/nginx stop
/usr/sbin/nginx -t
the configuration file /etc/nginx/nginx.conf syntax is ok
configuration file /etc/nginx/nginx.conf test is successful


Jika ada error tentang stub_status, check nginx. Nginx harusnya di konfigurasi dengan —-with-http_stub_status_module. Jika semua OK menggunakan shell lakukan test

# GET http://hostname.anda/nginx_status
Active connections: 1 
server accepts handled requests
 1 1 1 
Reading: 0 Writing: 1 Waiting: 0 

Download perl script: rrd_nginx.pl dan jadikan executable

cd /usr/local/src/
wget http://kovyrin.net/files/mrtg/rrd_nginx.pl.txt
mv rrd_nginx.pl.txt rrd_nginx.pl
chmod +x rrd_nginx.pl

Install rrd tools

apt-get install rrdcollect rrdtool rrdtool-tcl librrds-perl libgd-gd2-perl wget
mkdir /var/lib/nginx/rrd
mkdir /var/lib/nginx/rrd/html

Ubah setting di rrd_nginx.pl agar script tahu dimana menyimpan rrd-base dan image

vi /usr/local/src/rrd_nginx.pl
#!/usr/bin/perl
use RRDs;
use LWP::UserAgent;

# define location of rrdtool databases
my $rrd = ‘/var/lib/nginx/rrd’;
# define location of images
my $img = ‘/var/lib/nginx/rrd/html’;
# define your nginx stats URL
my $URL = “http://hostname.anda/nginx_status”;

Selanjutnya setup cron

crontab -e
0 * * * * /usr/local/src/rrd_nginx.pl

Jika semua persiapan telah dilakukan dengan baik maka kita akan melihat image di folder

/var/lib/nginx/rrd/html

Referensi

Pranala Menarik