Bueno os voy a explicar como configurar Graphite, lo haremos en una maquina EC2 de las que son gratuitas. https://aws.amazon.com/es/free/.
Que es Graphite?
Graphite es una herramienta que nos permite básicamente crear gráficos sobre unos datos que le vamos enviando periódicamente desde la máquina que queremos monitorizar, es muy sencillo y muy potente ya que tiene miles de funciones para hacer realmente cosas muy interesantes.
En el post Estadísticas VMware con PowerCLI y Graphite. ya se hacia una pequeña introducción y había unos ejemplos donde podéis ver el escenario final.
Pues venga al lio!
Tenemos que tener instalados una serie de paquetes, tales como estos.
apt-get install python apache2 python-twisted python-memcache libapache2-mod-python python-django libpixman-1-0 python-cairo python-django-tagging libapache2-mod-wsg python-cairo-dev python-django libapache2-mod-python python-setuptools git
Ahora nos bajaremos las ramas desde github.com
git clone https://github.com/graphite-project/graphite-web.git git clone https://github.com/graphite-project/carbon.git git clone https://github.com/graphite-project/whisper.git
En este punto, tenemos los tres repositorios en la rama masters, yo al ser un entorno de pruebas lo probare en esas versiones, si queréis algo mas estable esta la versión 0.9.10, que podéis cambiar a ella de la siguiente forma.
cd graphite-web git checkout 0.9.10 cd .. cd carbon git checkout 0.9.10 cd .. cd whisper git checkout 0.9.10 cd ..
Y si aún lo queréis mas fácil podéis instalarlo desde el repositorio.
apt-get install python-whisper graphite-carbon
Ahora vamos a instalar cada uno de los componentes, primero whisper, que es la base de datos donde iremos guardando las metricas.
Desde la carpeta de whisper haremos.
sudo python setup.py install
Y dentro de la carpeta carbon
sudo python setup.py install
Ahora vamos a configurar carbon, utilizaremos los ficheros por defecto.
cd /opt/graphite/conf cp carbon.conf.example carbon.conf cp storage-schemas.conf.example storage-schemas.conf
Como podemos ver en storage-schema.conf la configuración tiene un estilo tal que.
vi cd /opt/graphite/conf/storage-schemas.conf [default_1min_for_1day] pattern = .* retentions = 60s:1d
Esto quiere decir que nos guardara una granularidad de 60 segundos durante 1 día, como vemos es muy poco así que lo vamos a cambiar a lo siguiente.
[default_1min_for_1month_15min_for_2years] pattern = .* retentions = 60s:30d,15m:1y
Que quiere decir que nos guardara una granularidad de 60 segundos durante 30 días y 15 minutos durante 1 años.
Ahora vamos a la carperta graphite-web, para configurar el entrono
python check-dependencies.py
Es posible que nos de algun error de dependencias en mi caso cuando instale me decia
[REQUIRED] Unable to import the 'pytz' module, do you have pytz module installed for python 2.7.4? [REQUIRED] Unable to import the 'pyparsing' module, do you have pyparsing module installed for python 2.7.4?
La forma mas sencilla de instalar esto es con pip asi que haremos
apt-get install python-pip easy_install pyparsing==1.5.7
Y en el caso de pyparsing seleccionamos el compatible con la versión, en mi caso 1.5.7
Y una vez tengamos las dependencias cumplidas instalamos graphite-web
python setup.py install
Pues ahora que ya tenemos los tres componentes instalados, vamos a configurar el apache para que nos sirva las peticiones.
Yo lo estoy haciendo sobre una Debian y haremos un virtual host tal que.
vim /etc/apache2/sites-available/graphite ------------------------------------------- # This needs to be in your server's config somewhere, probably # the main httpd.conf # NameVirtualHost *:80 # This line also needs to be in your server's config. # LoadModule wsgi_module modules/mod_wsgi.so # You need to manually edit this file to fit your needs. # This configuration assumes the default installation prefix # of /opt/graphite/, if you installed graphite somewhere else # you will need to change all the occurances of /opt/graphite/ # in this file to your chosen install location. <IfModule !wsgi_module.c> LoadModule wsgi_module modules/mod_wsgi.so </IfModule> # XXX You need to set this up! # Read http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGISocketPrefix WSGISocketPrefix /var/run/wsgi <VirtualHost *:80> ServerName graphite DocumentRoot "/opt/graphite/webapp" ErrorLog /opt/graphite/storage/log/webapp/error.log CustomLog /opt/graphite/storage/log/webapp/access.log common # I've found that an equal number of processes & threads tends # to show the best performance for Graphite (ymmv). WSGIDaemonProcess graphite processes=5 threads=5 display-name='%{GROUP}' inactivity-timeout=120 WSGIProcessGroup graphite WSGIApplicationGroup %{GLOBAL} WSGIImportScript /opt/graphite/conf/graphite.wsgi process-group=graphite application-group=%{GLOBAL} # XXX You will need to create this file! There is a graphite.wsgi.example # file in this directory that you can safely use, just copy it to graphite.wgsi WSGIScriptAlias / /opt/graphite/conf/graphite.wsgi Alias /content/ /opt/graphite/webapp/content/ <Location "/content/"> SetHandler None </Location> # XXX In order for the django admin site media to work you # must change @[email protected] to be the path to your django # installation, which is probably something like: # /usr/lib/python2.6/site-packages/django Alias /media/ "@[email protected]/contrib/admin/media/" <Location "/media/"> SetHandler None </Location> # The graphite.wsgi file has to be accessible by apache. It won't # be visible to clients because of the DocumentRoot though. <Directory /opt/graphite/conf/> Order deny,allow Allow from all </Directory> </VirtualHost> ---------------------------------------- ln -s ../sites-available/graphite ../sites-enabled/001-graphite
El virtualhost que os puse más arriba es el que trae el como ejemplo, pero cambiando la ruta de «WSGISocketPrefix /var/run/wsgi» ya que sino no encuentra el wsgi, ahora preparamos el resto de configuraciones para que vaya correctamente.
cd graphite/examples sudo cp example-graphite-vhost.conf /etc/apache2/sites-available/default sudo cp /opt/graphite/conf/graphite.wsgi.example /opt/graphite/conf/graphite.wsgi sudo vim /etc/apache2/sites-available/default # moved 'WSGIImportScript /opt/gr..' to right before virtual host since it gave me an error saying # WSGIImportScript cannot occur within <VirtualHost> section # if this path does not exist make it!!!!!! # /etc/httpd/wsgi sudo mkdir /etc/httpd sudo mkdir /etc/httpd/wsgi sudo /etc/init.d/apache2 reload
Ahora lo que vamos hacer es crear la base de datos donde guardaremos las métricas
cd /opt/graphite/webapp/graphite sudo python manage.py syncdb
cd /opt/graphite/webapp/graphite cp local_settings.py.example local_settings.py
Si nos da algun problema al crear la base de datos, pondremos lo siguiente en el fichero de local_settings.py
DATABASES = { 'default': { 'NAME': '/opt/graphite/storage/graphite.db', 'ENGINE': 'django.db.backends.sqlite3', 'USER': '', 'PASSWORD': '', 'HOST': '', 'PORT': '' } }
Vamos a configurar el wsgi para que trabaje fino fino con apache.
Debemos asegurar sobretodo que tenemos bien configurado la carga del modulo, lo deberemos mirar en el fichero wsgi.load
cat /etc/apache2/mods-enabled/wsgi.load LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so
Y por ultimo arrancamos graphite
sudo ./bin/carbon-cache.py start
Y comprobamos la configuración de apache
apachectl -t Syntax OK
Y probamos en la url.
http://ipservidor/ y veremos algo tal que esto
Bueno ahora solo nos quedará enviarle los datos a graphite, en el post Estadísticas VMware con PowerCLI y Graphite ya hacia una pequeña introducción, pero en breve haré otro post explicando más en detalle como enviar los datos.
Ale a disfrutarlo
2 comentarios en «Instalación y configuración de Graphite + wsgi»