Linux Mint 17 Qianaでの、MRTGのインストールと設定。

下図のような折れ線グラフ+棒グラフを5分おきに更新させるツール、MRTGをご紹介します。

 aaa

# apt-get install snmp snmpd mrtg hddtemp lm-sensors nkf

# vi /etc/snmp/snmpd.conf


(下記を最下行に追記する。)

view all included .1 80
view system included .1.3.6.1.2.1.1

com2sec local localhost private
com2sec mynetwork 192.168.0.0/24 public
(上記の下線部分は、環境に合わせて適宜変更してください。)

group MyROSystem v1 paranoid
group MyROSystem v2c paranoid
group MyROSystem usm paranoid
group MyROGroup v1 readonly
group MyROGroup v2c readonly
group MyROGroup usm readonly
group MyRWGroup v1 readwrite
group MyRWGroup v2c readwrite
group MyRWGroup usm readwrite
group MyRWGroup any local
group MyROGroup any mynetwork

access MyROSystem "" any noauth exact system none none
access MyROGroup "" any noauth 0 all none none
access MyRWGroup "" any noauth 0 all all all

disk / 10000


snmpd を再起動し、mrtg.cfgを作成する。

# /etc/init.d/snmpd restart

# cfgmaker private@localhost > /etc/mrtg.cfg


mrtg.cfgを編集します。

# vi /etc/mrtg.cfg


# Created by

# /usr/bin/cfgmaker –ifref=descr –ifdesc=descr public@192.168.0.111

### Global Config Options

#  for UNIX
WorkDir: /home/USERDIR/public_html/html/mrtg/

#  or for NT
# WorkDir: c:mrtgdata

### Global Defaults

#  to get bits instead of bytes and graphs growing to the right
Options[_]: growright, noinfo

EnableIPv6: no
Language:eucjp

### Interface 2 >> Descr: ‘eth0’ | Name: ‘eth0’ | Ip: ‘192.168.0.111’ | Eth: ’00-03-0d-d3-bf-46′ ###

Target[eth0]: eth0:public@192.168.0.111:
SetEnv[eth0]: MRTG_INT_IP="192.168.0.111" MRTG_INT_DESCR="eth0"
MaxBytes[eth0]: 125000000
Title[eth0]: eth0トラフィック
PageTop[eth0]: <h1>eth0トラフィック</h1>

### CPU Usage ###
Target[cpu]: .1.3.6.1.4.1.2021.11.50.0&.1.3.6.1.4.1.2021.11.52.0:private@localhost
MaxBytes[cpu]: 100
#Unscaled[cpu]: dwmy # 縦軸を100%にしないで実績値に合わせる(100%にするとグラフがみえないため)
Options[cpu]: growright, noinfo, nopercent
YLegend[cpu]: CPU usage(%)
ShortLegend[cpu]: (%)
LegendI[cpu]: ユーザ 
LegendO[cpu]: システム
Legend1[cpu]: CPU使用率(ユーザ)(%)
Legend2[cpu]: CPU使用率(システム)(%)
Title[cpu]: CPU使用率
PageTop[cpu]: <H1>CPU使用率</H1>

# free(コマンド’free’を打ち込み、下記の下線の部分を、”Memory Free”項目の、”MaxBytes1[mem]:”、”MaxBytes2[mem]:”にコピペする。)

             total       used       free     shared    buffers     cached
Mem:       4049052    3714600     334452          0     565632    1791352
-/+ buffers/cache:    1357616    2691436
Swap:      4124668        356    4124312

### Memory Free ####
Target[mem]: .1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.4.0:private@localhost
MaxBytes1[mem]: 4049052

MaxBytes2[mem]: 4124668
Unscaled[mem]: dwmy
Options[mem]: gauge, absolute, growright, noinfo
YLegend[mem]: Mem Free(Bytes)
ShortLegend[mem]: Bytes
kilo[mem]: 1024
kMG[mem]: k,M,G,T,P
LegendI[mem]: Real
LegendO[mem]: Swap
Legend1[mem]: 空き物理メモリ[MBytes]
Legend2[mem]: 空きスワップメモリ[MBytes]
Title[mem]: 空きメモリ量
PageTop[mem]: <H1>空きメモリ量</H1>

### Disk Used ####
Target[disk]: .1.3.6.1.4.1.2021.9.1.9.1&.1.3.6.1.4.1.2021.9.1.9.1:private@localhost
MaxBytes[disk]: 100
Unscaled[disk]: dwmy
Options[disk]: gauge, absolute, growright, nopercent, noinfo
YLegend[disk]: Disk Used(%)
ShortLegend[disk]: (%)
LegendI[disk]: / Disk used
LegendO[disk]: / Disk Used
Legend1[disk]: / Disk used
Legend2[disk]: / Disk used
Title[disk]: ディスク使用率
PageTop[disk]: <H1>ディスク使用率</H1>

