Bon tuyaux Linux / *BSD  -   Lundi 12 Avril 2004

<Précédent Suivant>

MRTG via SNMP
Catégorie : Linux / *BSD
par hika hika AT bsdmon DOT com Homepage : http://www.bsdmon.com

1) Installation du port net-snmp
cd /usr/ports/net-mgmt/net-snmp
make install clean

ou si vous avez installé "portupgrade"

portinstall net-snmp

Ensuite, il s'agit de créer un fichier de configuration snmpd.conf
Pour ceci, un utilitaire pratique : snmpconf
snmpconf -i -g basic_setup

Ce programme vous posera une série de question.

Le plus important est de définir les droits d'accès de l'agent snmp et le nom de la community avec son accès par réseau.
Dans notre cas, pour utiliser snmp avec mrtg, il suffit de donner les droits de lecture seule par la "community".
Répondez par "n" aux questions :
"Do you want to allow SNMPv3 read-write user based access ?"
"Do you want to allow SNMPv3 read-only user based access ?"
"Do you want to allow SNMPv1/v2 read-write community access ?"
Et répondez par "y" à la question :
"Do you want to allow SNMPv1/v2 read-only community access ?"

Le choix du nom de la "community" peut être comme un mot de passe que vous seul doit connaître sur votre réseau.
Un nom comme "local" pour un accès depuis 127.0.0.1 peut suffire pour notre utilisation.
Les questions correspondants à ces paramètres :
"The community name to add read-only access for :"
"The hostname or network address to accept this community name from :"

2) Installation de mrtg
cd /usr/ports/net-mgmt/mrtg
make install clean

ou si vous avez installé "portupgrade"

portinstall mrtg

Vous pouvez ensuite créer un fichier mrtg.cfg de base grâce à la commande :
cfgmaker <community>@<machine> > /path/to/mrtg.cfg
exemple : cfgmaker local@localhost > /usr/local/etc/mrtg/mrtg.cfg

N'oubliez pas de modifier la directive "WorkDir" dans votre nouveau fichier mrtg.cfg.
Cette directive permet de définir l'emplacement des fichiers .png et .html que génèrera mrtg.

Un petit exemple de mrtg.cfg :

<mrtg.cfg>

# Created by
# /usr/local/bin/cfgmaker local@localhost


### Global Config Options

# for UNIX
WorkDir: /var/www/mrtg

# or for NT
# WorkDir: c:\mrtgdata

### Global Defaults

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

EnableIPv6: no

######################################################################
# System: sdf1.macross.vfx
# Description: FreeBSD sdf1.macross.vfx 4.9-STABLE FreeBSD 4.9-STABLE #8: Sun Mar i386
# Contact: hika@bsdmon.com
# Location: geeky room
######################################################################


### Interface 1 >> Descr: 'rl0' | Name: | Ip: '192.168.1.1' | Eth: ###

Target[rl0]: 1:local@localhost:
SetEnv[rl0]: MRTG_INT_IP="192.168.1.1" MRTG_INT_DESCR="rl0"
MaxBytes[rl0]: 1250000
Title[rl0]: Traffic Analysis for rl0 -- SDF1
PageTop[rl0]: <H1>Traffic Analysis for rl0 -- SDF1</h1>
<TABLE>
<TR><TD>System:</td> <TD>SDF1 in geeky room</td></tr>
<TR><TD>Maintainer:</td> <TD>hika@bsdmon.com</td></tr>
<TR><TD>Description:</td><TD>rl0 </td></tr>
<TR><TD>ifType:</td> <TD>ethernetCsmacd (6)</td></tr>
<TR><TD>ifName:</td> <TD></td></tr>
<TR><TD>Max Speed:</td> <TD>1250.0 kBytes/s</td></tr>
<TR><TD>Ip:</td> <TD>192.168.1.1 (sdf1.macross.vfx)</td></tr>
</table>
Options[rl0]: growright

