知乎专栏 |
[root@localhost ~]# dnf search mrtg Last metadata expiration check: 3:27:52 ago on Thu 26 Aug 2021 02:14:39 PM CST. ======================================================================================== Name Exactly Matched: mrtg ======================================================================================== mrtg.x86_64 : Multi Router Traffic Grapher ============================================================================================ Name Matched: mrtg ============================================================================================ pcp-import-mrtg2pcp.x86_64 : Performance Co-Pilot tools for importing MTRG data into PCP archive logs [root@localhost ~]# dnf install -y mrtg
默认配置文件
[root@localhost ~]# cat /etc/mrtg/mrtg.cfg ###################################################################### # Multi Router Traffic Grapher -- Example Configuration File ###################################################################### # This file is for use with mrtg-2.0 # # Note: # # * Keywords must start at the begin of a line. # # * Lines which follow a keyword line which do start # with a blank are appended to the keyword line # # * Empty Lines are ignored # # * Lines starting with a # sign are comments. # Where should the logfiles, and webpages be created? # Minimal mrtg.cfg #-------------------- HtmlDir: /var/www/mrtg ImageDir: /var/www/mrtg LogDir: /var/lib/mrtg ThreshDir: /var/lib/mrtg #Target[r1]: 2:public@myrouter.somplace.edu #MaxBytes[r1]: 1250000 #Title[r1]: Traffic Analysis #PageTop[r1]: <H1>Stats for our Ethernet</H1>
[root@localhost ~]# indexmaker --output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg
启用 mrtg
[root@localhost ~]# systemctl enable mrtg Created symlink /etc/systemd/system/multi-user.target.wants/mrtg.service → /usr/lib/systemd/system/mrtg.service.
启动 mrtg
[root@localhost ~]# systemctl start mrtg
查看启动状态
[root@localhost ~]# systemctl status mrtg ● mrtg.service - Multi-router Traffic Grapher Loaded: loaded (/usr/lib/systemd/system/mrtg.service; disabled; vendor preset: disabled) Active: active (running) since Thu 2021-08-26 17:58:34 CST; 4s ago Main PID: 176231 (mrtg) Tasks: 1 (limit: 100608) Memory: 21.4M CGroup: /system.slice/mrtg.service └─176231 /usr/bin/perl -w /usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok Aug 26 17:58:34 localhost.localdomain systemd[1]: Started Multi-router Traffic Grapher.
Nginx 配置
[root@localhost conf.d]# cat /etc/nginx/conf.d/monitor.netkiller.cn.conf server { listen 192.168.30.13:80; server_name 192.168.30.13; access_log /var/log/nginx/monitor.netkiller.cn.access.log; error_log /var/log/nginx/monitor.netkiller.cn.error.log; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { root /var/www/mrtg; index index.html; autoindex on; } }
$ sudo apt-get install mrtg $ sudo mkdir /etc/mrtg/ $ sudo sh -c 'cfgmaker --global "HtmlDir: /var/www/mrtg" \ --global "ImageDir: /var/www/mrtg" \ --global "LogDir: /var/lib/mrtg" \ --global "ThreshDir: /var/lib/mrtg" \ --global "Options[_]: growright,bits" \ --ifref=name --ifdesc=descr --show-op-down \ public@172.16.0.254 > /etc/mrtg/firewall.cfg' $ sudo mkdir -p /var/www/mrtg $ sudo indexmaker --output=/var/www/mrtg/firewall.html /etc/mrtg/firewall.cfg
# yum install mrtg
start
# env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
/etc/mrtg/mrtg.cfg
HtmlDir: /var/www/mrtg ImageDir: /var/www/mrtg LogDir: /var/lib/mrtg ThreshDir: /var/lib/mrtg #Target[r1]: 2:public@myrouter.somplace.edu #MaxBytes[r1]: 1250000 #Title[r1]: Traffic Analysis #PageTop[r1]: <H1>Stats for our Ethernet</H1> Target[dell_3548_switch]: ifInOctets.1&ifOutOctets.1:public@172.16.0.252 MaxBytes[dell_3548_switch]: 1250000 Title[dell_3548_switch]: Traffic Analysis PageTop[dell_3548_switch]: <H1>Stats for our Ethernet</H1>
create mrtg.cfg
cp /etc/mrtg/mrtg.cfg /etc/mrtg/mrtg.cfg.old cfgmaker --global "HtmlDir: /var/www/mrtg" \ --global "ImageDir: /var/www/mrtg" \ --global "LogDir: /var/lib/mrtg" \ --global "ThreshDir: /var/lib/mrtg" \ --global "Options[_]: growright,bits" \ --ifref=name --ifdesc=descr --show-op-down \ public@172.16.0.252 > /etc/mrtg/mrtg.cfg
index.html
# indexmaker --output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg
cfgmaker --global "HtmlDir: /var/www/mrtg" \ --global "ImageDir: /var/www/mrtg" \ --global "LogDir: /var/lib/mrtg" \ --global "ThreshDir: /var/lib/mrtg" \ --global "Options[_]: growright,bits" \ --ifref=name --ifdesc=descr \ --subdirs=Dell6224 \ public@172.16.0.251 \ --ifref=name --ifdesc=descr \ --subdirs=Dell3548 \ public@172.16.0.252 \ --ifref=name --ifdesc=descr \ --subdirs=H3CS3600 \ public@172.16.0.253 > /etc/mrtg/mrtg.cfg indexmaker --output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg
for host in 253 252 251 250 249 do cfgmaker --global "HtmlDir: /var/www/mrtg" \ --global "ImageDir: /var/www/mrtg" \ --global "LogDir: /var/lib/mrtg" \ --global "ThreshDir: /var/lib/mrtg" \ --global "Options[_]: growright,bits" \ \ --ifref=name --ifdesc=descr \ --subdirs=Cisco-Switch-2960G-$host \ public@172.16.0.$host \ \ > /etc/mrtg/switch-2960-$host.cfg indexmaker --output=/var/www/mrtg/switch-2960-$host.html /etc/mrtg/switch-2960-$host.cfg done
Xsize / Ysize
cfgmaker --global "HtmlDir: /var/www/mrtg" \ --global "ImageDir: /var/www/mrtg" \ --global "LogDir: /var/lib/mrtg" \ --global "ThreshDir: /var/lib/mrtg" \ --global "Options[_]: growright,bits" \ --global "Xsize[_]: 600" \ --global "Ysize[_]: 200" \ \ --ifref=name --ifdesc=descr \ --subdirs=Juniper-Firewall \ public@172.16.0.1 \ > /etc/mrtg/firewall.cfg