Мониторим загрузку интернет-канала с помощью MRTG
4 Июнь 2010 Автор: RamzessЗадался вопросом - как видеть загрузку интернет-канала на сервере. Оказалось, с помощью демона SNMPD и MRTG все очень просто реализовывается.
Итак:
Ставим SNMPD из портов:
# cd /usr/ports/net-mgmt/net-snmp && make install clean
Добавляем в /etc/rc.conf
snmpd_enable=”YES” snmpd_flags=”-a -Lsd -p /var/run/snmpd.pid”
Запускаем конфигуратор:
# snmpconf -i
Порядок настройки следующий:
The following installed configuration files were found:
1: /usr/local/share/snmp/snmpd.conf
Would you like me to read them in? Their content will be merged with the
output files created by this session.Valid answer examples: “all”, “none”,”3″,”1,2,5″
Read in which (default = all): all
I can create the following types of configuration files for you.
Select the file type you wish to create:
(you can create more than one as you run this program)1: snmpd.conf
2: snmptrapd.conf
3: snmp.confOther options: quit
Select File: 1
The configuration information which can be put into snmpd.conf is divided
into sections. Select a configuration section for snmpd.conf
that you wish to create:1: System Information Setup
2: Access Control Setup
3: Trap Destinations
4: Monitor Various Aspects of the Running Host
5: Extending the Agent
6: Agent Operating ModeOther options: finished
Select section: 1
Section: System Information Setup
Description:
This section defines some of the information reported in
the “system” mib group in the mibII tree.Select from:
1: The [typically physical] location of the system.
2: The contact information for the administrator
3: The proper value for the sysServices object.Other options: finished, list
Select section: 1
Configuring: syslocation
Description:
The [typically physical] location of the system.
Note that setting this value here means that when trying to
perform an snmp SET operation to the sysLocation.0 variable will make
the agent return the “notWritable” error code. IE, including
this token in the snmpd.conf file will disable write access to
the variable.
arguments: location_stringThe location of the system: Kyiv
Finished Output: syslocation Kyiv
Section: System Information Setup
Description:
This section defines some of the information reported in
the “system” mib group in the mibII tree.Select from:
1: The [typically physical] location of the system.
2: The contact information for the administrator
3: The proper value for the sysServices object.Other options: finished, list
Select section: 2
Configuring: syscontact
Description:
The contact information for the administrator
Note that setting this value here means that when trying to
perform an snmp SET operation to the sysContact.0 variable will make
the agent return the “notWritable” error code. IE, including
this token in the snmpd.conf file will disable write access to
the variable.
arguments: contact_stringThe contact information: email@gmail.com
Finished Output: syscontact email@gmail.com
Section: System Information Setup
Description:
This section defines some of the information reported in
the “system” mib group in the mibII tree.Select from:
1: The [typically physical] location of the system.
2: The contact information for the administrator
3: The proper value for the sysServices object.Other options: finished, list
Select section: 3
Configuring: sysservices
Description:
The proper value for the sysServices object.
arguments: sysservices_numberdoes this host offer physical services (eg, like a repeater) [answer 0 or 1]: 0
does this host offer datalink/subnetwork services (eg, like a bridge): 0
does this host offer internet services (eg, supports IP): 0
does this host offer end-to-end services (eg, supports TCP): 0
does this host offer application services (eg, supports SMTP): 1Finished Output: sysservices 64
Section: System Information Setup
Description:
This section defines some of the information reported in
the “system” mib group in the mibII tree.Select from:
1: The [typically physical] location of the system.
2: The contact information for the administrator
3: The proper value for the sysServices object.Other options: finished, list
Select section: finished
The configuration information which can be put into snmpd.conf is divided
into sections. Select a configuration section for snmpd.conf
that you wish to create:1: System Information Setup
2: Access Control Setup
3: Trap Destinations
4: Monitor Various Aspects of the Running Host
5: Extending the Agent
6: Agent Operating ModeOther options: finished
Select section: finished
The configuration information which can be put into snmpd.conf is divided
into sections. Select a configuration section for snmpd.conf
that you wish to create:1: System Information Setup
2: Access Control Setup
3: Trap Destinations
4: Monitor Various Aspects of the Running Host
5: Extending the Agent
6: Agent Operating ModeOther options: finished
Select section: 2
Section: Access Control Setup
Description:
This section defines who is allowed to talk to your running
snmp agent.Select from:
1: a SNMPv3 read-write user
2: a SNMPv3 read-only user
3: a SNMPv1/SNMPv2c read-only access community name
4: a SNMPv1/SNMPv2c read-write access community nameOther options: finished, list
Select section: 3
Configuring: rocommunity
Description:
a SNMPv1/SNMPv2c read-only access community name
arguments: community [default|hostname|network/bits] [oid]The community name to add read-only access for: ramzess
The hostname or network address to accept this community name from [RETURN for all]: localhost
The OID that this community should be restricted to [RETURN for no-restriction]:Finished Output: rocommunity pcbsd localhost
Section: Access Control Setup
Description:
This section defines who is allowed to talk to your running
snmp agent.Select from:
1: a SNMPv3 read-write user
2: a SNMPv3 read-only user
3: a SNMPv1/SNMPv2c read-only access community name
4: a SNMPv1/SNMPv2c read-write access community nameOther options: finished, list
Select section: finished
The configuration information which can be put into snmpd.conf is divided
into sections. Select a configuration section for snmpd.conf
that you wish to create:1: System Information Setup
2: Access Control Setup
3: Trap Destinations
4: Monitor Various Aspects of the Running Host
5: Extending the Agent
6: Agent Operating ModeOther options: finished
Select section: 6
Section: Agent Operating Mode
Description:
This section defines how the agent will operate when it
is running.Select from:
1: Should the agent operate as a master agent or not.
2: The system user that the agent runs as.
3: The system group that the agent runs as.
4: The IP address and port number that the agent will listen on.Other options: finished, list
Select section: 4
Configuring: agentaddress
Description:
The IP address and port number that the agent will listen on.
By default the agent listens to any and all traffic from any
interface on the default SNMP port (161). This allows you to
specify which address, interface, transport type and port(s) that you
want the agent to listen on. Multiple definitions of this token
are concatenated together (using ‘:’s).
arguments: [transport:]port[@interface/address],…Enter the port numbers, etc that you want the agent to listen to: localhost
Finished Output: agentaddress localhost
Section: Agent Operating Mode
Description:
This section defines how the agent will operate when it
is running.Select from:
1: Should the agent operate as a master agent or not.
2: The system user that the agent runs as.
3: The system group that the agent runs as.
4: The IP address and port number that the agent will listen on.Other options: finished, list
Select section: finished
The configuration information which can be put into snmpd.conf is divided
into sections. Select a configuration section for snmpd.conf
that you wish to create:1: System Information Setup
2: Access Control Setup
3: Trap Destinations
4: Monitor Various Aspects of the Running Host
5: Extending the Agent
6: Agent Operating ModeOther options: finished
Select section: finished
I can create the following types of configuration files for you.
Select the file type you wish to create:
(you can create more than one as you run this program)1: snmpd.conf
2: snmptrapd.conf
3: snmp.confOther options: quit
Select File: quit
The following files were created:
snmpd.conf installed in /usr/local/share/snmp
Собственно, настройка SNMPD окончена. Запускаем демона:
# /usr/local/etc/rc.d/snmpd start
И проверяем -стартанул ли он:
# sockstat -4 | grep snmpd root snmpd 621 7 tcp4 *:199 *:* root snmpd 621 9 udp4 127.0.0.1:161 *:*
Далее необходим пакет MRTG. Ставим из портов:
# сd /usr/ports/net-mgmt/mrtg/ && make install clean
Запускаем утилитку конфигуратор:
#cfgmaker –global ‘WorkDir: /usr/local/www/data-dist’ \
–global ‘Options[_]: bits,growright’ –output /usr/local/etc/mrtg/mrtg.cfg \
ramzess@localhost
Добавляем в crontab рисование графиков раз в 5 минут:
*/5 * * * * /usr/local/bin/mrtg /usr/local/etc/mrtg/mrtg.cfg
Ну и для красоты используем:
# indexmaker –output /usr/local/www/data-dist/index.html –columns=1 /usr/local/etc/mrtg/mrtg.cfg
Вот и всё. Проще простого. Мой график находится здесь
4 Июнь 2010, в 15:45
Я юзаю катус реальная штука _http://cacti.net/
4 Июнь 2010, в 17:45
Я тоже раньше юзал кактус. Из всей его функциональности реально нужна была только загрузка канала.Стрелять по воробьям из пушки — не вариант =)