LoadMIBs:/usr/local/share/snmp/mibs/UCD-SNMP-MIB.txt, /usr/local/share/snmp/mibs/TCP-MIB.txt, /usr/local/share/snmp/mibs/HOST-RESOURCES-MIB.txt, /usr/local/share/snmp/mibs/DISMAN-EVENT-MIB.txt

### Disk Percent usage ###
Target[ad0]: dskPercent.1&dskPercent.2:local@localhost
RouterUptime[ad0]: local@localhost
MaxBytes[ad0]: 100
Title[ad0]: DISK USAGE -- SDF1
PageTop[ad0]: <H1>DISK / and /usr Usage % -- SDF1</h1>
<TABLE>
<TR><TD>System:</td> <TD>SDF1 in geeky room</td></tr>
<TR><TD>Maintainer:</td> <TD>hika@bsdmon.com</td></tr>
<TR><TD>Description:</td><TD>ad0 Disk usage </td></tr>
<TR><TD>Device</td> <TD>/dev/ad0s1a /dev/ad0s2e</td></tr>
</table>
Unscaled[ad0]: ymwd
ShortLegend[ad0]: %
YLegend[ad0]: DISK USAGE
Legend1[ad0]: /usr disk
Legend2[ad0]: / disk
Legend3[ad0]:
Legend4[ad0]:
LegendI[ad0]: /usr disk
LegendO[ad0]: / disk
Options[ad0]: growright,gauge,nopercent

### / disk usage ###
Target[ad0s1a]: dskAvail.2&dskTotal.2:local@localhost
RouterUptime[ad0s1a]: local@localhost
MaxBytes[ad0s1a]: 5000000
Title[ad0s1a]: DISK / USAGE -- SDF1
PageTop[ad0s1a]: <H1>DISK / usage -- SDF1</h1>
<TABLE>
<TR><TD>System:</td> <TD>SDF1 in geeky room</td></tr>
<TR><TD>Maintainer:</td> <TD>hika@bsdmon.com</td></tr>
<TR><TD>Description:</td><TD>ad0s1a / Disk usage </td></tr>
<TR><TD>Device</td> <TD>/dev/ad0s1a</td></tr>
</table>
Unscaled[ad0s1a]: ymwd
ShortLegend[ad0s1a]:
YLegend[ad0s1a]: DISK / USAGE
Legend1[ad0s1a]: available
Legend2[ad0s1a]: total
Legend3[ad0s1a]:
Legend4[ad0s1a]:
LegendI[ad0s1a]: available
LegendO[ad0s1a]: total
Options[ad0s1a]: growright,gauge,nopercent

### /usr disk usage ###
Target[ad0s2e]: dskAvail.1&dskTotal.1:local@localhost
RouterUptime[ad0s2e]: local@localhost
MaxBytes[ad0s2e]: 11000000
Title[ad0s2e]: DISK /usr USAGE -- SDF1
PageTop[ad0s2e]: <H1>DISK /usr usage -- SDF1</h1>
<TABLE>
<TR><TD>System:</td> <TD>SDF1 in geeky room</td></tr>
<TR><TD>Maintainer:</td> <TD>hika@bsdmon.com</td></tr>
<TR><TD>Description:</td><TD>ad0s2e /usr Disk usage </td></tr>
<TR><TD>Device</td> <TD>/dev/ad0s2e</td></tr>
</table>
Unscaled[ad0s2e]: ymwd
ShortLegend[ad0s2e]:
YLegend[ad0s2e]: DISK /usr USAGE
Legend1[ad0s2e]: available
Legend2[ad0s2e]: total
Legend3[ad0s2e]:
Legend4[ad0s2e]:
LegendI[ad0s2e]: available
LegendO[ad0s2e]: total
Options[ad0s2e]: growright,gauge,nopercent

