Sei sulla pagina 1di 7

MONITOREO DEL SISTEMA – MRTG

MRTG requiere de un servidor Web instalado en la máquina, así como también librerías para generar
gráficos (gd) y herramientas de compilación que serán usadas también por NAGIOS:
Como paso previo, verifiquemos si tenemos los pre requisitos instalados:

yum install httpd gd gd-devel gcc glibc glibc-common

Configuramos para que apache se inicie automáticamente.


En CentOS 7:
systemctl enable httpd
systemctl restart httpd

En CentOS 6:
chkconfig httpd on
service httpd restart

El sitio debería ser accesible mediante:


http://su.ip/
http://127.0.0.1/

El directorio en el que se almacenan las páginas web es:


/var/www/html

Pasos para instalar MRTG

La página web de MRTG es:


http://oss.oetiker.ch/mrtg/

1
1. Instalación de los paquetes
La siguiente instrucción instalará los siguientes paquetes:
 SNMP
 MRTG
yum install mrtg net-snmp net-snmp-utils
Se instalarán también todas las dependencias requeridas.

2. Configurar SNMP para que responda a los requerimientos


Necesitamos monitorear el servidor local (localhost) incluyendo las interfaces de red, el CPU, la
memoria, etc.

Configuramos el fichero principal de SNMP, luego de generar una copia del mismo:
cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.original
vi /etc/snmp/snmpd.conf

El fichero debe quedar así:


com2sec notConfigUser default snmpsecret
group notConfigGroup v1 notConfigUser
view roview included .1
access notConfigGroup "" any noauth exact roview rwview none
syslocation La Paz, Bolivia
syscontact Administrator <su@email.com>
disk /
load 12 14 14
pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat
Guarde el fichero

Ahora, configuramos para que el snmpd se inicie automáticamente y lo activamos.


En CentOS 7:
systemctl enable snmpd
systemctl restart snmpd

En CentOS 6:
chkconfig snmpd on
service snmpd restart

Podemos probar con el comando “snmpwalk” si se puede obtener información del sistema:
snmpwalk -v 1 -c snmpsecret localhost IP-MIB::ipAdEntIfIndex

Esto debería darnos:


[root@centos6 snmp]# snmpwalk -v 1 -c snmpsecret localhost IP-
MIB::ipAdEntIfIndex
IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1
IP-MIB::ipAdEntIfIndex.192.168.100.220 = INTEGER: 2
[root@centos6 snmp]#

En caso de que este comando de error, o timeout, se puede deber a solo 2 motivos:
 El demonio snmpd no fue reiniciado correctamente
 El fichero de configuración snmpd.conf tiene algún error

2
3. Configurar MRTG
Una guía completa de como configurar MRTG se encuentra en esta página web:
http://oss.oetiker.ch/mrtg/doc/index.en.html
Acortaremos los pasos.

Usamos el comando cfgmaker para crear la configuración en /etc/mrtg/mrtg.cfg usamos:


cfgmaker --global 'Options[_]: growright, bits, unknaszero' --ifref=ip
--ifdesc=descr --noreversedns --global 'WorkDir: /var/www/mrtg'
--output=/etc/mrtg/mrtg.cfg snmpsecret@localhost

Finalmente, ejecutamos indexmaker para crear las páginas web iniciales para desplegar los estados
que genere MRTG:
indexmaker --output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg

4. Verificamos el CRON de MRTG


/etc/cron.d/mrtg ejecuta mrtg para monitorear el Sistema:
cat /etc/cron.d/mrtg

Debería darnos:
*/5 * * * * root LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
--lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok

Es decir, se ejecuta MRTG cada 5 minutos.

5. Ejecutamos el comando de MRTG unas 3 veces para que generen los ficheros de datos
LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
--lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok

Verá algunos errores en las 2 o 3 primeras ejecuciones:


[root@centos6 snmp]# LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
--lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok

2016-08-23 14:15:43, Rateup WARNING: /usr/bin/rateup could not read the


