MRTG

まず

# yum install httpd
から始めよう
総ダウンロード容量: 3.0 M
インストール容量: 10 M
Is this ok [y/d/N]: y

となったり

# systemctl start httpd
# systemctl enable httpd
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'

と表示されるかもしれないし、

# firewall-cmd --list-services

の結果に http が載ってないかもしれない

# firewall-cmd --add-service=http --permanent
success
# firewall-cmd --reload
success
# firewall-cmd --list-services
dhcpv6-client http smtp ssh

ブログのデータベース接続エラーがrebootで治ったのも
メモリ不足でDBが落ちてた気がするのでKVMのホストにいつものトコロを見ながらMRTGを入れてみる。
KVMのホストとターゲットのクライアントにsnmpパッケージを入れる

# yum -y install net-snmp
# yum -y install net-snmp-utils   ※追記

# vi /etc/snmp/snmpd.conf
ゴニュゴニョして起動。
# systemctl start snmpd
そして常駐化

# systemctl enable snmpd
 ln -s '/usr/lib/systemd/system/snmpd.service' '/etc/systemd/system/multi-user.target.wants/snmpd.service'

KVMのホストにMRTGパッケージを入れる

# yum -y install mrtg

ここで、/etc/httpd/conf.d/mrtg.conf にLAN接続でも観れるように追記した方がいいだろう。

<Location /mrtg>
Require local
Require ip 192.168.*.0/24
# Require ip 10.1.2.3
# Require host example.org
</Location>

では、MRTGの 本体の設定ファイルを作成しよう

# cfgmaker --ifref=descr --ifdesc=descr public@*.*.*.* > /etc/mrtg/mrtg.cfg ※*.*.*.*はKVMゲストのIPアドレス
--base: Get Device Info on public@*.*.*.*:
SNMP Error:
no response received
SNMPv1_Session (remote host: "*.*.*.*" [*.*.*.*].161)
                  community: "public"
                 request ID: 2017506137
                PDU bufsize: 8000 bytes
                    timeout: 2s
                    retries: 5
                    backoff: 1)
 at /usr/bin/../lib64/mrtg2/SNMP_util.pm line 651.
SNMPWALK Problem for 1.3.6.1.2.1.1 on public@*.*.*.*::::::v4only
 at /usr/bin/cfgmaker line 951.