### CPU Temp ###
Target[cputemp]: `/root/sensors.sh`
MaxBytes[cputemp]: 100
Title[cputemp]: CPU温度
PageTop[cputemp]:<h1>CPU温度</h1>
Options[cputemp]: growright,absolute,gauge,nopercent,noinfo
WithPeak[cputemp]: ymw
#unscaled[cputemp]: dwmy
YLegend[cputemp]: Temperature
ShortLegend[cputemp]: C
LegendI[cputemp]: CPU0
LegendO[cputemp]: CPU1
Legend1[cputemp]: CPU0温度
Legend2[cputemp]: CPU1温度

### SSD Temp ###
Target[hddtemp]: `/root/hddtemp.sh`
MaxBytes[hddtemp]: 80
Title[hddtemp]: SSD温度
PageTop[hddtemp]:<h1>SSD温度</h1>
Options[hddtemp]: growright,absolute,gauge,nopercent,noinfo
WithPeak[hddtemp]: ymw
YLegend[hddtemp]: Temperature
ShortLegend[hddtemp]: C
LegendI[hddtemp]: Temp:SSD
LegendO[hddtemp]: Temp:SSD
Legend1[hddtemp]: SSD Temperature in Degrees Celcius
Legend2[hddtemp]: SSD Temperature in Degrees Celcius


mrtg.cfg を mrtg.cfg.orgとしてコピーし、mrtg.cfg をEUC-JP化する

# cp /etc/mrtg.cfg /etc/mrtg.cfg.org

# nkf -e /etc/mrtg.cfg.org > /etc/mrtg.cfg


sensors.shと、hddtemp.shを"/root"に作成する。

# vi /root/sensors.sh


#!/bin/sh

sensors | grep Core | awk ‘{print $3}’ | sed -e ‘s/+//’ -e ‘s/[^0-9+.].*//’


# vi /root/hddtemp.sh


#!/bin/sh

/usr/sbin/hddtemp -n /dev/sda1
/usr/sbin/hddtemp -n /dev/sda2


# chmod +x /root/sensors.sh /root/hddtemp.sh 


CPUの温度を測定するための準備

# sensors-detect

(下記の「YES/no」の質問は、みんな”ENTERキー”でおk。)


# sensors-detect revision 5861 (2010-09-21 17:21:05 +0200)
# System: Mouse Computer I50Ix1 (laptop)

This program will help you determine which kernel modules you need
to load to use lm_sensors most effectively. It is generally safe
and recommended to accept the default answers to all questions,
unless you know what you’re doing.