primary log file for localhost_192.168.100.220

[root@centos6 snmp]# LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg


--lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok
[root@centos6 snmp]#

3
6. Habilitamos el acceso a la página MRTG
MRTG ya está instalado y corriendo cada 5 minutos.
MRTG ya tiene una página web, pero por defecto está configurada para que solo se pueda ver desde
el servidor local.
Si desea, puede acceder desde el navegador de su servidor local asi:
http://localhost/mrtg
http://127.0.0.1/mrtg

Si desea entrar desde afuera, hay que configurar el fichero de acceso del MRTG
cp /etc/httpd/conf.d/mrtg.conf /etc/httpd/conf.d/mrtg.original
vi /etc/httpd/conf.d/mrtg.conf

El fichero debe quedar así:


#
# This configuration file maps the mrtg output (generated daily)
# into the URL space. By default these results are only accessible
# from the local host.
#
Alias /mrtg /var/www/mrtg

<Location /mrtg>
Order deny,allow
Allow from all
# Allow from 127.0.0.1
# Allow from ::1
# Allow from .example.com
</Location>

Reinicie el servidor web.


En CentOS 7:
systemctl restart httpd

En CentOS 6:
service httpd restart

Ahora, intente ver el resultado de MRTG:


http://su.ip/mrtg

Se está monitoreando solo la red, adicionemos más opciones:

Primero creamos el fichero que nos ayudará a desplegar la carga promedio del sistema.
/var/lib/mrtg/mrtg-loadavg.sh

4
El fichero debe tener este contenido:
#!/bin/sh
# Created by Jehiah Czebotar
# http://www.jehiah.com/
#
# This script is licensed under the GPL
# http://www.gnu.org/copyleft/gpl.html
#
# Date : January 5, 2003
# File : mrtg-loadavg.sh
# Version: 1.0
#########################

#### Sample /etc/mrtg.cfg usage

# Target[spock-cpu]: `scripts/mrtg-loadavg.sh`
# MaxBytes[spock-cpu]: 500
# Title[spock-cpu]: Server CPU Load (5 minute average)
# YLegend[spock-cpu]: Load*100
# ShortLegend[spock-cpu]: load
# Legend1[spock-cpu]: CPU Load (x 100)
# Legend2[spock-cpu]:
# LegendI[spock-cpu]: 1min load
# LegendO[spock-cpu]: 5min load
# PageTop[spock-cpu]: <h1>Server 5-minute average CPU Load</h1>
# Options[spock-cpu]: gauge,nopercent,integer,growright

awk </proc/loadavg '{print ($1*100) "\n" ($2*100) }'


uptime | cut -d" " -f4-7 | sed 's/,//g'
hostname;

Le damos permiso de ejecución:


chmod +x /var/lib/mrtg/mrtg-loadavg.sh

y editamos el fichero de configuración de MRTG:


vi /etc/mrtg/mrtg.cfg

Adicionamos lo siguiente al final del mismo:


LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt,
/usr/share/snmp/mibs/TCP_MIB.txt, /usr/share/snmp/mibs/HOST-RESOURCES-
MIB.txt
#
# Memory Monitoring (Total Versus Available Memory)
#
Target[spock_memory]: memAvailReal.0&memTotalReal.0:snmpsecret@localhost
Title[spock_memory]: Free Memory
PageTop[spock_memory]: <h1>Free Memory</h1>
MaxBytes[spock_memory]: 100000000000
ShortLegend[spock_memory]: B
YLegend[spock_memory]: Bytes
LegendI[spock_memory]: Free
LegendO[spock_memory]: Total
Legend1[spock_memory]: Free memory, not including swap, in bytes
Legend2[spock_memory]: Total memory
Options[spock_memory]: gauge,growright,nopercent
kMG[spock_memory]: k,M,G,T,P,X