WARNING: Skipping public@*.*.*.*: as no info could be retrieved
Use of uninitialized value $comment_sysdescr in substitution (s///) at /usr/bin/cfgmaker line 379.
Use of uninitialized value $sysname in concatenation (.) or string at /usr/bin/cfgmaker line 412.
Use of uninitialized value $comment_sysdescr in concatenation (.) or string at /usr/bin/cfgmaker line 412.
Use of uninitialized value $syscontact in concatenation (.) or string at /usr/bin/cfgmaker line 412.
Use of uninitialized value $syslocation in concatenation (.) or string at /usr/bin/cfgmaker line 412.

だったのでKVMゲストのファイアーウォールにsnmpが使える様する。
# firewall-cmd –add-service=snmp

Error: INVALID_SERVICE: snmp
だった。
# firewall-cmd –get-services
で確認してみると

amanda-client bacula bacula-client dhcp dhcpv6 dhcpv6-client dns ftp high-availability http https imaps ipp ipp-client ipsec kerberos kpasswd ldap ldaps libvirt libvirt-tls mdns mountd ms-wbt mysql nfs ntp openvpn pmcd pmproxy pmwebapi pmwebapis pop3s postgresql proxy-dhcp radius rpc-bind samba samba-client smtp ssh telnet tftp tftp-client transmission-client vnc-server wbem-https

snmpは無かったのでポートで設定。

firewall-cmd --zone=public --add-port=161/udp --permanent
# systemctl restart firewalld
# cfgmaker --ifref=descr --ifdesc=descr public@192.168.*.* > /etc/mrtg/mrtg.cfg ※KVMホストのIPアドレス
--base: Get Device Info on public@*.*.*.*:
--base: Vendor Id: Unknown Vendor - 1.3.6.1.4.1.8072.3.2.10
--base: Populating confcache
--base: Get Interface Info
--base: Walking ifIndex
--snpd:   public@*.*.*.*: -> 1 -> ifIndex = 1
--snpd:   public@*.*.*.*: -> 2 -> ifIndex = 2
--snpd:   public@*.*.*.*: -> 3 -> ifIndex = 3
--snpd:   public@*.*.*.*: -> 4 -> ifIndex = 4
--snpd:   public@*.*.*.*: -> 5 -> ifIndex = 5
--snpd:   public@*.*.*.*: -> 6 -> ifIndex = 6
--snpd:   public@*.*.*.*: -> 7 -> ifIndex = 7
--base: Walking ifType
--snpd:   public@*.*.*.*: -> 1 -> ifType = 24
--snpd:   public@*.*.*.*: -> 2 -> ifType = 6
--snpd:   public@*.*.*.*: -> 3 -> ifType = 6
--snpd:   public@*.*.*.*: -> 4 -> ifType = 6
--snpd:   public@*.*.*.*: -> 5 -> ifType = 6
--snpd:   public@*.*.*.*: -> 6 -> ifType = 6
--snpd:   public@*.*.*.*: -> 7 -> ifType = 6
--base: Walking ifAdminStatus
--snpd:   public@*.*.*.*: -> 1 -> ifAdminStatus = 1
--snpd:   public@*.*.*.*: -> 2 -> ifAdminStatus = 1
--snpd:   public@*.*.*.*: -> 3 -> ifAdminStatus = 1
--snpd:   public@*.*.*.*: -> 4 -> ifAdminStatus = 1
--snpd:   public@*.*.*.*: -> 5 -> ifAdminStatus = 1
--snpd:   public@*.*.*.*: -> 6 -> ifAdminStatus = 1
--snpd:   public@*.*.*.*: -> 7 -> ifAdminStatus = 1
--base: Walking ifOperStatus
--snpd:   public@*.*.*.*: -> 1 -> ifOperStatus = 1
--snpd:   public@*.*.*.*: -> 2 -> ifOperStatus = 1
--snpd:   public@*.*.*.*: -> 3 -> ifOperStatus = 2
--snpd:   public@*.*.*.*: -> 4 -> ifOperStatus = 1
--snpd:   public@*.*.*.*: -> 5 -> ifOperStatus = 2
--snpd:   public@*.*.*.*: -> 6 -> ifOperStatus = 1
--snpd:   public@*.*.*.*: -> 7 -> ifOperStatus = 1
--base: Walking ifMtu
--snpd:   public@*.*.*.*: -> 1 -> ifMtu = 65536
--snpd:   public@*.*.*.*: -> 2 -> ifMtu = 1500
--snpd:   public@*.*.*.*: -> 3 -> ifMtu = 1500
--snpd:   public@*.*.*.*: -> 4 -> ifMtu = 1500
--snpd:   public@*.*.*.*: -> 5 -> ifMtu = 1500
--snpd:   public@*.*.*.*: -> 6 -> ifMtu = 1500
--snpd:   public@*.*.*.*: -> 7 -> ifMtu = 1500
--base: Walking ifSpeed
--snpd:   public@*.*.*.*: -> 1 -> ifSpeed = 10000000
--snpd:   public@*.*.*.*: -> 2 -> ifSpeed = 1000000000
--snpd:   public@*.*.*.*: -> 3 -> ifSpeed = 0
--snpd:   public@*.*.*.*: -> 4 -> ifSpeed = 0
--snpd:   public@*.*.*.*: -> 5 -> ifSpeed = 0
--snpd:   public@*.*.*.*: -> 6 -> ifSpeed = 10000000
--snpd:   public@*.*.*.*: -> 7 -> ifSpeed = 10000000

後はこのMRTGの設定ファイルを先のページの通りにゴニョゴニョする。
システムがUTF8なので、EUC-JPでしか動けないMRTGは直接/etc/cron.dに配置できないので

#!/bin/bash
LOCK=/var/lock/mrtg/mrtg_l
CONFCACHE=/var/lib/mrtg/mrtg.ok
export LANG=ja_JP.eucJP
mrtg /etc/mrtg/mrtg.cfg --lock-file $LOCK --confcache-file $CONFCACHE

な起動スクリプト(mrtg.sh)を作り、/etc/cron.dから起動しなければいけないらしい。
そして、
# chmod  700  mrtg.sh
ps.
ブラウザがcharset=euc-jpの設定を無視しているダケな様なので・・・
※多分ドメインのトップページに合わせている。
mrtg.shに以下を追記し、htmlをutf-8に差し替える。

# HTML euc-jp ⇒ utf-8
WorkDir=/var/www/mrtg
for FNAME in ${WorkDir}/*.html
do
  if grep charset=euc-jp ${FNAME} > /dev/null 2>&1
  then
    sed -e "s/charset=euc-jp/charset=utf-8/g" ${FNAME} > ${WorkDir}/tmpfile
    nkf -w ${WorkDir}/tmpfile > ${FNAME}
  fi
done

温度を調べる場合は
# yum install lm_sensors
# sensors で
acpitz-virtual-0
Adapter: Virtual device
temp1:        +26.8°C  (crit = +90.0°C)
coretemp-isa-0000
Adapter: ISA adapter
Core 0:       +43.0°C  (high = +105.0°C, crit = +105.0°C)
Core 1:       +44.0°C  (high = +105.0°C, crit = +105.0°C)
Core 2:       +46.0°C  (high = +105.0°C, crit = +105.0°C)
Core 3:       +46.0°C  (high = +105.0°C, crit = +105.0°C)
と出てくるので、
# snmpwalk -v 2c -c public 192.168.***.*** 1.3.6.1.4.1.2021.13.16
LM-SENSORS-MIB::lmTempSensorsIndex.1 = INTEGER: 1
LM-SENSORS-MIB::lmTempSensorsIndex.2 = INTEGER: 2
LM-SENSORS-MIB::lmTempSensorsIndex.3 = INTEGER: 3
LM-SENSORS-MIB::lmTempSensorsIndex.4 = INTEGER: 4
LM-SENSORS-MIB::lmTempSensorsIndex.5 = INTEGER: 5
LM-SENSORS-MIB::lmTempSensorsDevice.1 = STRING: temp1
LM-SENSORS-MIB::lmTempSensorsDevice.2 = STRING: Core 0
LM-SENSORS-MIB::lmTempSensorsDevice.3 = STRING: Core 1
LM-SENSORS-MIB::lmTempSensorsDevice.4 = STRING: Core 2
LM-SENSORS-MIB::lmTempSensorsDevice.5 = STRING: Core 3
LM-SENSORS-MIB::lmTempSensorsValue.1 = Gauge32: 26800
LM-SENSORS-MIB::lmTempSensorsValue.2 = Gauge32: 44000
LM-SENSORS-MIB::lmTempSensorsValue.3 = Gauge32: 45000
LM-SENSORS-MIB::lmTempSensorsValue.4 = Gauge32: 46000
LM-SENSORS-MIB::lmTempSensorsValue.5 = Gauge32: 46000
# OIDを調べる。
#  snmptranslate -On -IR LM-SENSORS-MIB::lmTempSensorsValue
.1.3.6.1.4.1.2021.13.16.2.1.3
# snmpwalk -v 2c -c public 192.168.***.*** .1.3.6.1.4.1.2021.13.16.2.1.3
LM-SENSORS-MIB::lmTempSensorsValue.1 = Gauge32: 26800
LM-SENSORS-MIB::lmTempSensorsValue.2 = Gauge32: 44000
LM-SENSORS-MIB::lmTempSensorsValue.3 = Gauge32: 44000
LM-SENSORS-MIB::lmTempSensorsValue.4 = Gauge32: 47000
LM-SENSORS-MIB::lmTempSensorsValue.5 = Gauge32: 47000
snmpwalk -v 2c -c public 192.168.***.*** .1.3.6.1.4.1.2021.13.16.2.1.3.1
LM-SENSORS-MIB::lmTempSensorsValue.1 = Gauge32: 26800
/etc/mrtg/mrtg.cfgに追記

### temp1 ####
Target[temp1]: .1.3.6.1.4.1.2021.13.16.2.1.3.1&.1.3.6.1.4.1.2021.13.16.2.1.3.3:public@192.168.***.***
MaxBytes1[temp1]: 80000
MaxBytes2[temp1]: 80000
Options[temp1]: gauge, absolute, growright, noinfo
YLegend[temp1]: temp1
kilo[temp1]: 1024
Factor[temp1]: 0.001
kMG[temp1]: C,
LegendI[temp1]: temp1
LegendO[temp1]: Core2
Legend1[temp1]: temp1
Legend2[temp1]: Core2
Title[temp1]: 温度
PageTop[temp1]: <H1>温度</H1>

# ./mrtg.sh で動作確認
最後にinit.htmlを作成。
#  indexmaker –columns=1 \
–addhead=”<META HTTP-EQUIV=\”Content-Type\” CONTENT=\”text/html; charset=euc-jp\”>” \
/etc/mrtg/mrtg.cfg > /var/www/mrtg/index.html
全部出来上がったので公開。
# systemctl reload httpd
暫くして

WARNING: Could not match host:'public@192.168.***.***:' ref:'Descr' key:'vnet0'
ERROR: Target[vnet0][_IN_] ' $target->[1]{$mode} ' did not eval into defined data
ERROR: Target[vnet0][_OUT_] ' $target->[1]{$mode} ' did not eval into defined data
と大量にメールが飛んでいたので vnet0 の設定を削除。
syslogのレベルをinfoからnoticeに変えたせいかな?
ps.
MRTGの画面が時々不調。
よく見れば作成したファイルのオーナーがroot。
chown -R apache:apache /var/www/mrtg
を追記。



コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA