Configurar MRTG con SNMP bajo Linux
Todo esto es posible hacerlo gracias a una utilidad llamada MRTG (Multi Router Traffic Grapher), que recoge la información de nuestro sistema con SNMP (Simple Network Management Protocol) y la muestra en una interface web.
Así, podemos obtener gráficos como éste:

A continuación se detalla el proceso de instalación y configuración.
Cómo es habitual en mis artículos, basaré el proceso de instalación en una máquina con Debian, aunque no debería ser mayor problema adaptarlo a cualquier distribución.
Empezaremos por instalar SNMP:
newton:~# apt-get install snmp snmpd
Una vez instalado, pasaremos a editar el archivo de configuración, /etc/snmp/snmpd.conf
Si lo que nos interesa es tan sólo consultar al servidor SNMP desde nuestra máquina (para MRTG), nos bastará con incluir la siguiente línea en la configuración para permitir la lectura desde localhost:
com2sec readonly 127.0.0.1 public
Reiniciamos el servicio para actualizar la configuración:
newton:~# /etc/init.d/snmpd restart
Comprobamos que la configuración es correcta y tenemos acceso, deberían aparecer múltiples líneas sobre nuestro sistema:
newton:/etc/snmp# snmpwalk -v 1 -c public localhost system
SNMPv2-MIB::sysDescr.0 = STRING: Linux newton 2.4.27-da-1 #2 Tue Oct 11 21:54:02 CEST 2005 i686 SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10 SNMPv2-MIB::sysUpTime.0 = Timeticks: (5331) 0:00:53.31El siguiente paso a realizar es instalar MRTG:
newton:~# apt-get install mrtg
Para hacer una configuración inicial, la cual nos detectará automáticamente las interfaces de red, ejecutaremos lo siguiente:
newton:~# cfgmaker --community public --output /etc/mrtg.cfg localhost
--base: Get Device Info on public@localhost: --base: Vendor Id: --base: Populating confcache --snpo: confcache public@localhost: Descr lo --> 1 --snpo: confcache public@localhost: Descr eth0 --> 2Pasaremos a editar el archivo de configuración /etc/mrtg.cfg que nos ha creado el cfgmaker para añadir otros gráficos interesantes:
Tan solo debemos añadir el código que se indica a continuación en el orden que queremos que nos aparezcan los gráficos en la web.
Consumo de CPU:
LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt Target[localhost.cpu]:ssCpuRawUser.0&ssCpuRawUser.0:public@localhost + ssCpuRawSystem.0& ssCpuRawSystem.0:public@localhost + ssCpuRawNice.0&ssCpuRawNice.0:public@localhost RouterUptime[localhost.cpu]: public@localhost MaxBytes[localhost.cpu]: 100 Title[localhost.cpu]: CPU Load PageTop[localhost.cpu]: Carga de CPU % Unscaled[localhost.cpu]: ymwd ShortLegend[localhost.cpu]: % YLegend[localhost.cpu]: Uso de CPU Legend1[localhost.cpu]: CPU Activa en % (Carga) Legend2[localhost.cpu]: Legend3[localhost.cpu]: Legend4[localhost.cpu]: LegendI[localhost.cpu]: Active LegendO[localhost.cpu]: Options[localhost.cpu]: growright,nopercentMemoria RAM:
LoadMIBs: /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt Target[localhost.mem]: .1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.6.0:public@localhost PageTop[localhost.mem]: Memoria RAM Options[localhost.mem]: nopercent,growright,gauge,noinfo Title[localhost.mem]: Memoria Libre MaxBytes[localhost.mem]: 1000000 kMG[localhost.mem]: k,M,G,T,P,X YLegend[localhost.mem]: bytes ShortLegend[localhost.mem]: bytes LegendI[localhost.mem]: Free Memory: LegendO[localhost.mem]: Legend1[localhost.mem]: Free memory, not including swap, in bytesMemoria SWAP:
LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt Target[localhost.swap]: memAvailSwap.0&memAvailSwap.0:public@localhost PageTop[localhost.swap]: Memoria Swap Options[localhost.swap]: nopercent,growright,gauge,noinfo Title[localhost.swap]: Memoria Libre MaxBytes[localhost.swap]: 1000000 kMG[localhost.swap]: k,M,G,T,P,X YLegend[localhost.swap]: bytes ShortLegend[localhost.swap]: bytes LegendI[localhost.swap]: Memoria Libre: LegendO[localhost.swap]: Legend1[localhost.swap]: Swap memory avail, in bytesUna vez tengamos todos los gráficos que nos interesen, debemos generar el directorio web de MRTG:
newton:~# indexmaker --output /var/www/mrtg/index.html /etc/mrtg.cfg
Ahora tan sólo nos quedará añadir a nuestro crontab a MRTG para que actualice los gráficos:
Editamos el crontab de root (crontab -e), y añadimos la siguiente línea que actualizará cada 5 minutos los gráficos:
*/5 * * * * mrtg /etc/mrtg.cfg
En principio esto es todo, aunque por supuesto, puede ampliarse muchísimo añadiendo otros gráficos.
Más información:
MRTG
MRTG Implementation Manual
Target[localhost.cpu]:ssCpuRawUser.0&ssCpuRawUser.0:public@localhost + ssCpuRawSystem.0&
ssCpuRawSystem.0:public@localhost + ssCpuRawNice.0&ssCpuRawNice.0:public@localhost
En el post aparece como si fueran dos líneas, pero debe ir en una misma:
Target[localhost.cpu]:ssCpuRawUser.0&ssCpuRawUser.0:public@localhost + ssCpuRawSystem.0&ssCpuRawSystem.0:public@localhost + ssCpuRawNice.0&ssCpuRawNice.0:public@localhost
Elimina el salto de línea y verás como funciona.
---
www.gra2.com
in.solit.us: Upload and share your files