Configuration¶
Events creation¶
The creation of events can be done via signals. Invenio-stats provides an easy way to generate those events.
-
invenio_stats.config.
STATS_REGISTER_RECEIVERS
= True¶ Enable the registration of signal receivers.
Default is
True
. The signal receivers are functions which will listen to the signals listed in by theSTATS_EVENTS
config variable. An event will be generated for each signal sent.
-
invenio_stats.config.
STATS_EVENTS
= {'file-download': {'event_builders': ['invenio_stats.contrib.event_builders.file_download_event_builder'], 'signal': 'invenio_files_rest.signals.file_downloaded'}}¶ Enabled Events.
Each key is the name of an event. A queue will be created for each event.
If the dict of an event contains the
signal
key, and the config variableSTATS_REGISTER_RECEIVERS
isTrue
, a signal receiver will be registered. Receiver function which will be connected on a signal and emit events. The key is the name of the emitted event.signal
: Signal to which the receiver will be connected to.event_builders
: list of functions which will create and enhance the event.- Each function will receive the event created by the previous function and can update it. Keep in mind that these functions will run synchronously during the creation of the event, meaning that if the signal is sent during a request they will increase the response time.
Events processing¶
If you create events they will be queued in an AMQP queue. You should ensure that you regularly process them. You do this by configuring a Celery Beat schedule similar to this:
from datetime import timedelta
CELERY_BEAT_SCHEDULE = {
'indexer': {
'task': 'invenio_stats.tasks.process_events',
'schedule': timedelta(hours=3),
},
}
This example uses the Celery beat process to trigger an event processing task every 3 hours.
Invenio-stats provides two tasks:
- invenio_stats.tasks.process_events
- invenio_stats.tasks.aggregate_events
Queues configuration¶
Invenio-stats creates AMQP queues in order to buffer events. Those queues need to be configured. Change these parameters only if you know what you are doing.
invenio_stats.config.STATS_MQ_EXCHANGE: Default exchange used for the message queues.