Webapp¶
Documentation¶
Informations¶
- This module is a Web server created for visualize data from Storage(s). In few lines Webapp purposes followings stuff:
- Authentication and authorization made by user and group management
- Multiple storga management
- REST API interface
- Storages’ API centralization
Unlike other web graph system, Numeter doesn’t only purpose a graph tree. It allow users to organize Data Sources in custom level of displaying.
WebApp is completly independant from other Numeter modules. The only connection point is Storage’s REST API.
External Links¶
Troubleshooting¶
Configuration¶
Webapp configuration is located in /etc/numeter/numeter_webapp.cfg`
.
database
section¶
engine
¶
Warning
Required
- This setting defines which database backend will be used. Choose among Django engine or a custom. Default Django’s engines are:
django.db.backends.mysql
django.db.backends.postgresql_psycopg2
django.db.backends.sqlite3
django.db.backends.oracle
You can use a database backend that doesn’t ship with Django by setting ENGINE to a fully-qualified path (i.e. mypackage.backends.whatever
).
Example:
engine = django.db.backends.sqlite3
name
¶
Warning
Required
This setting defines name of the database to use. For SQLite, it’s the full path to the database file.
Examples:
name = numeter
name = /var/db/numeter.db # with Sqlite
user
¶
Note
Not required with Sqlite
This setting defines username to use when connecting to the database.
Example:
user = numeter
password
¶
Note
Not required with Sqlite
This setting defines password to use when connecting to the database.
Example:
password = yourpass
host
¶
Note
Optionnal
This setting defines host to use when connecting to the database. An empty string means localhost.
Example:
host = db.my.lan
port
¶
Note
Optionnal
This setting defines port to use when connecting to the database. An empty string means the default port.
Example:
port = 3306
cache
section¶
use_cache
¶
Note
Optionnal, defaults to False
.
This setting defines if a cache backend will be used.
Example:
use_cache = True
location
¶
Warning
Required if use_cache = True
This setting defines location of the cache to use. This might be the directory for a file system cache, a host and port for a memcache server, or simply an identifying name for a local memory cache.
Example:
location = unix:/var/run/memcached.sock
timeout
¶
Note
Optionnal, defaults to 300
.
This setting defines number of seconds before a cache entry is considered stale.
Example:
timeout = 3000
max_entries
¶
Note
Optionnal, defaults to 300
.
This setting defines maximum number of entries allowed in the cache before old values are deleted.
Example:
max_entries = 3000
storage
section¶
timeout
¶
Note
Optionnal, defaults to 5
.
This setting defines timeout for connection to storages.
Example:
timeout = 10
global
section¶
admins
¶
Warning
Required
This setting is a tuple that lists people who get code error notifications.
Example:
admins = [ ('admin', 'admin@locahost') ]
allowed_hosts
¶
Note
Optionnal, defaults to ['*']
.
This setting is a list of strings representing the host/domain names that this site can serve. String `‘*’`` representing all.
Example:
admins = ['numeter.my.lan','numeter.lan']
timezone
¶
Warning
Required
This setting defines time zone for this installation.
Example:
timezone = Europe/Paris
language_code
¶
Note
Optionnal, defaults to en-us
.
This setting defines default language of website.
Example:
language_code = en-us
media_root
¶
Note
Optionnal, defaults to /var/www/numeter/media/
.
This setting defines location of media files. In facts, a folder named graphlib will be created in. And each folder inside will be a graphic JavaScript library which user will choose.
By default media_root
‘s tree is the following:
media_root
|- graphlib
|- dygraph
|- dygraph-combined.js
|- dygraph-numeter.js
The default JavaScript library is Dygraph.
Example:
media_root = /var/www/numeter/media/
secret_key_file
¶
Note
Optionnal, defaults to /etc/numeter/secret_key.txt
.
This setting defines location of secret key file.
Example:
media_root = /etc/key.txt
logging
section¶
use_logging
¶
Note
Optionnal, defaults to False
.
This setting defines if logging will be used. Be sure to have correct logging locations with writing rigth, else webapp won’t launch.
Example:
use_logging = False
info_file
¶
Note
Optionnal, defaults to /var/log/numeter/webapp/info.log
.
This setting defines location of info log file.
Example:
info_file = /tmp/info.log
error_file
¶
Note
Optionnal, defaults to /var/log/numeter/webapp/error.log
.
This setting defines location of error log file.
Example:
error_file = /tmp/error.log
file_size
¶
Note
Optionnal, defaults to 1000000
.
This setting defines size of log file before rotate. Size is in byte.
Example:
file_size = 2000000
debug
section¶
debug
¶
Note
Optionnal, defaults to False
.
Warning
Never set as True in prodiction environment, it could be a real leak of informations.
This setting defines if debuging is enabled.
Example:
debug = True
use_mock_storage
¶
Note
Optionnal, defaults to False
.
This setting defines if Mock Storage is enabled. Useful for test numeter without other modules. Two mocks are available over /mock/X/
, where X
is 1
or 2
.
Example:
use_mock_storage = True
use_debug_toolbar
¶
Note
Optionnal, defaults to False
, set as False
if debug = False
.
This setting defines if Django Debug Toolbar is enabled.
Example:
use_debug_toolbar = True
debug_internal_ips
¶
Note
Optionnal, defaults to ['127.0.0.1']
.
This setting is a list of IPs which use Debug Toolbar.
Example:
debug_internal_ips = ['192.168.0.2','192.168.0.3']
Installation¶
Debian packages¶
Build your own Debian packages with git-buildpackage or pbuilder for exemple or use numeter repo : http://repo.numeter.com (coming soon)
apt-get install numeter-webapp
Manual¶
- Depends:
- python-django
- django-rest-framework
- django-filter
Django and rest framework setup¶
You need Django >= 1.5
so you need at least wheezy-backports
sources. You also need rest-framework
and django-filter
From packages :
echo 'deb http://ftp.fr.debian.org/debian wheezy-backports main' >> /etc/apt/sources.list.d/debian-backports.list
apt-get update
apt-get install -t wheezy-backports python-django python-mimeparse
pip install djangorestframework==2.4.0
pip install django-filter
Numeter Webapp setup¶
Get sources
git clone https://github.com/enovance/numeter
Launch the setup
cd numeter/web-app
python setup.py install
Configure¶
Webapp’s settings are by default in /etc/numeter/numeter_webapp.cfg
.
You have to define following stuff:
- A database backend
- A web frontend
- Optionnaly a cache backend
Backend database¶
All Django’s database engine are supported, feel free to test third engine.
MySQL
Install python requirements:
apt-get install mysql-server mysql-client
apt-get install python-mysqldb
Create valid user and database:
CREATE DATABASE numeter;
GRANT ALL ON numeter.* TO numeter@'localhost' IDENTIFIED BY 'yourpass';
Edit Webaap configuration file, /etc/numeter/numeter_webapp.cfg
sed -i -re '
s/^engine.*/engine = django.db.backends.mysql/ ;
s/^name.*/name = numeter/ ;
s/^user.*/user = numeter/ ;
s/^password.*/password = yourpass/ ;
s/^host.*/host = localhost/ ;
s/^port.*/port = 3306/' /etc/numeter/numeter_webapp.cfg
Sqlite3
apt-get install sqlite3
Note
You do not need to create database. Only choose a file which writable by django user.
Numeter webapp configuration¶
Edit Webapp configuration file, follow comments inside for help
vim /etc/numeter/numeter_webapp.cfg
If you are sure to have a good database configuration
numeter-webapp syncdb
Note
It will ask you to create a first superuser. If you choose ‘no’, it will be possible to make it with numeter-webapp add-user -S
.
Use a web front¶
We advise to use Apache + mod_wsgi or Nginx + uWSGI. The Django embebbed webserver is usefull for a fast launch witout configuration.
Django embebbed webserver
numeter-webapp runserver 0.0.0.0:8000
Warning
Not recommended in production environment.
Apache
Install mod wsgi :
apt-get install libapache2-mod-wsgi
a2enmod wsgi
Copy the site template in your apache configuration:
cp web-app/extras/numeter-apache.example /etc/apache2/sites-available/numeter-webapp
# For packaged setup /usr/share/doc/numeter/webapp/numeter-webapp
RESTFW_DIR=$(dirname $(python -c 'import rest_framework;print rest_framework.__file__'))
NUMETER_DIR=$(dirname $(python -c 'import numeter_webapp;print numeter_webapp.__file__'))
sed -i "s#@APP_DIR@#$NUMETER_DIR# ; "s#@RESTFW_DIR@#$RESTFW_DIR# ; s/ServerName.*/ServerName YoursServer/" /etc/apache2/sites-available/numeter-webapp
a2ensite numeter-webapp
Note
You can customize it for match with your security requirements.
With debian example config are located in /usr/share/doc/numeter-storage/
Nginx
Install nginx and uwsgi :
apt-get install nginx uwsgi uwsgi-plugin-python
Copy the site template in your apache configuration:
NUMETER_DIR=$(dirname $(python -c 'import numeter_webapp;print numeter_webapp.__file__'))
# Nginx
cp web-app/extras/numeter-nginx.example /etc/nginx/sites-available/numeter-webapp
ln -s /etc/nginx/sites-available/numeter-webapp /etc/nginx/sites-enabled/
sed -i "s#@APP_DIR@#$NUMETER_DIR#g" /etc/nginx/sites-available/numeter-webapp
/etc/init.d/nginx restart
# uwsgi
cp web-app/extras/numeter_webapp.ini.example /etc/uwsgi/apps-available/numeter_webapp.ini
ln -s /etc/uwsgi/apps-available/numeter_webapp.ini /etc/uwsgi/apps-enabled/
sed -i "s#@APP_DIR@#$NUMETER_DIR#g" /etc/uwsgi/apps-available/numeter_webapp.ini
/etc/init.d/uwsgi restart
Note
You can customize it for match with your security requirements.
With debian example config are located in /usr/share/doc/numeter-storage/
Use memcached backend¶
Note
Cache is not mandatory
Install Memcached
apt-get install memcached python-memcache
Set ‘use_cache’ to True in numeter_webapp.cfg:
sed -i 's/use_cache.*=.*/use_cache = True/' /etc/numeter/numeter_webapp.cfg
Note
By default Webapp will connect to Memcached with a Unix socket at /var/run/memcached.sock`
.
First launch¶
numeter-webapp syncdb
numeter-webapp storage add --name=local_storage --port=8080 --url_prefix=/numeter-storage --address=127.0.0.1
Note
syncdb
will ask you to create a first superuser. If you choose ‘no’, it will be possible to make it with numeter-webapp user add -S
.
Launch your Web frontend or simply numeter-webapp runserver 0.0.0.0:80
. You must add hosts in database for use it, go to ‘Configuration/Storage/YourStorage/’ and click on button Create hosts.