使用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