Skip to content


cacti 监控 nginx status 支持ip及用户验证

Cacti监控主机:192.168.0.1

Nginx被监控服务器:192.168.0.2

1。首先在编译nginx时允许http_stub_status_module,不然是监控不到nginx的运行状态的

2。编辑配置文件,在要监控的虚拟主机里加入如下内容:

# vi /opt/nginx/conf/nginx.conf
###nginx monitor
location /nginx_status {
stub_status on;
access_log off;
allow 192.168.0.1;
deny all;
}

3。重新加载nginx的配置文件

# /etc/init.d/nginx restart

4。下载cacti for nginx插件包

# wget http://forums.cacti.net/download.php?id=12676
解压后一共有5个文件

# tar xvfz cacti-nginx.tar.gz

cp get_nginx_clients_status.pl /scripts/
cp get_nginx_socket_status.pl /scripts/
chmod 0755 /scripts/get_nginx_socket_status.pl
chmod 0755 /scripts/get_nginx_clients_status.pl

5。 检查插件
get_nginx_clients_status.pl http://nginx.server.tld/nginx_status

可以看到如下返回:

nginx_accepts:113869 nginx_handled:113869 nginx_requests:122594

6。在后台导入模板文件Import Templates->
Import Template from Local File
把2个监控模板文件导入
cacti_graph_template_nginx_clients_stat.xml
cacti_graph_template_nginx_sockets_stat.xml

7。添加图表
New Graphs 选择已有Devices在Associated Graph Templates中添加
Nginx Clients Stat
保存后输入地址如:http://192.168.0.2/nginx
过几分钟就可以看到图表

nginx status 带身份认证

auth_basic “Web_ADMIN”;
auth_basic_user_file htpasswd;

方法一:
使用带认证的地址
http://username:[email protected]/nginx

方法二:
修改下get_nginx_clients_status.pl ,把adminname和password换成你的。
适用于所有的主机都使用相同的用户和密码。

15 my $ua = LWP::UserAgent->new(timeout => 5);
16 my $req = HTTP::Headers->new;
17 $req = HTTP::Request->new(GET => $ARGV[0]);
18
19 $req->authorization_basic(‘adminname’,’password’);
20
21 #my $response = $ua->request(HTTP::Request->new(‘GET’,$ARGV[0]));
22 my $response = $ua->request($req);
23
24 my @content = split (/\n/, $response->content);

cacti_nginx

参考:
http://forums.cacti.net/about26458.html
http://www.sitepoint.com/forums/showthread.php?t=597455

Posted in Cacti, 技术.

Tagged with , , .


No Responses (yet)

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.