欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Nginx+SmokePing 实践

程序员文章站 2022-03-20 13:10:08
...

Nginx+SmokePing安装配置


SmokePing是一款完全免费的可以用来监控IDC网络质量的工具,并且它有一个基于RRDTool绘图的前端展示界面,用户可以直观的通过浏览器查看各类监控信息。

SmokePing

安装epel源:

yum -y install epel-release

安装绘图工具:

yum -y install rrdtool perl-rrdtool

安装smokeping所需扩展:

yum -y install perl-core openssl-devel fping curl gcc-c++

下载SmokePing源码:

wget https://oss.oetiker.ch/smokeping/pub/smokeping-2.6.11.tar.gz

编译安装:

tar xf smokeping-2.6.11.tar.gz
cd smokeping-2.6.11
./configure --prefix=/usr/local/smokeping 
会报错,然后根据提示运行SmokePing给我们准备的脚本,来自动帮我们安装依赖:
./setup/build-perl-modules.sh /usr/local/smokeping/thirdparty
重新编译:
./configure --prefix=/usr/local/smokeping
make install    #直接make install即可

配置smokeping:

cd /usr/local/smokeping/htdocs/     #进入到SmokePing的WEB目录
mkdir {cache,data,var}              #新建三个目录
mv smokeping.fcgi.dist smokeping.fcgi

cd /usr/local/smokeping/etc/        #进入到smokeping的etc目录内
chmod 600 /usr/local/smokeping/etc/smokeping_secrets.dist   #修改权限
cp config.dist config               #复制一份配置文件

编辑config文件,修改imgcache、datadir、piddir的路径
imgcache = /usr/local/smokeping/htdocs/cache
datadir  = /usr/local/smokeping/htdocs/data
piddir  = /usr/local/smokeping/htdocs/var

修改一个你准备监控的服务器或是VPSIP,
++ James
menu = James
title =James
alerts = someloss
slaves = boomer slave2
#host = james.address
host = 192.168.20.200

debug模式测试:

cd /usr/local/smokeping/bin/
./smokeping --config=/usr/local/smokeping/etc/config --debug

正式运行smokeping并开启日志记录:

/usr/local/smokeping/bin/smokeping --config=/usr/local/smokeping/etc/config --logfile=smoke.log

Nginx

通过Nginx来反向代理SmokePing的FCGI程序,以实现WEB访问:

yum -y install nginx

由于Nginx本身是不支持直接访问FCGI的,所以这里我们要安装一个spawn-fcgi:

yum -y install spawn-fcgi

修改SmokePing的WEB目录所有者改为Nginx:

chown -R nginx.nginx /usr/local/smokeping/htdocs/

用spawn-fcgi以nginx用户来启动SmokePing的FCGI程序:

spawn-fcgi -a 127.0.0.1 -p 9007 -P /var/run/smokeping-fastcgi.pid -u nginx -f /usr/local/smokeping/htdocs/smokeping.fcgi

在Nginx的conf.d目录内新建一个SmokePing的站点conf:

# cat /etc/nginx/conf.d/smokeping.conf
server {
        listen       81;
        server_name  localhost;
        location / {
            root   /usr/local/smokeping/htdocs/;
            index  index.html index.htm smokeping.fcgi;
        }
        location ~ .*\.fcgi$ {
            root  /usr/local/smokeping/htdocs/;
            fastcgi_pass   127.0.0.1:9007;
            include /etc/nginx/fastcgi_params;
        }
}   

修改nginx主配置文件:

# cat /etc/nginx/nginx.conf
user  nginx;
worker_processes  1;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  65;
    #gzip  on;
    include /etc/nginx/conf.d/*.conf;
}

启动nginx服务:

systemctl restart nginx

至此nginx+smokeping安装配置完毕,可以直接通过浏览器访问smokeping的web界面了。

支持中文

安装一个中文字体:

    yum -y install wqy-zenhei-fonts.noarch

编辑SmokePing的配置文件smokeping/etc/config 添加 charset = utf-8

...
*** Presentation ***
charset = utf-8         #添加
template = /usr/local/smokeping/etc/basepage.html.dist
+ charts
...

编辑/usr/local/smokeping/lib/Smokeping/Graphs.pm 文件插入如下代码:
‘–font TITLE:20:”WenQuanYi Zen Hei Mono”’,

if ($mode =~ /[anc]/){
        my $val = 0;
        for my $host (@hosts){
            my ($graphret,$xs,$ys) = RRDs::graph
            ("dummy",
            '--start', $tasks[0][1],
            '--end', $tasks[0][2],
            '--font TITLE:20:"WenQuanYi Zen Hei Mono"',   #添加

接着修改需要显示中文的监控项目名字,然后重启服务即可。重启SmokePing和FCGI:

ps -ef |grep smokeping
kill 进程号
/usr/local/smokeping/bin/smokeping --config=/usr/local/smokeping/etc/config --logfile=/var/log/smokeping.log
spawn-fcgi -a 127.0.0.1 -p 9007 -P /var/run/smokeping-fastcgi.pid -u nginx -f /usr/local/smokeping/htdocs/smokeping.fcgi

添加需要监控的网站和节点

在/usr/local/smokeping/etc/config中添加,添加完后需要重启
smokeping 会根据配置文件config在/usr/local/smokeping/htdocs/data之下添加moniter文件夹,其下包含website子文件夹
添加监控节点示例:注意+是第一层,++是第二层,+++ 是第三层
示例:

+ Test
menu= 三大网络监控
title = 监控统计

++ dianxin
menu = 电信网络监控
title = 电信网络监控列表
host = /Test/dianxin/dianxin-bj /Test/dianxin/dianxin-tj

+++ dianxin-bj
menu = 北京电信
title = 北京电信
alerts = someloss
host = 202.96.199.133

+++ dianxin-tj
menu = 天津电信
title = 天津电信
alerts = someloss
host = 219.150.32.132

++ liantong
menu = 联通网络监控
title = 联通网络监控列表
host = /Test/liantong/liantong-sc /Test/liantong/liantong-sh

+++ liantong-sc
menu = 四川联通
title = 四川联通
alerts = someloss
host = 119.6.6.6

+++ liantong-sh
menu = 上海联通
title = 上海联通
alerts = someloss
host = 210.22.84.3

++ yidong
menu = 移动网络监控
title = 移动网络监控列表
host = /Test/yidong/yidong-bj /Test/yidong/yidong-tj

+++ yidong-bj
menu = 北京移动
title = 北京移动
alerts = someloss
host = 221.130.33.52

+++ yidong-tj
menu = 天津移动
title = 天津移动
alerts = someloss
host = 211.137.160.5    

效果图:
Nginx+SmokePing 实践

相关标签: SmokePing