### TCP open active/passive connection ###
Target[tcpopen]: tcpActiveOpens.0&tcpPassiveOpens.0:local@localhost
MaxBytes[tcpopen]: 1000000
Title[tcpopen]: Open TCP active/passive connections -- SDF1
PageTop[tcpopen]: <H1>Open TCP active/passive connections -- SDF1</h1>
<TABLE>
<TR><TD>System:</td> <TD>SDF1 in geeky room</td></tr>
<TR><TD>Maintainer:</td> <TD>hika@bsdmon.com</td></tr>
<TR><TD>Description:</td><TD>TCP Open active connection</td></tr>
<TR><TD>Protocol</td> <TD>TCP</td></tr>
</table>
ShortLegend[tcpopen]: ~
YLegend[tcpopen]: Connections
Legend1[tcpopen]: Open TCP active connections
Legend2[tcpopen]: Open TCP passive connections
LegendI[tcpopen]: Active open connections:
LegendO[tcpopen]: Passive open connections:
Options[tcpopen]: nopercent,growright,gauge,noinfo

### Available memory, Total real memory ###
Target[mem]: memAvailReal.0&memTotalReal.0:local@localhost
MaxBytes[mem]: 1000000
Title[mem]: Memory -- SDF1
PageTop[mem]: <H1>Memory -- SDF1</h1>
<TABLE>
<TR><TD>System:</td> <TD>SDF1 in geeky room</td></tr>
<TR><TD>Maintainer:</td> <TD>hika@bsdmon.com</td></tr>
<TR><TD>Description:</td><TD>Available memory, not including swap, in bytes</td></tr>
</table>
kMG[mem]: k,M,G,T,P,X
YLegend[mem]: Memory in bytes
ShortLegend[mem]: bytes
LegendI[mem]: Available Memory:
LegendO[mem]: Total Memory:
Legend1[mem]: Available memory, not including swap, in bytes
Legend2[mem]: Total real memory
Options[mem]: nopercent,growright,gauge,noinfo

### Available swap, Total real swap ###
Target[swap]: memAvailSwap.0&memTotalSwap.0:local@localhost
MaxBytes[swap]: 1000000
Title[swap]: Swap -- SDF1
PageTop[swap]: <H1>Swap -- SDF1</h1>
<TABLE>
<TR><TD>System:</td> <TD>SDF1 in geeky room</td></tr>
<TR><TD>Maintainer:</td> <TD>hika@bsdmon.com</td></tr>
<TR><TD>Description:</td><TD>Swap memory in bytes</td></tr>
<TR><TD>Device</td> <TD>/dev/ad0s1b</td></tr>
</table>
kMG[swap]: k,M,G,T,P,X
YLegend[swap]: Swap in bytes
ShortLegend[swap]: bytes
LegendI[swap]: Available swap:
LegendO[swap]: Total swap:
Legend1[swap]: Swap memory in bytes
Legend2[swap]: Total swap
Options[swap]: nopercent,growright,gauge,noinfo


### CPU LOAD user % ###
Target[cpu]: ssCpuUser.0&ssCpuIdle.0:local@localhost
RouterUptime[cpu]: local@localhost
MaxBytes[cpu]: 100
Title[cpu]: CPU LOAD -- SDF1
PageTop[cpu]: <H1>User CPU Load % -- SDF1</h1>
<TABLE>
<TR><TD>System:</td> <TD>SDF1 in geeky room</td></tr>
<TR><TD>Maintainer:</td> <TD>hika@bsdmon.com</td></tr>
<TR><TD>Description:</td><TD>CPU LOAD user</td></tr>
</table>
Unscaled[cpu]: ymwd
ShortLegend[cpu]: %
YLegend[cpu]: CPU Utilization
Legend1[cpu]: User CPU in % (Load)
Legend2[cpu]: Idle CPU in % (Load)
Legend3[cpu]:
Legend4[cpu]:
LegendI[cpu]: User
LegendO[cpu]: Idle
Options[cpu]: growright,gauge,nopercent

