geosolutions-it / geonode-generic

Generic Geonode-project based app, to be used with docker/rancher
https://waffle.io/geosolutions-it/geonode-generic
3 stars 6 forks source link

GeoNode's monitor must be enabled by default #4

Closed giohappy closed 6 years ago

giohappy commented 6 years ago

GeoNode monitoring must be enabled by default. It's a key element for the typical user, who wants to have reports on numners of users, data downloads, etc.

Enable and configure Monitoring
===============================

--> DJANGO_SETTINGS_MODULE=ihp.settings python manage.py collect_metrics -n -t xml -f
--> psql -c 'set timezone=UTC;'

1. settings
-------------------------------

CORS_ORIGIN_ALLOW_ALL = True

MONITORING_ENABLED = True
# add following lines to your local settings to enable monitoring
if MONITORING_ENABLED:
    INSTALLED_APPS += ('geonode.contrib.monitoring',)
    MIDDLEWARE_CLASSES += ('geonode.contrib.monitoring.middleware.MonitoringMiddleware',)
    MONITORING_CONFIG = None
    MONITORING_HOST_NAME = 'localhost'
    MONITORING_SERVICE_NAME = 'local-geonode'
    MONITORING_HOST_NAME = SITE_HOST_NAME

INSTALLED_APPS += ('geonode.contrib.ows_api',)

GEOIP_PATH = os.path.join(os.path.dirname(__file__), '..', 'GeoLiteCity.dat')

2. migrations
-------------------------------

DJANGO_SETTINGS_MODULE=<project_name>.settings python manage.py migrate monitoring
DJANGO_SETTINGS_MODULE=<project_name>.settings python manage.py updategeoip
DJANGO_SETTINGS_MODULE=<project_name>.settings python manage.py collect_metrics -n -t xml -f

3. configuration
-------------------------------

.. also update "Sites" from admin
.. also do not forget to enable notifications and configure them from user profile

please follow : http://docs.geonode.org/en/master/tutorials/admin/monitoring/#configuration

IMPORTANT:
 - Services Dates / Times are mandatory
 - Times must be in UTC

4. cront job
-------------------------------

sudo crontab -e

--> * * * * * supervisorctl  start geonode-monitoring

5. supervisor
-------------------------------

sudo apt install supervisor
sudo service supervisor restart
sudo update-rc.d supervisor enable

sudo vim /etc/supervisor/conf.d/geonode-monitoring.conf

[program:geonode-monitoring]
command=/home/igad/Envs/geonode/bin/python -W ignore /home/igad/igad_geonode/geonode/manage.py collect_metrics -n -t xml
directory = /home/igad/igad_geonode
environment=DJANGO_SETTINGS_MODULE="igad_geonode.settings"
user=igad
numproc=1
stdout_logfile=/home/igad/logs/geonode-celery.log
stderr_logfile=/home/igad/logs/geonode-celery.log
autostart = true
autorestart = true
startsecs = 10
stopwaitsecs = 600
priority = 998

sudo service supervisor restart
sudo supervisorctl start geonode-monitoring
sudo supervisorctl status geonode-monitoring

sudo vim /etc/hosts

127.0.0.1       localhost
51.255.134.48   igad-dev.geo-solutions.it igad-geonode-dev

# The following lines are desirable for IPv6 capable hosts

see #11 for scheduling implementation

cezio commented 6 years ago

As an app, it can be enabled by default, but there's also monitoring configuration part, which should be processed in ui by user.

Alternatively, there's autoconfigure code which should populate configuration based on settings (it's not very well tested though, just basic case), which should populate hosts and services. I can add MONITORING_AUTOCONFIGURE flag to settings, which will enable autoconf on deployment (when no host/service is defined), or just hardcode autoconfigure in geonode-generic.

giohappy commented 6 years ago

I would be in favour of autonfiguring it.

cezio commented 6 years ago

Monitoring requires collector script to be run each minute. This can be done by cron task, or we can add it to uwsgi scheduler: http://uwsgi-docs.readthedocs.io/en/latest/Cron.html

giohappy commented 6 years ago

I would use a dedicated container for scheduled tasks (cron). It could be used both for monitoring and for scheduled backups. Don't you think?

cezio commented 6 years ago

ok. for further reference:

https://forums.rancher.com/t/scheduling-recurring-cron-like-tasks-using-containers/555/4 https://github.com/rancher/container-crontab https://play.pixelblaster.ro/blog/2017/08/15/my-recipe-for-cronjobs-with-docker/

giohappy commented 6 years ago

monitoring models setup defined in https://github.com/geosolutions-it/geonode-generic/commit/a95e94082c9e7

cezio commented 6 years ago

There was a misconfiguration causing no data were collected, i've added proper host name generation in settings for this.