5
#
# Memory Monitoring (Percentage usage)
#
Title[spock_mempercent]: Percentage Free Memory
PageTop[spock_mempercent]: <h1>Percentage Free Memory</h1>
Target[spock_mempercent]: (
memAvailReal.0&memAvailReal.0:snmpsecret@localhost ) * 100 / (
memTotalReal.0&memTotalReal.0:snmpsecret@localhost )
options[spock_mempercent]: growright,gauge,transparent,nopercent
Unscaled[spock_mempercent]: ymwd
MaxBytes[spock_mempercent]: 100
YLegend[spock_mempercent]: Memory %
ShortLegend[spock_mempercent]: Percent
LegendI[spock_mempercent]: Free
LegendO[spock_mempercent]: Free
Legend1[spock_mempercent]: Percentage Free Memory
Legend2[spock_mempercent]: Percentage Free Memory

#
# New TCP Connection Monitoring (per minute)
#

Target[spock_newconns]:
tcpPassiveOpens.0&tcpActiveOpens.0:snmpsecret@localhost
Title[spock_newconns]: Newly Created TCP Connections
PageTop[spock_newconns]: <h1>New TCP Connections</h1>
MaxBytes[spock_newconns]: 10000000000
ShortLegend[spock_newconns]: c/s
YLegend[spock_newconns]: Conns / Min
LegendI[spock_newconns]: In
LegendO[spock_newconns]: Out
Legend1[spock_newconns]: New inbound connections
Legend2[spock_newconns]: New outbound connections
Options[spock_newconns]: growright,nopercent,perminute

#
# Established TCP Connections
#

Target[spock_estabcons]: tcpCurrEstab.0&tcpCurrEstab.0:snmpsecret@localhost
Title[spock_estabcons]: Currently Established TCP Connections
PageTop[spock_estabcons]: <h1>Established TCP Connections</h1>
MaxBytes[spock_estabcons]: 10000000000
ShortLegend[spock_estabcons]:
YLegend[spock_estabcons]: Connections
LegendI[spock_estabcons]: In
LegendO[spock_estabcons]:
Legend1[spock_estabcons]: Established connections
Legend2[spock_estabcons]:
Options[spock_estabcons]: growright,nopercent,gauge

6
#
# Disk Usage Monitoring
#

Target[spock_disk]: dskPercent.1&dskPercent.1:snmpsecret@localhost
Title[spock_disk]: Disk Partition Usage
PageTop[spock_disk]: <h1>Disk Partition Usage /</h1>
MaxBytes[spock_disk]: 100
ShortLegend[spock_disk]: %
YLegend[spock_disk]: Utilization
LegendI[spock_disk]: /
LegendO[spock_disk]:
Options[spock_disk]: gauge,growright,nopercent
Unscaled[spock_disk]: ymwd

#
# CPU Server Load Monitoring
#
Target[spock-cpu]: `/var/lib/mrtg/mrtg-loadavg.sh`
MaxBytes[spock-cpu]: 500
Title[spock-cpu]: Average Server Load
YLegend[spock-cpu]: Load
ShortLegend[spock-cpu]: load
Legend1[spock-cpu]: 1min Avg Server Load
Legend2[spock-cpu]: 5min Avg Sever Load
LegendI[spock-cpu]: 1min load
LegendO[spock-cpu]: 5min load
PageTop[spock-cpu]: <h1>Average Server Load</h1>
Options[spock-cpu]: gauge,nopercent,growright
YTicsFactor[spock-cpu]: 0.01
Factor[spock-cpu]: 0.01

Volvemos a generar la página web:


rm -Rf /var/www/mrtg/index.html
indexmaker --output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg

Nuevamente ejecutamos 3 veces el proceso del MRTG (recuerde, se generarán errores) …


[root@centos6 snmp]# LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --
lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok
..
[root@centos6 snmp]# LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --
lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok
[root@centos6 snmp]#

Listo, vuelva a cargar la página.


Permita que MRTG se ejecute por unos 30 minutos y comenzará a ver resultados en sus gráficos.

Potrebbero piacerti anche