步骤:
1、下载网络流量监控脚本:
https://raw.githubusercontent.com/June-Wang/NagiosPlugins/master/check_net_traffic.sh
上传到/usr/local/nagios/libexec(根据自己的环境修改)
2、pnp模板:
https://raw.githubusercontent.com/June-Wang/NagiosPlugins/master/check_net_traffic.php
上传到/usr/local/pnp4nagios/share/templates.dist/(根据自己的环境修改)
- <?php
- /*
- * Copyright (c) 2012 Jason Hancock <jsnbyh@gmail.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is furnished
- * to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the nagios-puppet bundle that can be found
- * at https://github.com/jasonhancock/nagios-memory
- */
- $alpha = 'CC';
- $colors = array(
- '#00FF00' . $alpha,
- '#000066' . $alpha,
- '#25345C' . $alpha,
- '#88008A' . $alpha,
- '#4F7774' . $alpha,
- );
- $opt[1] = sprintf('-T 55 -l 0 --vertical-label "Bytes" --title "%s / Network Traffic"', $hostname);
- $def[1] = '';
- $count = 0;
- foreach ($DS as $i) {
- $def[1] .= rrd::def("var$i", $rrdfile, $DS[$i], 'AVERAGE');
- if ($i == '1') {
- $def[1] .= rrd::area ("var$i", $colors[$count], rrd::cut(ucfirst($NAME[$i]), 15));
- } else {
- $def[1] .= rrd::line1 ("var$i", $colors[$count], rrd::cut(ucfirst($NAME[$i]), 15), 'STACK');
- }
- $def[1] .= rrd::gprint ("var$i", array('LAST','MAX','AVERAGE'), "%4.2lf %s\t");
- $count++;
- }
用法:
1、将以下命令行添加到nrpe.cfg
echo 'command[check_net_traffic]=/usr/local/nagios/libexec/check_net_traffic.sh -d eth0 -w 7m -c 10m' >> /usr/local/nagios/etc/nrpe.cfg
参数说明:
-d 是要监控的网卡名
-w -c 是设定的阀值,只能是b、k、m、g,大小写均可,单位是大B(字节),需要说明的是这个阀值是上行(上传)和下行(下载)的总和。
2、将pnp模板考到Nagios Server 的pnp文件夹:
cp check_net_traffic.php /usr/local/pnp4nagios/share/templates.dist/
3、Nagios Server主机配置文件中加入
define service{
use dpmc-service,srv-pnp
host_name backup
service_description Check Net
check_command check_nrpe!check_net_traffic
contact_groups system
}
注意:
1、脚本第一次运行时,会将当前网卡的相关数值写到临时文件中,临时文件会保存在/usr/local/nagios/libexec/下。
2、(未核实)流量图Y轴的单位是上行和下行的总和,累加关系,不是表示输出比输入高。(未核实)
以下是效果图: