Smokeping

出自 ArchWiki

Smokeping 允许您探测服务器列表,使用 RRDtool 存储数据,并基于 RRDtool 的输出生成统计图表。Smokeping 由两部分组成。一个守护进程在后台运行,以设定的时间间隔进行 ping 和收集数据。一个 Web 界面以图形的形式显示数据。

本 Wiki 页面涵盖 smokeping 守护进程和 CGI Web 界面的基本设置。

安装

本节介绍如何使用 smokeping 软件包安装 Smokeping。Apache 上的 FastCGI 将按照 Apache 和 FastCGI 中的描述进行设置。

smokeping 软件包由两部分组成

  • /etc/smokeping/ 中的 smokeping 守护进程和配置。此守护进程执行监控。
  • /srv/http/smokeping 中的 smokeping “htdocs”。这些将由 Web 界面使用。

除了 smokeping 软件包外,您还需要

  • smokeping 可以用来监控的工具。fping 是简单 ping 探测的最简单和默认方法。
  • apachemod_fcgidAUR 用于 Web 界面(如果您使用 Apache)。
  • fcgiwrap 以及启动并启用 fcgiwrap.socket(如果您使用 Nginx)
  • FastCGI 脚本可以写入的图像缓存目录,例如 /srv/smokeping/imgcache
  • smokeping 守护进程可以写入,FastCGI 脚本可以读取的数据目录,例如 /srv/smokeping/data
  • 确保主配置文件可被 smokeping 守护进程读取。

可选先决条件

如果您想使用其他探测器(如 DNS 或 http 探测器),您将需要如下所示的其他软件包。本 Wiki 页面不涵盖这些软件包的配置。

探测器 所需软件包
Curl curl
DNS bind(用于 dig 实用程序)
EchoPing echoping
SSH openssh
TelnetIOSPing perl-net-telnet
AnotherDNS perl-net-dns
LDAP perl-ldap
LDAP (tls) perl-io-socket-ssl
Authen perl-authen-radius

配置

Smokeping 要求您编辑一些文件。未编辑的文件以 .dist 扩展名结尾。重命名 /etc/smokeping 中的 .dist 文件以删除后缀。find 命令执行此操作,并打印出每个正在重命名且需要编辑的文件

# cd /etc/smokeping
# find . -name '*.dist' -print -execdir sh -c 'mv {} $(basename {} .dist)' \;
# mv /srv/http/smokeping/smokeping.fcgi.dist /srv/http/smokeping/smokeping.fcgi

编辑配置文件

接下来,编辑 /etc/smokeping/config 文件;这是 smokeping 的主配置文件。简要描述各节,然后是一个完整的示例。

注意: 大多数路径都需要更改,可能从 /usr/etc/ 更改为 /etc/smokeping,但请确认每个路径。可以使用 pacman -Ql smokeping 找到各种 .dist 文件的路径

/etc/smokeping/config 文件的 General 节最容易编辑。个性化配置文件的顶部以匹配您的信息。注释描述了每个字段。请注意,如果您没有安装 sendmail 程序(即来自 postfix 或 sendmail),请使用其他程序代替,例如 /bin/false。您指定的文件必须存在,否则 smokeping 将报错。

Alerts 节在本示例中不需要任何更改。

Database 节不需要任何更改。

Presentation 节中,需要更新模板文件名的路径,(即 /etc/smokeping/basepage.html

Probes 节指定哪些探测器处于活动状态。默认情况下,仅启用 FPing 探测器。本节不需要任何更改。

Slaves 节在本最小示例中不需要,因此可以注释掉或删除。请注意,如果您在 Slaves 节中使用 smokeping_secrets 设置,则必须使该文件对外界不可读,否则 smokeping 将报错:chmod 600 /etc/smokeping/smokeping_secrets

Targets 节指定将探测哪些主机(在我们的示例中为 ping)。自定义它,以便它探测您想要收集统计信息的主机,如下例所示。

您可以通过 https://oss.oetiker.ch/smokeping/doc/smokeping_examples.en.html 上的示例了解有关 Smokeping 配置文件的更多信息

/etc/smokeping/config
*** General ***

owner     = Your Name Here                            # your name
contact   = your.email@host.bla                       # your email
mailhost  = your.smtp.server.bla                      # your mail server
sendmail  = /bin/false                                # where the sendmail program is
imgcache  = /srv/smokeping/imgcache                   # filesystem directory where we store files
imgurl    = imgcache                                  # URL directory to find them
datadir   = /srv/smokeping/data                       # where we share data between the daemon & webapp
piddir    = /var/run                                  # filesystem directory to store PID file
cgiurl    = https://127.0.0.1/smokeping/smokeping.fcgi  # exterior URL
smokemail = /etc/smokeping/smokemail   
tmail     = /etc/smokeping/tmail
syslogfacility = local0
# each probe is now run in its own process
# disable this to revert to the old behaviour
# concurrentprobes = no

*** Alerts ***
to = alertee@address.somewhere
from = smokealert@company.xy

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

*** Database ***

step     = 300
pings    = 20

# consfn mrhb steps total

AVERAGE  0.5   1  1008
AVERAGE  0.5  12  4320
    MIN  0.5  12  4320
    MAX  0.5  12  4320
AVERAGE  0.5 144   720
    MAX  0.5 144   720
    MIN  0.5 144   720

*** Presentation ***

template = /etc/smokeping/basepage.html

+ charts

menu = Charts
title = The most interesting destinations
++ stddev
sorter = StdDev(entries=>4)
title = Top Standard Deviation
menu = Std Deviation
format = Standard Deviation %f

++ max
sorter = Max(entries=>5)
title = Top Max Roundtrip Time
menu = by Max
format = Max Roundtrip Time %f seconds

++ loss
sorter = Loss(entries=>5)
title = Top Packet Loss
menu = Loss
format = Packets Lost %f

++ median
sorter = Median(entries=>5)
title = Top Median Roundtrip Time
menu = by Median
format = Median RTT %f seconds

+ overview 

width = 600
height = 50
range = 10h

+ detail

width = 600
height = 200
unison_tolerance = 2
nodata_color = ffb0b0
loss_background = yes

"Last 3 Hours"    3h
"Last 30 Hours"   30h
"Last 10 Days"    10d
"Last 400 Days"   400d

*** Probes ***

+ FPing

binary = /usr/bin/fping

*** Targets ***

probe = FPing

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

+ targets
menu = Targets
title = Targets

++ CloudflareDNS
 
menu = Cloudflare DNS
title = Cloudflare DNS server
host = 1.1.1.1

++ GoogleDNS

menu = Google DNS
title = Google DNS server
host = 8.8.8.8

++ MultiHost

menu = Multihost example
title = CloudflareDNS and Google DNS
host = /targets/CloudflareDNS /targets/GoogleDNS

关于 smokeping 配置文件语法的注意事项

每个 + 字符定义层次结构中的一个节。节名称中不允许有空格。节名称中也应避免使用句点和正斜杠。这可能是因为 RRD 文件存储在数据目录下,其名称与节的名称完全相同。

Targets 节中,您可以将 host 定义为真实的主机名,也可以定义为另一个节的路径,以生成多主机图表,如上面的 MultiHost 示例所示。

设置系统的其余部分

设置配置文件引用的额外目录

# mkdir -p /srv/smokeping/data
# mkdir -p /srv/smokeping/imgcache
# chown -R smokeping:smokeping /srv/smokeping
# chown -R http:http /srv/smokeping/imgcache
# chmod a+rx /srv/smokeping
# chmod -R a+rx /srv/smokeping/data

由于 smokeping 配置文件由 smokeping 守护进程和 FastCGI 脚本读取,因此它需要是可读的

# chmod a+rx /etc/smokeping
# chmod a+r /etc/smokeping/config

关于 Smokeping 主从配置的注意事项

主从配置有一个额外的复杂之处,但原理是相同的。对于从服务器,smokeping 不会将数据写入 RRD 文件 - 它们是由 Web 服务器推送过来的。因此,在主从模式下,您需要确保您的 Web 服务器运行的用户 [nginx 以用户 http 身份运行] 也具有 RRD 文件(在 /srv/smokeping/data 下)的写入权限。

当在 主/从 模式下运行 Smokeping 时,主服务器具有 smokeping 从服务器运行的用户的有效权限。请勿以 root 身份运行从服务器。请先阅读 安全注意事项

他们的 Wiki 上的 Smokeping FAQ 详细说明了复杂的权限要求。如果您的主从配置仍然无法正常工作,请使用 setfacl 提供所需的最低权限

On the master, give both `http` and `smokeping` full access (rwx) to `/srv/smokeping/*`
# setfacl -R -m u:http:rwx /srv/smokeping
# setfacl -R -m u:smokeping:rwx /srv/smokeping

Set specific read permissions for files inside `/etc/smokeping`
# setfacl -m u:http:r /etc/smokeping/smokeping_secrets
# setfacl -m u:smokeping:r /etc/smokeping/config /etc/smokeping/smokeping_secrets

从服务器不需要配置文件,它们从主服务器拉取配置,只需要读取 /etc/smokeping/smokeping_secrets

# /usr/bin/smokeping --master-url=https://smokeping.site/smokeping.fcgi
# setfacl -m u:http:r /etc/smokeping/smokeping_secrets

从服务器的 systemd 单元示例

[Unit]
Description=Smokeping Slave: my.slave.net
Documentation=man:smokeping_master_slave(7)

[Service]
ExecStart=/usr/sbin/smokeping \
  --master-url=https://smokeping.site/smokeping.fcgi \
  --cache-dir=/var/lib/smokeping \
  --shared-secret=/etc/smokeping/smokeping_secrets \
  --pid-dir=/run/smokeping \
  --slave-name=my.slave.net 
# The --slave-name should be an exact match to both the master's config and smokeping_secrets
  
ExecReload=/bin/kill -HUP $MAINPID  

[Service]
Type=forking
RuntimeDirectory=smokeping
PIDFile=/run/smokeping/smokeping.pid
User=smokeping
Group=smokeping
Restart=on-failure

启动并启用守护进程

启动 并启用 smokeping.service。然后检查它是否正在运行。

设置 Web 前端

Apache

编辑 /etc/httpd/conf/httpd.conf 以使其包含

LoadModule fcgid_module modules/mod_fcgid.so
<IfModule fcgid_module>
  AddHandler fcgid-script .fcgi
</IfModule>

Alias /smokeping/imgcache /srv/smokeping/imgcache
Alias /smokeping /srv/http/smokeping

<Directory "/srv/smokeping/imgcache">
  AllowOverride all
  Require all granted
</Directory>

<Directory "/srv/http/smokeping">
 Options FollowSymLinks ExecCGI
 AllowOverride all
 Require all granted
</Directory>

启动 Apache via the httpd.service

检查 https://127.0.0.1/smokeping/smokeping.fcgi 是否加载。第一个数据应在几分钟后出现。

如果图形中的字体不可读,您可能需要安装 ttf-dejavu 软件包。

Caddy

感谢 Caddy 社区 和此配置文件 /etc/smokeping/config 以及 启用 fcgiwrap.socket

/etc/caddy/caddy.conf.d/smokeping.conf
smokeping.example.com {

        log stdout
        errors

        tls john@example.com
        root /srv/http/smokeping

        fastcgi / unix:/var/run/fcgiwrap.sock {
                env SCRIPT_FILENAME /srv/http/smokeping/smokeping.fcgi.dist
        }
}

smokeping.example.com/js {
        root /srv/http/smokeping/js
}

smokeping.example.com/css {
        root /srv/http/smokeping/css
}

smokeping.example.com/cache {
        root /var/cache/smokeping
}

此 Caddy smokeping 配置的更新版本 - https://gist.github.com/Strykar/4df1eb8aebc4d5f7039f6045301352c7

Caddy 2

感谢 francislavoie 和 Caddy 社区 以及 Caddy 文档。启动并启用 fcgiwrap.socket!

/etc/caddy/caddy.conf.d/smokeping.conf
smokeping.example.com {

    handle /js/* {
        root * /srv/http/smokeping/
        file_server
    }
    handle /css/* {
        root * /srv/http/smokeping/
        file_server
    }
    handle /imgcache/* {
        root * /srv/http/smokeping/
        file_server
    }
    handle /images/* {
        root * /srv/http/smokeping/
        file_server
    }
    
    handle {
        root * /srv/http/smokeping/
        reverse_proxy unix//var/run/fcgiwrap.sock {
            transport fastcgi {
                env SCRIPT_FILENAME /srv/http/smokeping/smokeping.fcgi
                split ""
            }
        }
    }
}

Lighttpd

首先安装 lighttpdfcgi

编辑 Lighttpd 配置文件,并确保您至少拥有以下所有配置指令

/etc/lighttpd/lighttpd.conf
server.document-root    = "/srv/http"
server.follow-symlink   = "enable"

server.modules += ("mod_fastcgi")
fastcgi.server = (
        ".fcgi" =>
        ((
                "bin-path" => "/srv/http/smokeping/smokeping.fcgi",
                "host" => "localhost",
                "port" => 8001,
        )),
)

启动/启用 lighttpd.service

Systemd 应显示 smokeping_cgilighttpd.service 管理。

$ systemctl status lighttpd
● lighttpd.service - Lighttpd Web Server
   Loaded: loaded (/usr/lib/systemd/system/lighttpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2018-12-26 14:34:42 PST; 1 day 7h ago
  Process: 17117 ExecReload=/bin/kill -HUP $MAINPID (code=exited, status=0/SUCCESS)
 Main PID: 28321 (lighttpd-angel)
    Tasks: 6 (limit: 4915)
   Memory: 128.9M
   CGroup: /system.slice/lighttpd.service
           ├─17119 /usr/bin/lighttpd -D -f /etc/lighttpd/lighttpd.conf
           ├─17126 /usr/bin/perl /usr/bin/smokeping_cgi /etc/smokeping/config
           ├─17127 /usr/bin/perl /usr/bin/smokeping_cgi /etc/smokeping/config
           ├─17128 /usr/bin/perl /usr/bin/smokeping_cgi /etc/smokeping/config
           ├─17129 /usr/bin/perl /usr/bin/smokeping_cgi /etc/smokeping/config
           └─28321 /usr/bin/lighttpd-angel -D -f /etc/lighttpd/lighttpd.conf

最后,添加一个符号链接以允许加载图像

# ln -s -t /srv/http/smokeping /srv/smokeping/imgcache

Nginx

确保 fcgiwrap.socketnginx.service 都通过 systemctl 运行。

为 smokeping 向 /etc/nginx/nginx.conf 添加服务器块,以下是启用 TLS 块的示例。

   server {
       server_name smokeping.example.com;
       listen 443 ssl http2;
       listen [::]:443 ssl http2;
       root /srv/http/smokeping/;
       index smokeping.fcgi;
       gzip off;
       access_log /var/log/nginx_smokeping.log combined;
       error_log /var/log/nginx_smokeping.log;
       location ~ \.fcgi$ {
           fastcgi_intercept_errors on;
           include /etc/nginx/fastcgi_params;
           fastcgi_param SCRIPT_FILENAME /srv/http/smokeping/smokeping.fcgi;
           fastcgi_pass unix:/var/run/fcgiwrap.sock;
       }
       location /imgcache {
           alias /srv/smokeping/imgcache;
           gzip off;
       }
   }

通过 nginx -t 以 root 用户身份验证您的配置是否正常,并通过 nginx -s reload 以 root 用户身份重新加载配置。

高级配置

Smokeping 是一个功能强大的工具,可以通过多种方式进行配置。您可以设置许多不同类型的探测器。您可以设置从属 smokeping 服务器,这些服务器可以发送其统计信息并向您显示来自其他服务器的探测。

您还可以在 perl 中创建自定义探测器,请参阅 他们 wiki 上的 一些第三方探测器。本指南目前未涵盖这些选项,请查阅 Smokeping 网站上的文档。

另请参阅 - https://github.com/oetiker/SmokePing/wiki/FAQ

注意事项

Smoketrace (Tr.cgi)

根据 发行说明SmokeTraceroute 实用程序自 v2.5.0 起已不再提供。