OpenBSD有非常丰富的命令行工具可以查看系统状态,譬如优秀的systat,但是systat只能显示当前的状态,无法显示历史记录,这当然无法满足网管员的溯源要求,这个时候就需要用到图形界面的网管工具了。

OpenBSD开发人员也port了不少linux下的网管工具,包括collectd、nagios、smokeping等,不过功能就比linux下的差一些,譬如collectd中就有好多插件无法使用。好在OpenBSD还有原生的symon供用户选择。

symon是一个系统监控工具,跑在FreeBSD、NetBSD、OpenBSD和linux下,它能精确地搜集到最新的系统性能数据,譬如cpu、内存、pf、网卡流量和进程等。symon软件包由symon和symux两个组件组成,symon每隔5秒钟收集系统状态,然后将数据传递给symux,由symux写入到rrd文件中。rrd本身并不是一个图形文件,因此symon还提供了一个单独的syweb组件来完成绘图和web展示。

1. 准备工作

OpenBSD的默认安装包含了apache1.3.8,但是默认情况下并未启动,因此需要先激活:

/etc/rc.conf
httpd=YES

2. 安装

2.1 symon

# pkg_add -I symon

2.2 syweb

# cd /usr/ports/www/syweb/ && sudo make install

3. 配置symon.conf和symux.conf文件

默认情况下,安装symon后自动在/etc目录下生成symon.confsymux.conf两个文件,用户需要根据自己的情况进行调整,另外,symon自带了一个脚本,可用于生成新的symon.conf文件:/usr/local/share/symon/c_config.sh

3.1 symon.conf

# vim /etc/symon.conf
  monitor { cpu(0),  mem,
      if(fxp0), if(fxp1), if(fxp2), if(fxp3),
      pf,
      mbuf,
      sensor(lm2.temp0),sensor(lm2.temp1),
      sensor(lm2.fan0),sensor(lm2.fan1),sensor(lm2.fan2),
      proc(httpd), proc(sshd),
      io(wd0), df(wd0f), df(wd0a)
  } stream to 127.0.0.1 2100

[...]

3.2 symux.conf

# vim /etc/symux.conf
 mux 127.0.0.1 2100
 source 127.0.0.1 {
   accept { cpu(0),  mem,
        pf,
        mbuf,
        sensor(lm2.temp0), sensor(lm2.temp1),
        sensor(lm2.fan0), sensor(lm2.fan1), sensor(lm2.fan2),
        proc(httpd), proc(sshd),
        if(fxp0), if(fxp1), if(fxp2), if(fxp3),
        io(wd0), df(wd0f), df(wd0a)
   }
        datadir "/var/www/symon/rrds/localhost"
 }

[...]

4. 在chroot中安装rrdtool

# /var/www/symon/install_rrdtool.sh
rrdtool and libs installed in apache root

接着创建rrd文件

# mkdir /var/www/symon/rrds/localhost && cd /var/www/symon/rrds/localhost
# /usr/local/share/symon/c_smrrds.sh all
/var/www/symon/rrds/localhost/df_sd0d.rrd created
/var/www/symon/rrds/localhost/df_sd0a.rrd created
/var/www/symon/rrds/localhost/io_sd0.rrd created
/var/www/symon/rrds/localhost/if_em3.rrd created
/var/www/symon/rrds/localhost/if_em2.rrd created
/var/www/symon/rrds/localhost/if_em1.rrd created
/var/www/symon/rrds/localhost/if_em0.rrd created
/var/www/symon/rrds/localhost/proc_openvpn.rrd created
/var/www/symon/rrds/localhost/proc_unbound.rrd created
/var/www/symon/rrds/localhost/proc_httpd.rrd created
/var/www/symon/rrds/localhost/mbuf.rrd created
/var/www/symon/rrds/localhost/pf.rrd created
/var/www/symon/rrds/localhost/mem.rrd created
/var/www/symon/rrds/localhost/cpu0.rrd created

5. 启动symux和symon

# /usr/local/libexec/symux
# /usr/local/libexec/symon

设置开机启动symux & symon

/etc/rc.local
if [ -x /usr/local/libexec/symux ]; then
  echo -n ' symux';
  /usr/local/libexec/symux
fi
 
if [ -x /usr/local/libexec/symon ]; then
  echo -n ' symon';
  /usr/local/libexec/symon
fi

6. 调整syweb的配置

OpenBSD中的apache默认跑在chroot下,因此确保以下目录配置是否正确,另外需要将其它模式下的目录配置注释掉。

/var/www/htdocs/syweb/setup.inc
/* running OpenBSD, apache chrooted: */
$symon['rrdtool_path']='/usr/local/bin/rrdtool';
$symon['cache_dir']='/symon/cache';
$symon['host_tree']='/symon/rrds';
$symon['layout_dir']='/symon';
[...]

7. 测试

通过浏览器访问:http://<your.ip>/syweb/index.php