海运的博客

Nagios配置pnp4nagios支持图表显示

发布时间:June 3, 2012 // 分类:Nagios // No Comments

Nagios配合pnp4nagios可实现类似Cacti的图表显示,便于管理和分析服务器运行状况。
Nagios安装请参考:https://www.haiyun.me/archives/centos-install-nagios.html
安装rrdtool,需安装epel源

#https://www.haiyun.me
yum install rrdtools perl-rrdtool perl-Time-HiRes

安装php4nagios:

wget http://nchc.dl.sourceforge.net/project/pnp4nagios/PNP-0.6/pnp4nagios-0.6.17.tar.gz
tar zxvf pnp4nagios-0.6.17.tar.gz 
cd pnp4nagios-0.6.17
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make all
make install
make install-webconf
make install-config
make install-init
#make fullinstall #相当于上面3个指令

配置php4nagios:

#https://www.haiyun.me
cd /usr/local/pnp4nagios/etc/
mv misccommands.cfg-sample misccommands.cfg
mv rra.cfg-sample rra.cfg
mv nagios.cfg-sample nagios.cfg
cd pages/
mv web_traffic.cfg-sample web_traffic.cfg
cd ../check_commands/
mv check_all_local_disks.cfg-sample check_all_local_disks.cfg
mv check_nrpe.cfg-sample check_nrpe.cfg
mv check_nwstat.cfg-sample check_nwstat.cfg
/etc/init.d/npcd start
chkconfig npcd on

配置Nagios数据输出接口:

vim /usr/local/nagios/etc/nagios.cfg 
process_performance_data=1 #默认为0,修改为1
host_perfdata_command=process-host-perfdata #注释开头#号
service_perfdata_command=process-service-perfdata #注释开头#号

替换commands.cfg命令process-service-perfdata为以下内容:

vim /usr/local/nagios/etc/objects/commands.cfg 
# 'process-host-perfdata' command definition
define command{
        command_name    process-host-perfdata
        command_line    /usr/local/pnp4nagios/libexec/process_perfdata.pl -d HOSTPERFDATA 
        }
# 'process-service-perfdata' command definition
define command{
        command_name    process-service-perfdata
        command_line    /usr/local/pnp4nagios/libexec/process_perfdata.pl
        }                              

在模板配置文件中添加图表图标模板:

#https://www.haiyun.me
 vim /usr/local/nagios/etc/objects/templates.cfg 
define host {
name          host-pnp
action_url    /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=_HOST_
register   0
}
define service {
name         service-pnp
action_url   /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=$SERVICEDESC$
register   0
}

复制鼠标悬停图标显示文件:

cp /usr/local/pnp4nagios/contrib/ssi/* /usr/local/nagios/share/ssi/ 

在监控主机或服务中调用图表模板:

define host{
        use                     linux-server,host-pnp                             
        host_name               localhost
        alias                   localhost
        address                 127.0.0.1
        }
define service{
        use                             local-service,service-pnp
        host_name                       localhost
        service_description             PING
    check_command            check_ping!100.0,20%!500.0,60%
        }
define service{
        use                             local-service,service-pnp
        host_name                       localhost
        service_description             Root Partition
    check_command            check_local_disk!20%!10%!/
        }

重启nagios,访问nagios界面即可看到图表小图标:
nagios图表图标.png
点击图标会显示pnp4nagios测试页面:
pnp4nagios测试页面.png
全是绿色代表配置正常,然后移除或修改install.php文件:

rm -rf /usr/local/pnp4nagios/share/install.php

再次点击图标就会显示当前监控服务由pnp4nagios生成的图表了:
nagios图表pnp4nagios.png

分类
最新文章
最近回复
  • 海运: ups不知有没选项可设置此参数,不过你可以在另外一台电脑上安装nut客户端自动关机。
  • kgami: 想请教一下,设置了的电脑自动关机之后,几秒后UPS怎么也跟着关机了,导致另外一台电脑没关机就断...
  • 海运: 写的很详细了啊,/etc/nut/hosts.conf用以nut-cgi连接nut服务器参数,...
  • ryan: 请问下nginx配置好了,怎么和这个nut链接呢?最后可视化管理这块能给个详细一点的教程么?谢谢。
  • 1: /etc/config/fstab配置文件 https://openwrt.org/zh/do...
  • 听雨看雪: 找了好久,终于找到UP主,给出的正确解决方案,太感谢了,困扰大半年的问题,重装了N道PVE系统...
  • zr: 大佬,这个bash-completion是从哪个源搞到的
  • 姚生: 要要下载
  • 阿东: 我在编译树莓派的时候也遇到同样的问题,后来发现是make menuconfig 的时候忘了带环...
  • crowjin: 你确定这能过滤??不是所有请求都返回空地址::?