Some south bridges, CPUs or memory controllers contain embedded sensors.
Do you want to scan for them? This is totally safe. (YES/no):
Module cpuid loaded successfully.
Silicon Integrated Systems SIS5595…                       No
VIA VT82C686 Integrated Sensors…                          No
VIA VT8231 Integrated Sensors…                            No
AMD K8 thermal sensors…                                   No
AMD Family 10h thermal sensors…                           No
AMD Family 11h thermal sensors…                           No
Intel digital thermal sensor…                             Success!
    (driver `coretemp’)
Intel AMB FB-DIMM thermal sensor…                         No
VIA C7 thermal sensor…                                    No
VIA Nano thermal sensor…                                  No

Some Super I/O chips contain embedded sensors. We have to write to
standard I/O ports to probe them. This is usually safe.
Do you want to scan for Super I/O sensors? (YES/no):
Probing for Super-I/O at 0x2e/0x2f
Trying family `National Semiconductor’…                   No
Trying family `SMSC’…                                     No
Trying family `VIA/Winbond/Nuvoton/Fintek’…               No
Trying family `ITE’…                                      No
Probing for Super-I/O at 0x4e/0x4f
Trying family `National Semiconductor’…                   Yes
Found unknown chip with ID 0x8502

Some hardware monitoring chips are accessible through the ISA I/O ports.
We have to write to arbitrary I/O ports to probe them. This is usually
safe though. Yes, you do have ISA I/O ports even if you do not have any
ISA slots! Do you want to scan the ISA I/O ports? (YES/no):
Probing for `National Semiconductor LM78′ at 0x290…       No
Probing for `National Semiconductor LM79′ at 0x290…       No
Probing for `Winbond W83781D’ at 0x290…                   No
Probing for `Winbond W83782D’ at 0x290…                   No

Lastly, we can probe the I2C/SMBus adapters for connected hardware
monitoring devices. This is the most risky part, and while it works
reasonably well on most systems, it has been reported to cause trouble
on some systems.
Do you want to probe the I2C/SMBus adapters now? (YES/no):
Using driver `i2c-i801′ for device 0000:00:1f.3: Intel ICH9
Module i2c-i801 loaded successfully.
Module i2c-dev loaded successfully.

Next adapter: i915 gmbus disabled (i2c-0)
Do you want to scan it? (YES/no/selectively):

Next adapter: i915 gmbus ssc (i2c-1)
Do you want to scan it? (YES/no/selectively):

Next adapter: i915 GPIOB (i2c-2)
Do you want to scan it? (YES/no/selectively):

Next adapter: i915 gmbus vga (i2c-3)
Do you want to scan it? (YES/no/selectively):
Next adapter: i915 GPIOA (i2c-4)
Do you want to scan it? (YES/no/selectively):
Next adapter: i915 gmbus panel (i2c-5)
Do you want to scan it? (YES/no/selectively):
Client found at address 0x50
Probing for `Analog Devices ADM1033’…                     No
Probing for `Analog Devices ADM1034’…                     No
Probing for `SPD EEPROM’…                                 No
Probing for `EDID EEPROM’…                                Yes
    (confidence 8, not a hardware monitoring chip)

Next adapter: i915 GPIOC (i2c-6)
Do you want to scan it? (YES/no/selectively):
Client found at address 0x50
Probing for `Analog Devices ADM1033’…                     No
Probing for `Analog Devices ADM1034’…                     No
Probing for `SPD EEPROM’…                                 No
Probing for `EDID EEPROM’…                                Yes
    (confidence 8, not a hardware monitoring chip)

Next adapter: i915 gmbus dpc (i2c-7)
Do you want to scan it? (YES/no/selectively):

Next adapter: i915 GPIOD (i2c-8)
Do you want to scan it? (YES/no/selectively):

Next adapter: i915 gmbus dpb (i2c-9)
Do you want to scan it? (YES/no/selectively):

Next adapter: i915 GPIOE (i2c-10)
Do you want to scan it? (YES/no/selectively):

Next adapter: i915 gmbus reserved (i2c-11)
Do you want to scan it? (YES/no/selectively):

Next adapter: i915 gmbus dpd (i2c-12)
Do you want to scan it? (YES/no/selectively):

Next adapter: i915 GPIOF (i2c-13)
Do you want to scan it? (YES/no/selectively):

Next adapter: DPDDC-B (i2c-14)
Do you want to scan it? (YES/no/selectively):

Next adapter: DPDDC-C (i2c-15)
Do you want to scan it? (YES/no/selectively):

Next adapter: DPDDC-D (i2c-16)
Do you want to scan it? (YES/no/selectively):

Now follows a summary of the probes I have just done.
Just press ENTER to continue:

Driver `coretemp’:
  * Chip `Intel digital thermal sensor’ (confidence: 9)

To load everything that is needed, add this to /etc/modules:
#—-cut here—-(ココが重要ポイントです。この部分を切り取り、”/etc/modules”に追記します。)
# Chip drivers
coretemp
#—-cut here—-

If you have some drivers built into your kernel, the list above will
contain too many modules. Skip the appropriate ones!

Do you want to add these lines automatically to /etc/modules? (yes/NO)

Unloading i2c-dev… OK
Unloading i2c-i801… OK
Unloading cpuid… OK


# vi /etc/modules


# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.

lp

#—-cut here—-
# Chip drivers
coretemp
#—-cut here—-


# modprobe coretemp

# reboot (PC再起動。これは一応です。) 


# indexmaker /etc/mrtg.cfg

                    –columns=1

                    –title="Linux Mint 17 Qiana MRTG"

                    –addhead="<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset = euc-jp">"

                    –output=/home/USERDIR/public_html/html/mrtg/index.html

 

# vi /home/USERDIR/public_html/html/mrtg/index.html


 <!– <meta http-equiv="content-type" content="text/html; charset=iso-8859-15" > –>
(indexmakerで出力した物の、7行目辺りのこの部分を”<!–”、”–>”で括ると、文字化けしないで表示される。)
 


# vi /etc/cron.d/mrtg


(下記のように書き換えます。)

*/5 *   * * *   root    env LANG=C /usr/bin/mrtg /etc/mrtg.cfg 2>&1


以上で、インストールと設定作業は終了です。このまま、5分以上待ってみて、グラフが正常に更新されていれば、おkということです。
お疲れ様でした!(^ω^)。