海运的博客

ubuntu安装smokeping并配置nginx fastcgi

发布时间:November 16, 2020 // 分类: // No Comments

使用apt安装smokeping不安装apache,cgi文件位于/usr/share/smokeping/smokeping.cgi, 其它文件位于/usr/share/smokeping/www目录。

apt install --no-install-recommends smokeping
apt install fcgiwrap

nginx配置文件:

server {
        listen     88;
        charset utf-8;

        location / {
                root /usr/share/smokeping/www/;
        }
        location ~ /$ {
                root /usr/share/smokeping/;
                index smokeping.cgi;
        }
        location ^~ /smokeping/ {
                alias /usr/share/smokeping/www/;
        }
        location ~ .*\.(cgi|sh)$ {
                gzip off;
                root /usr/share/smokeping/;
                include /etc/nginx/fastcgi_params;
                fastcgi_pass  unix:/var/run/fcgiwrap.socket;
        }
        access_log off;
}

编译安装smokeping,ubuntu20.04/debian11测试:

apt install rrdtool librrds-perl zlib1g-dev make gcc libssl-dev
wget https://oss.oetiker.ch/smokeping/pub/smokeping-2.8.2.tar.gz
tar zxf smokeping-2.8.2.tar.gz 
cd smokeping-2.8.2/
./configure --prefix=/usr/local/smokeping
make && make install
cp /usr/local/smokeping/bin/smokeping_cgi /usr/local/smokeping/smokeping.cgi
mkdir /usr/local/smokeping/htdocs/images/
chown www-data /usr/local/smokeping/htdocs/images/

nginx:

server {
        listen     88;
        charset utf-8;
 
        location / {
                root /usr/local/smokeping/htdocs/;
        }
        location ~ /$ {
                root /usr/local/smokeping/;
                index smokeping.cgi;
        }
        location ^~ /smokeping/ {
                alias /usr/local/smokeping/htdocs/;
        }
        location ~ .*\.(cgi|sh)$ {
                gzip off;
                root /usr/local/smokeping/;
                include /etc/nginx/fastcgi_params;
                fastcgi_pass  unix:/var/run/fcgiwrap.socket;
        }
        access_log off;
}

smokeping配置文件目录,smokeping.cgi需手工修改,smokeping主主程序可添加--config参数自定义。

grep cfg /usr/share/smokeping/smokeping.cgi
my $cfg = (shift @ARGV) || "/etc/smokeping/config";

修改data目录,datadir目录smokeping要有读写权限,dyndir目录fcgiwrap运行用户www-data要有读写权限。

cat /etc/smokeping/config.d/pathnames
datadir  = /mnt/smokeping/data
dyndir = /mnt/smokeping/data/__cgi
imgcache = /usr/local/smokeping/htdocs/images
imgurl   = images

修改检测频率每60秒10次,也可在Probes内设置,注意再次修改要删除数据。

cat /etc/smokeping/config.d/Database 
step     = 60
pings    = 10

Probes配置:

*** Probes ***

+ FPing
binary = /usr/bin/fping
step = 60
pings = 20
#mininterval = 0.05
#timeout = 0.5

+ DNS
binary = /usr/bin/dig
forks = 2
lookup = google.com
step = 60
pings = 10

+Curl
binary = /usr/bin/curl
forks = 5
step = 60
pings = 10
timeout = 5
agent = User-Agent: Smokeping
require_zero_status = yes
urlformat = http://%host%/

Targets配置:

*** Targets ***

probe = FPing

menu = Top
title = Network Latency Grapher
remark = Welcome to the SmokePing website of WORKS Company. \
         Here you will learn all about the latency of our network.

+ Ping
menu = Ping
title = Ping

alerts = hostdown,startdown

++ OL
menu = OL
title = OL
host = www.haiyun.me

++ HE
menu = HE
title = HE
host = www.haiyun.me

+ Curl 
menu = Curl
title = Curl

probe = Curl

++ OL
menu = OL
title = OL
host = 127.0.0.1
extraargs = --socks5 127.0.0.1:2016

++ HE
menu = HE
title = HE
host = 127.0.0.1
extraargs = --socks5 127.0.0.1:2015

Alerts配置:

*** Alerts ***
#to = alertee@address.somewhere
to = |/usr/local/bin/sendmail
from = smokealert@haiyun.me
#mailhost=www.haiyun.me
#mailpass=xxxxxx
#mailuser=xxxx

+someloss
type = loss
# in percent
pattern = >0%,*12*,>0%,*12*,>0%
comment = loss 3 times  in a row

+hostdown
type = loss
pattern = <90%,<90%,>90%,>90%,>90%,>90%,>90%,>90%
comment = no reply

+startdown
type = loss
pattern = ==S,>90%,>90%,>90%,>90%,>90%,>90%
comment = loss at startup

虽然smokeping可配置使用smtp发信,好像不支持smtp tls/ssl,所以调用/usr/local/bin/sendmail来发信,注意smokeping运行用户要有执行权限。:

#!/usr/bin/php
<?php
include('/usr/local/bin/smtp.php');
if (count($argv) != 6) {
  die("Invalid parameter\n");
}
$alertname = $argv[1];
$target = $argv[2];
$losspattern = $argv[3];
$rtt = $argv[4];
$hostname = $argv[5];
$title = $target.' is down';
$body = 'host: '.$hostname.'<br />'.'rtt: '.$rtt.'<br />';
send_mail($title, $body);

标签:smokeping

评论已关闭

分类
最新文章
最近回复
  • 海运: 恩山有很多。
  • swsend: 大佬可以分享一下固件吗,谢谢。
  • Jimmy: 方法一 nghtp3步骤需要改成如下才能编译成功: git clone https://git...
  • 海运: 地址格式和udpxy一样,udpxy和msd_lite能用这个就能用。
  • 1: 怎么用 编译后的程序在家里路由器内任意一台设备上运行就可以吗?比如笔记本电脑 m参数是笔记本的...
  • 孤狼: ups_status_set: seems that UPS [BK650M2-CH] is ...
  • 孤狼: 擦。。。。apcupsd会失联 nut在冲到到100的时候会ONBATT进入关机状态,我想想办...
  • 海运: 网络,找到相应的url编辑重发请求,firefox有此功能,其它未知。
  • knetxp: 用浏览器F12网络拦截或监听后编辑重发请求,修改url中的set为set_super,将POS...
  • Albert: 啊啊啊啊啊啊啊啊啊 我太激动了,终于好了英文区搜索了半天,翻遍了 pve 论坛没找到好方法,博...