nagios监控是一种常用的监控软件,同时,有个很大的缺点,就是没法展现旧的历史数据,服务状态趋势,言简意赅的说,就是缺少绘图。
nagios相关资料参见本博客上的内容:http://www.ttlsa.com/?s=nagios
原理:
使用service_perfdata_file_processing_command指令,将nagios监控到的每个服务数据,传递给 /usr/local/nagiosgraph/bin/insert.pl脚本处理,生产rrd文件。
下面来说说Nagiosgraph的配置:
1. 获取组件
1
2
3
|
# wget http://downloads.sourceforge.net/project/nagiosgraph/nagiosgraph/1.4.4/nagiosgraph-1.4.4.tar.gz
# tar -xzf nagiosgraph-1.4.4.tar.gz
# cd nagiosgraph-1.4.4
|
2. 检测环境要求
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# ./install.pl --check-prereq
checking
required
PERL
modules
Carp
.
.
.
1.04
CGI
.
.
.
3.15
Data
::
Dumper
.
.
.
2.121_08
File
::
Basename
.
.
.
2.74
File
::
Find
.
.
.
1.10
MIME
::
Base64
.
.
.
3.07
POSIX
.
.
.
1.09
RRDs
.
.
.
1.2027
Time
::
HiRes
.
.
.
1.9717
checking
optional
PERL
modules
GD
.
.
.
2.35
checking
nagios
installation
found
nagios
at
/
usr
/
local
/
nagios
/
bin
/
nagios
checking
web
server
installation
found
apache
at
/
usr
/
sbin
/
httpd
|
缺少哪些perl模块,就安装那些模块,同时还要注意版本的要求。
3. 安装
1
|
.
/
install
.
pl
--
install
|
一路按回车键。
4. 编辑nagios.cfg文件
在nagios.conf文件下,添加以下内容
1
2
3
4
5
6
7
|
# process nagios performance data using nagiosgraph
process_performance_data
=
1
service_perfdata_file
=
/
tmp
/
perfdata
.
log
service_perfdata_file_template
=
$
LASTSERVICECHECK
$
||
$
HOSTNAME
$
||
$
SERVICEDESC
$
||
$
SERVICEOUTPUT
$
||
$
SERVICEPERFDATA
$
service_perfdata_file_mode
=
a
service_perfdata_file_processing_interval
=
30
service_perfdata_file_processing_command
=
process
-
service
-
perfdata
-
for
-
nagiosgraph
|
5. 编辑commands.cfg文件
添加以下内容
1
2
3
4
5
6
7
8
9
|
#########################################
#
# nagiosgraph
#
# command to process nagios performance data for nagiosgraph
define
command
{
command_name
process
-
service
-
perfdata
-
for
-
nagiosgraph
command_line
/
usr
/
local
/
nagiosgraph
/
bin
/
insert
.
pl
}
|
6. 修改httpd.conf文件
添加以下内容
1
|
Include
/
usr
/
local
/
nagiosgraph
/
etc
/
nagiosgraph
-
apache
.
conf
|
7. 重新启动服务
1
2
|
# /etc/init.d/httpd restart
# /etc/init.d/nagios restart
|
8. 查看nagiosgraph配置信息
在浏览器输入:http://10.0.100.125/nagiosgraph/cgi-bin/showconfig.cgi网址查看。
9. 定义动作URL
修改templates.cfg文件,添加以下内容:
1
2
3
4
5
|
define
service
{
name
nagiosgraph
action_url
/
nagiosgraph
/
cgi
-
bin
/
show
.
cgi
?
host
=
$
HOSTNAME
$
&
service
=
$
SERVICEDESC
$
register
0
}
|
10. 添加你需要的绘图
默认情况下,启用Performance Data的服务都会绘图。
实例如下:
1
2
3
4
5
6
7
|
define
service
{
use
MongoDB
,
nagiosgraph
hostgroup_name
MongoDB_Servers
service_description
Mongo
Memory
Usage
check_command
check_mongodb
!
12345
!
''
!
''
!
memory
!
130
!
260
servicegroups
Mongodbservices
}
|
添加完,会有个下面的图标
11. 效果如下
12. 每个服务项都会有个rrd文件
在/usr/local/nagiosgraph/var/rrd目录下的各自主机子目录下
对于无法生成Performance Data数据,将无法绘图,出现nagiosgraph no data available信息,查看nagiosgraph.log出现下面信息:
322207-Tue Apr 8 17:18:36 2014 insert.pl warn output/perfdata not recognized:
322279:hostname:X.X.X.X
322299-servicedesc:Mongo Free Connections
322334-output:OK - 6 percent (52 of 819 connections) used
322385-perfdata:
perfdata为空,这就需要我们自己去对output信息进行解析了。通过/usr/local/nagiosgraph/etc/map这个文件,来定义正则表达式来处理,该文件是个perl脚本,来将output信息映射到perfdata。
map如何自定义正则表达式下节再说,请关注。
转载请注明:成长的对话 » Nagios Nagiosgraph配置