### CPU LOAD user + system % ###
Target[usrsys]: ssCpuUser.0&ssCpuSystem.0:local@localhost
RouterUptime[usrsys]: local@localhost
MaxBytes[usrsys]: 100
Title[usrsys]: CPU LOAD -- SDF1
PageTop[usrsys]: <H1>CPU (user and system) Load % -- SDF1</h1>
<TABLE>
<TR><TD>System:</td> <TD>SDF1 in geeky room</td></tr>
<TR><TD>Maintainer:</td> <TD>hika@bsdmon.com</td></tr>
<TR><TD>Description:</td><TD>CPU LOAD (user + system)</td></tr>
</table>
Unscaled[usrsys]: ymwd
ShortLegend[usrsys]: %
YLegend[usrsys]: CPU Utilization
Legend1[usrsys]: User CPU in % (Load)
Legend2[usrsys]: System CPU in % (Load)
Legend3[usrsys]:
Legend4[usrsys]:
LegendI[usrsys]: User
LegendO[usrsys]: System
Options[usrsys]: growright,gauge,nopercent

### CPU LOAD active % ###
Target[cpusum]: ssCpuUser.0&ssCpuUser.0:local@localhost + ssCpuSystem.0&ssCpuSystem.0:local@localhost
RouterUptime[cpusum]: local@localhost
MaxBytes[cpusum]: 100
Title[cpusum]: CPU LOAD -- SDF1
PageTop[cpusum]: <H1>Active CPU Load % -- SDF1</h1>
<TABLE>
<TR><TD>System:</td> <TD>SDF1 in geeky room</td></tr>
<TR><TD>Maintainer:</td> <TD>hika@bsdmon.com</td></tr>
<TR><TD>Description:</td><TD>Active CPU LOAD</td></tr>
</table>
Unscaled[cpusum]: ymwd
ShortLegend[cpusum]: %
YLegend[cpusum]: CPU Utilization
Legend1[cpusum]: Active CPU in % (Load)
Legend2[cpusum]:
Legend3[cpusum]:
Legend4[cpusum]:
LegendI[cpusum]: Active
LegendO[cpusum]:
Options[cpusum]: growright,gauge,nopercent

### System processes ###
Target[proc]: hrSystemProcesses.0&hrSystemProcesses.0:local@localhost
RouterUptime[proc]: local@localhost
MaxBytes[proc]: 4000
Title[proc]: System processes -- SDF1
PageTop[proc]: <H1>System processes -- SDF1</h1>
<TABLE>
<TR><TD>System:</td> <TD>SDF1 in geeky room</td></tr>
<TR><TD>Maintainer:</td> <TD>hika@bsdmon.com</td></tr>
<TR><TD>Description:</td><TD>System processes number</td></tr>
</table>
ShortLegend[proc]: ~
YLegend[proc]: Processes number
Legend1[proc]: System processes
Legend2[proc]:
Legend3[proc]:
Legend4[proc]:
LegendI[proc]: System processes
LegendO[proc]:
Options[proc]: growright,gauge,nopercent

</mrtg>


Ensuite vous pouvez créer une page d'accueil pour vos graphs mrtg avec la commande :
indexmaker /path/to/mrtg.cfg > <WorkDir>/index.htm

Enfin, taper :
mrtg /path/to/mrtg.cfg

Ce qui générera vos résultats tant attendus.

Vous pouvez ensuite utiliser le daemon cron pour effectuer la commande ci dessus à intervalle régulier.
Par exemple avec un crontab suivant :

<crontab>

PATH=/usr/bin:/usr/sbin:/sbin:/bin:/usr/local/bin:/usr/local/sbin:.
10/* * * * * mrtg /path/to/mrtg.cfg

</crontab>

<Précédent Suivant>
FreeBSD Mall Smarty Template Engine Page générée le Jeudi 25 Avril 2024 09:34:46 Powered by FreeBSD
POWERED BY FreeBSD, Apache, PHP, PostgreSQL, Code & design by Hika
BSD Daemon Copyright 1988 by Marshall Kirk McKusick. All Rights Reserved.