%global _empty_manifest_terminate_build 0 Name: python-django-elasticsearch-metrics Version: 5.0.0 Release: 1 Summary: Django app for storing time-series metrics in Elasticsearch. License: MIT URL: http://github.com/CenterForOpenScience/django-elasticsearch-metrics Source0: https://mirrors.nju.edu.cn/pypi/web/packages/8f/82/e3af99016c697fdea2925a9c81513b7ff320117915f1017cd341ac87e4b0/django-elasticsearch-metrics-5.0.0.tar.gz BuildArch: noarch Requires: python3-elasticsearch-dsl Requires: python3-pytest Requires: python3-mock Requires: python3-pytest-django Requires: python3-factory-boy Requires: python3-flake8 Requires: python3-pre-commit Requires: python3-konch Requires: python3-tox Requires: python3-flake8-bugbear Requires: python3-flake8 Requires: python3-pre-commit Requires: python3-flake8-bugbear Requires: python3-pytest Requires: python3-mock Requires: python3-pytest-django Requires: python3-factory-boy %description # django-elasticsearch-metrics [![pypi](https://badge.fury.io/py/django-elasticsearch-metrics.svg)](https://badge.fury.io/py/django-elasticsearch-metrics) [![Build Status](https://travis-ci.org/CenterForOpenScience/django-elasticsearch-metrics.svg?branch=master)](https://travis-ci.org/CenterForOpenScience/django-elasticsearch-metrics) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black) Django app for storing time-series metrics in Elasticsearch. ## Pre-requisites * Python 2.7 or >=3.6 * Django 1.11 or 2.0 * Elasticsearch 6 ## Install ``` pip install django-elasticsearch-metrics ``` ## Quickstart Add `"elasticseach_metrics"` to `INSTALLED_APPS`. ```python INSTALLED_APPS += ["elasticsearch_metrics"] ``` Define the `ELASTICSEARCH_DSL` setting. ```python ELASTICSEARCH_DSL = {"default": {"hosts": "localhost:9200"}} ``` This setting is passed to [`elasticsearch_dsl.connections.configure`](http://elasticsearch-dsl.readthedocs.io/en/stable/configuration.html#multiple-clusters) so it takes the same parameters. In one of your apps, define a new metric in `metrics.py`. A `Metric` is a subclass of [`elasticsearch_dsl.Document`](https://elasticsearch-dsl.readthedocs.io/en/stable/api.html#document). ```python # myapp/metrics.py from elasticsearch_metrics import metrics class PageView(metrics.Metric): user_id = metrics.Integer(index=True, doc_values=True) ``` Use the `sync_metrics` management command to ensure that the [index template](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html) for your metric is created in Elasticsearch. ```shell # This will create an index template called myapp_pageview python manage.py sync_metrics ``` Now add some data: ```python from myapp.metrics import PageView user = User.objects.latest() # By default we create an index for each day. # Therefore, this will persist the document # to an index called, e.g. "myapp_pageview_2020.02.04" PageView.record(user_id=user.id) ``` Go forth and search! ```python # perform a search across all page views PageView.search() ``` ## Per-month or per-year indices By default, an index is created for every day that a metric is saved. You can change this to create an index per month or per year by changing the `ELASTICSEARCH_METRICS_DATE_FORMAT` setting. ```python # settings.py # Monthly: ELASTICSEARCH_METRICS_DATE_FORMAT = "%Y.%m" # Yearly: ELASTICSEARCH_METRICS_DATE_FORMAT = "%Y" ``` ## Index settings You can configure the index template settings by setting `Metric.Index.settings`. ```python class PageView(metrics.Metric): user_id = metrics.Integer() class Index: settings = {"number_of_shards": 2, "refresh_interval": "5s"} ``` ## Index templates Each `Metric` will have its own [index template](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html). The index template name and glob pattern are computed from the app label for the containing app and the class's name. For example, a `PageView` class defined in `myapp/metrics.py` will have an index template with the name `myapp_pageview` and a template glob pattern of `myapp_pageview_*`. If you declare a `Metric` outside of an app, you will need to set `app_label`. ```python class PageView(metrics.Metric): class Meta: app_label = "myapp" ``` Alternatively, you can set `template_name` and/or `template` explicitly. ```python class PageView(metrics.Metric): user_id = metrics.Integer() class Meta: template_name = "myapp_pviews" template = "myapp_pviews_*" ``` ## Abstract metrics ```python from elasticsearch_metrics import metrics class MyBaseMetric(metrics.Metric): user_id = metrics.Integer() class Meta: abstract = True class PageView(MyBaseMetric): class Meta: app_label = "myapp" ``` ## Optional factory_boy integration ```python import factory from elasticsearch_metrics.factory import MetricFactory from ..myapp.metrics import MyMetric class MyMetricFactory(MetricFactory): my_int = factory.Faker("pyint") class Meta: model = MyMetric def test_something(): metric = MyMetricFactory() # index metric in ES assert isinstance(metric.my_int, int) ``` ## Configuration * `ELASTICSEARCH_DSL`: Required. Connection settings passed to [`elasticsearch_dsl.connections.configure`](http://elasticsearch-dsl.readthedocs.io/en/stable/configuration.html#multiple-clusters). * `ELASTICSEARCH_METRICS_DATE_FORMAT`: Date format to use when creating indexes. Default: `%Y.%m.%d` (same date format Elasticsearch uses for [date math](https://www.elastic.co/guide/en/elasticsearch/reference/current/date-math-index-names.html)) ## Management commands * `sync_metrics`: Ensure that index templates have been created for your metrics. * `show_metrics`: Pretty-print a listing of all registered metrics. * `check_metrics`: Check if index templates are in sync. Exits with an error code if any metrics are out of sync. ## Signals Signals are located in the `elasticsearch_metrics.signals` module. * `pre_index_template_create(Metric, index_template, using)`: Sent before `PUT`ting a new index template into Elasticsearch. * `post_index_template_create(Metric, index_template, using)`: Sent after `PUT`ting a new index template into Elasticsearch. * `pre_save(Metric, instance, using, index)`: Sent at the beginning of a Metric's `save()` method. * `post_save(Metric, instance, using, index)`: Sent at the end of a Metric's `save()` method. ## Caveats * `_source` is disabled by default on metric indices in order to save disk space. For most metrics use cases, Users will not need to retrieve the source JSON documents. Be sure to understand the consequences of this: https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-source-field.html#_disabling_source . To enable `_source`, you can override it in `class Meta`. ```python class MyMetric(metrics.Metric): class Meta: source = metrics.MetaField(enabled=True) ``` ## Resources * [Elasticsearch as a Time Series Data Store](https://www.elastic.co/blog/elasticsearch-as-a-time-series-data-store) * [Pythonic Analytics with Elasticsearch](https://www.elastic.co/blog/pythonic-analytics-with-elasticsearch) * [In Search of Agile Time Series Database](https://taowen.gitbooks.io/tsdb/content/index.html) ## License MIT Licensed. %package -n python3-django-elasticsearch-metrics Summary: Django app for storing time-series metrics in Elasticsearch. Provides: python-django-elasticsearch-metrics BuildRequires: python3-devel BuildRequires: python3-setuptools BuildRequires: python3-pip %description -n python3-django-elasticsearch-metrics # django-elasticsearch-metrics [![pypi](https://badge.fury.io/py/django-elasticsearch-metrics.svg)](https://badge.fury.io/py/django-elasticsearch-metrics) [![Build Status](https://travis-ci.org/CenterForOpenScience/django-elasticsearch-metrics.svg?branch=master)](https://travis-ci.org/CenterForOpenScience/django-elasticsearch-metrics) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black) Django app for storing time-series metrics in Elasticsearch. ## Pre-requisites * Python 2.7 or >=3.6 * Django 1.11 or 2.0 * Elasticsearch 6 ## Install ``` pip install django-elasticsearch-metrics ``` ## Quickstart Add `"elasticseach_metrics"` to `INSTALLED_APPS`. ```python INSTALLED_APPS += ["elasticsearch_metrics"] ``` Define the `ELASTICSEARCH_DSL` setting. ```python ELASTICSEARCH_DSL = {"default": {"hosts": "localhost:9200"}} ``` This setting is passed to [`elasticsearch_dsl.connections.configure`](http://elasticsearch-dsl.readthedocs.io/en/stable/configuration.html#multiple-clusters) so it takes the same parameters. In one of your apps, define a new metric in `metrics.py`. A `Metric` is a subclass of [`elasticsearch_dsl.Document`](https://elasticsearch-dsl.readthedocs.io/en/stable/api.html#document). ```python # myapp/metrics.py from elasticsearch_metrics import metrics class PageView(metrics.Metric): user_id = metrics.Integer(index=True, doc_values=True) ``` Use the `sync_metrics` management command to ensure that the [index template](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html) for your metric is created in Elasticsearch. ```shell # This will create an index template called myapp_pageview python manage.py sync_metrics ``` Now add some data: ```python from myapp.metrics import PageView user = User.objects.latest() # By default we create an index for each day. # Therefore, this will persist the document # to an index called, e.g. "myapp_pageview_2020.02.04" PageView.record(user_id=user.id) ``` Go forth and search! ```python # perform a search across all page views PageView.search() ``` ## Per-month or per-year indices By default, an index is created for every day that a metric is saved. You can change this to create an index per month or per year by changing the `ELASTICSEARCH_METRICS_DATE_FORMAT` setting. ```python # settings.py # Monthly: ELASTICSEARCH_METRICS_DATE_FORMAT = "%Y.%m" # Yearly: ELASTICSEARCH_METRICS_DATE_FORMAT = "%Y" ``` ## Index settings You can configure the index template settings by setting `Metric.Index.settings`. ```python class PageView(metrics.Metric): user_id = metrics.Integer() class Index: settings = {"number_of_shards": 2, "refresh_interval": "5s"} ``` ## Index templates Each `Metric` will have its own [index template](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html). The index template name and glob pattern are computed from the app label for the containing app and the class's name. For example, a `PageView` class defined in `myapp/metrics.py` will have an index template with the name `myapp_pageview` and a template glob pattern of `myapp_pageview_*`. If you declare a `Metric` outside of an app, you will need to set `app_label`. ```python class PageView(metrics.Metric): class Meta: app_label = "myapp" ``` Alternatively, you can set `template_name` and/or `template` explicitly. ```python class PageView(metrics.Metric): user_id = metrics.Integer() class Meta: template_name = "myapp_pviews" template = "myapp_pviews_*" ``` ## Abstract metrics ```python from elasticsearch_metrics import metrics class MyBaseMetric(metrics.Metric): user_id = metrics.Integer() class Meta: abstract = True class PageView(MyBaseMetric): class Meta: app_label = "myapp" ``` ## Optional factory_boy integration ```python import factory from elasticsearch_metrics.factory import MetricFactory from ..myapp.metrics import MyMetric class MyMetricFactory(MetricFactory): my_int = factory.Faker("pyint") class Meta: model = MyMetric def test_something(): metric = MyMetricFactory() # index metric in ES assert isinstance(metric.my_int, int) ``` ## Configuration * `ELASTICSEARCH_DSL`: Required. Connection settings passed to [`elasticsearch_dsl.connections.configure`](http://elasticsearch-dsl.readthedocs.io/en/stable/configuration.html#multiple-clusters). * `ELASTICSEARCH_METRICS_DATE_FORMAT`: Date format to use when creating indexes. Default: `%Y.%m.%d` (same date format Elasticsearch uses for [date math](https://www.elastic.co/guide/en/elasticsearch/reference/current/date-math-index-names.html)) ## Management commands * `sync_metrics`: Ensure that index templates have been created for your metrics. * `show_metrics`: Pretty-print a listing of all registered metrics. * `check_metrics`: Check if index templates are in sync. Exits with an error code if any metrics are out of sync. ## Signals Signals are located in the `elasticsearch_metrics.signals` module. * `pre_index_template_create(Metric, index_template, using)`: Sent before `PUT`ting a new index template into Elasticsearch. * `post_index_template_create(Metric, index_template, using)`: Sent after `PUT`ting a new index template into Elasticsearch. * `pre_save(Metric, instance, using, index)`: Sent at the beginning of a Metric's `save()` method. * `post_save(Metric, instance, using, index)`: Sent at the end of a Metric's `save()` method. ## Caveats * `_source` is disabled by default on metric indices in order to save disk space. For most metrics use cases, Users will not need to retrieve the source JSON documents. Be sure to understand the consequences of this: https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-source-field.html#_disabling_source . To enable `_source`, you can override it in `class Meta`. ```python class MyMetric(metrics.Metric): class Meta: source = metrics.MetaField(enabled=True) ``` ## Resources * [Elasticsearch as a Time Series Data Store](https://www.elastic.co/blog/elasticsearch-as-a-time-series-data-store) * [Pythonic Analytics with Elasticsearch](https://www.elastic.co/blog/pythonic-analytics-with-elasticsearch) * [In Search of Agile Time Series Database](https://taowen.gitbooks.io/tsdb/content/index.html) ## License MIT Licensed. %package help Summary: Development documents and examples for django-elasticsearch-metrics Provides: python3-django-elasticsearch-metrics-doc %description help # django-elasticsearch-metrics [![pypi](https://badge.fury.io/py/django-elasticsearch-metrics.svg)](https://badge.fury.io/py/django-elasticsearch-metrics) [![Build Status](https://travis-ci.org/CenterForOpenScience/django-elasticsearch-metrics.svg?branch=master)](https://travis-ci.org/CenterForOpenScience/django-elasticsearch-metrics) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black) Django app for storing time-series metrics in Elasticsearch. ## Pre-requisites * Python 2.7 or >=3.6 * Django 1.11 or 2.0 * Elasticsearch 6 ## Install ``` pip install django-elasticsearch-metrics ``` ## Quickstart Add `"elasticseach_metrics"` to `INSTALLED_APPS`. ```python INSTALLED_APPS += ["elasticsearch_metrics"] ``` Define the `ELASTICSEARCH_DSL` setting. ```python ELASTICSEARCH_DSL = {"default": {"hosts": "localhost:9200"}} ``` This setting is passed to [`elasticsearch_dsl.connections.configure`](http://elasticsearch-dsl.readthedocs.io/en/stable/configuration.html#multiple-clusters) so it takes the same parameters. In one of your apps, define a new metric in `metrics.py`. A `Metric` is a subclass of [`elasticsearch_dsl.Document`](https://elasticsearch-dsl.readthedocs.io/en/stable/api.html#document). ```python # myapp/metrics.py from elasticsearch_metrics import metrics class PageView(metrics.Metric): user_id = metrics.Integer(index=True, doc_values=True) ``` Use the `sync_metrics` management command to ensure that the [index template](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html) for your metric is created in Elasticsearch. ```shell # This will create an index template called myapp_pageview python manage.py sync_metrics ``` Now add some data: ```python from myapp.metrics import PageView user = User.objects.latest() # By default we create an index for each day. # Therefore, this will persist the document # to an index called, e.g. "myapp_pageview_2020.02.04" PageView.record(user_id=user.id) ``` Go forth and search! ```python # perform a search across all page views PageView.search() ``` ## Per-month or per-year indices By default, an index is created for every day that a metric is saved. You can change this to create an index per month or per year by changing the `ELASTICSEARCH_METRICS_DATE_FORMAT` setting. ```python # settings.py # Monthly: ELASTICSEARCH_METRICS_DATE_FORMAT = "%Y.%m" # Yearly: ELASTICSEARCH_METRICS_DATE_FORMAT = "%Y" ``` ## Index settings You can configure the index template settings by setting `Metric.Index.settings`. ```python class PageView(metrics.Metric): user_id = metrics.Integer() class Index: settings = {"number_of_shards": 2, "refresh_interval": "5s"} ``` ## Index templates Each `Metric` will have its own [index template](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html). The index template name and glob pattern are computed from the app label for the containing app and the class's name. For example, a `PageView` class defined in `myapp/metrics.py` will have an index template with the name `myapp_pageview` and a template glob pattern of `myapp_pageview_*`. If you declare a `Metric` outside of an app, you will need to set `app_label`. ```python class PageView(metrics.Metric): class Meta: app_label = "myapp" ``` Alternatively, you can set `template_name` and/or `template` explicitly. ```python class PageView(metrics.Metric): user_id = metrics.Integer() class Meta: template_name = "myapp_pviews" template = "myapp_pviews_*" ``` ## Abstract metrics ```python from elasticsearch_metrics import metrics class MyBaseMetric(metrics.Metric): user_id = metrics.Integer() class Meta: abstract = True class PageView(MyBaseMetric): class Meta: app_label = "myapp" ``` ## Optional factory_boy integration ```python import factory from elasticsearch_metrics.factory import MetricFactory from ..myapp.metrics import MyMetric class MyMetricFactory(MetricFactory): my_int = factory.Faker("pyint") class Meta: model = MyMetric def test_something(): metric = MyMetricFactory() # index metric in ES assert isinstance(metric.my_int, int) ``` ## Configuration * `ELASTICSEARCH_DSL`: Required. Connection settings passed to [`elasticsearch_dsl.connections.configure`](http://elasticsearch-dsl.readthedocs.io/en/stable/configuration.html#multiple-clusters). * `ELASTICSEARCH_METRICS_DATE_FORMAT`: Date format to use when creating indexes. Default: `%Y.%m.%d` (same date format Elasticsearch uses for [date math](https://www.elastic.co/guide/en/elasticsearch/reference/current/date-math-index-names.html)) ## Management commands * `sync_metrics`: Ensure that index templates have been created for your metrics. * `show_metrics`: Pretty-print a listing of all registered metrics. * `check_metrics`: Check if index templates are in sync. Exits with an error code if any metrics are out of sync. ## Signals Signals are located in the `elasticsearch_metrics.signals` module. * `pre_index_template_create(Metric, index_template, using)`: Sent before `PUT`ting a new index template into Elasticsearch. * `post_index_template_create(Metric, index_template, using)`: Sent after `PUT`ting a new index template into Elasticsearch. * `pre_save(Metric, instance, using, index)`: Sent at the beginning of a Metric's `save()` method. * `post_save(Metric, instance, using, index)`: Sent at the end of a Metric's `save()` method. ## Caveats * `_source` is disabled by default on metric indices in order to save disk space. For most metrics use cases, Users will not need to retrieve the source JSON documents. Be sure to understand the consequences of this: https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-source-field.html#_disabling_source . To enable `_source`, you can override it in `class Meta`. ```python class MyMetric(metrics.Metric): class Meta: source = metrics.MetaField(enabled=True) ``` ## Resources * [Elasticsearch as a Time Series Data Store](https://www.elastic.co/blog/elasticsearch-as-a-time-series-data-store) * [Pythonic Analytics with Elasticsearch](https://www.elastic.co/blog/pythonic-analytics-with-elasticsearch) * [In Search of Agile Time Series Database](https://taowen.gitbooks.io/tsdb/content/index.html) ## License MIT Licensed. %prep %autosetup -n django-elasticsearch-metrics-5.0.0 %build %py3_build %install %py3_install install -d -m755 %{buildroot}/%{_pkgdocdir} if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi pushd %{buildroot} if [ -d usr/lib ]; then find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst fi if [ -d usr/lib64 ]; then find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst fi if [ -d usr/bin ]; then find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst fi if [ -d usr/sbin ]; then find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst fi touch doclist.lst if [ -d usr/share/man ]; then find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst fi popd mv %{buildroot}/filelist.lst . mv %{buildroot}/doclist.lst . %files -n python3-django-elasticsearch-metrics -f filelist.lst %dir %{python3_sitelib}/* %files help -f doclist.lst %{_docdir}/* %changelog * Mon May 29 2023 Python_Bot - 5.0.0-1 - Package Spec generated