varnish-nagios的安装使用
就目前来说,最流行的cache加速,应该算是varnish了,最流行的监控当然是nagios ———— 至少我是这样认为的。为了将varnish的stat进行很好的监控。varnish官方提供了varnish-nagios功能插件。用于整合到nagios的libexec里。下面就针对该插件,具体的介绍下其安装和使用。
一、下载安装
该包即可以在varnish官网上下到,同时也在github上有托管。官网下载地址是:http://repo.varnish-cache.org/source/,github项为:https://github.com/varnish/varnish-nagios 。两都提供的源码文件略有不同,官方的提供的是varnish-nagios-1.1.tar.gz文件,长久以来没进行过更新了,可以直接通过configure进行安装;github上的项目包也长久没有更新了,其不能直接进行configure安装,其通过运行autogen.sh脚本,生成configure文件。这里以github上的为例:
1./autogen.sh
2+ aclocal
3+ libtoolize --copy --force
4./autogen.sh: line 44: libtoolize: command not found
运行autogen时,可能会报上面的错误。报错是因为缺少libtool软件包,通过yum安装libtool包重新运行即可。运行完生成configure文件后,执行下面的操作进行安装:
1./configure --prefix=/App/nagios/
2…………………………………………………………
3checking for VARNISHAPI... no
4configure: error: Package requirements (varnishapi) were not met:
5No package 'varnishapi' found
6Consider adjusting the PKG_CONFIG_PATH environment variable if you
7installed software in a non-standard prefix.
8Alternatively, you may set the environment variables VARNISHAPI_CFLAGS
9and VARNISHAPI_LIBS to avoid the need to call pkg-config.
10See the pkg-config man page for more details.
运行过程中可能又会碰到上面的错误。当然,rpm包方式安装的varnish也会报这个错误。通过yum -y install varnish-libs时,仍然会上面的错。通过yum -y install varnish-libs-devel 。再执行上面的confiure语包,问题解决。我们来看下,两个包的文件内容有什么不同:
1[root@localhost ~]# rpm -ql varnish-libs
2/usr/lib64/libvarnishapi.so.1
3/usr/lib64/libvarnishapi.so.1.0.0
4/usr/share/doc/varnish-libs-3.0.3
5/usr/share/doc/varnish-libs-3.0.3/LICENSE
6[root@localhost varnish-nagios-master]# rpm -ql varnish-libs-devel
7/usr/include/varnish
8/usr/include/varnish/varnishapi.h
9/usr/include/varnish/vcli.h
10/usr/include/varnish/vsc.h
11/usr/include/varnish/vsc_all.h
12/usr/include/varnish/vsc_fields.h
13/usr/include/varnish/vsl.h
14/usr/include/varnish/vsl_tags.h
15/usr/include/varnish/vsm.h
16/usr/lib64/libvarnishapi.so
17/usr/lib64/pkgconfig/varnishapi.pc
18/usr/share/doc/varnish-libs-devel-3.0.3
19/usr/share/doc/varnish-libs-devel-3.0.3/LICENSE
因为varnish-nagios要同时依赖so文件的.h头文件,所以这两个包都是必须的。而如果是源码包安装的varnish,可以通过下面的方法解决:
1export LD_LIBRARY_PATH=/App/varnish/lib:$LD_LIBRARY_PATH
通过以上方法,可以让varnish-nagios可以通过pkgconfig里的varnishapi.pc文件知道varnish所有文件生成的路径。这样就可以通过下面的操作成功安装varnish-nagios了:
1./configure --prefix=/App/nagios/
2make && make install
注:上面的报错也可以通过改变/etc/ld.so.conf 文件并执行 /sbin/ldconfig 命令的方法解决。
二、使用
完成安装后,其只会生成一个文件check_varnish,通过上面的配置安装的话,该文件的生成路径是/App/nagios/libexec/check_varnish 。先看下其用法:
1[root@back libexec]# ./check_varnish -h
2usage: check_varnish [-lv] [-n varnish_name] [-p param_name [-c N] [-w N]]
3-v Increase verbosity.
4-n varnish_name Specify the Varnish instance name
5-p param_name Specify the parameter to check (see below).
6 The default is 'ratio'.
7-c [@][lo:]hi Set critical threshold
8-w [@][lo:]hi Set warning threshold
9All items reported by varnishstat(1) are available - use the
10identifier listed in the left column by 'varnishstat -l'. In
11addition, the following parameters are available:
12uptime How long the cache has been running (in seconds)
13ratio The cache hit ratio expressed as a percentage of hits to
14 hits + misses. Default thresholds are 95 and 90.
15usage Cache file usage as a percentage of the total cache space.
从上面的帮助文档上不难看出,其就是利用了varnishstat -1 (此处是一) 来获取数据并处理。但该插件功能显得很鸡肋。
其一, -c和-w对某些参数的监控不适用。这里就以默认的ration项为例好了:
1[root@back libexec]# ./check_varnish -w 80 -c 60
2VARNISH CRITICAL: Cache hit ratio (89)|ratio=89
我目前的命中率是89%,我想让命中率小于80%时告警,小于60%时严重告警。而其在命令中率在89%时就已经严重告警。
其二,-p参数不支持多参数:
1[root@back libexec]# ./check_varnish -p LCK.ban.colls -w 1 -c 2 -p SMA.s0.c_req -w 5320688 -c 6320603
2VARNISH WARNING: Allocator requests (5,323,425)|SMA.s0.c_req=5323425
如上,我随意取了两个参数,可以发现,其真正有效使用的只是后一个参数。估计这也是该插件长久得不到更新的原因,但其也并非一无是处。对一些参数的检测上(如:varnish内存使用情况),其还是适用的。而其不适用的参数,个人感觉使用varnishstat -1配合脚本实现应该更好。
参考页面:
http://terraltech.com/monitoring-vanish-server-with-shinken/
https://www.varnish-cache.org/utilities
http://hi.baidu.com/3444542/item/a752144400cc4595833ae193
捐赠本站(Donate)
如您感觉文章有用,可扫码捐赠本站!(If the article useful, you can scan the QR code to donate))
- Author: shisekong
- Link: https://blog.361way.com/varnish-nagios/2427.html
- License: This work is under a 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议. Kindly fulfill the requirements of the aforementioned License when adapting or creating a derivative of this work.