Package: elasticmetrics
Collect performance metrics from ElasticSearch.elasticmetricsis a Python library, designed to be used in different contexts and easy
to integrate with other tools. Each step of data collection, transformation and
reporting is defined in a separate reusable module:collectors: abstract logic of collecting data.metrics: abstract selecting and/or aggregating measurments (metrics)formatters: transform metrics into other formats.tool: combine the functionality of other modules to form a CLI applicationCollectorscollectors.ElasticSearchCollectorcollects cluster and node stats by calling ElasticSearch APIs.fromelasticmetrics.collectorsimportElasticSearchCollectorcollector=ElasticSearchCollector('es.example.org')collector.cluster_health()# call _cluster/health, get ES cluster high level statscollector.cluster_stats()# call _cluster/stats, get ES cluster detailed statscollector.node_stats()# call _node/_local/stats, get ES node detailed stats# collector supports detailed configurations like# SSL, basic HTTP auth with UTF-8 credentials, and control over SSL contextinsecure_ssl_collector=ElasticSearchCollector('localhost',port=9200,scheme='https',user=u't€stuser',password=u't€stpássword',ssl_context={'no_cert_verify':True})The returned values are exactly what’s returned from the Elasitc APIs.Composing FeaturesFeatures from different modules can be composed together to achieve expected behavior.fromelasticmetrics.collectorsimportElasticSearchCollectorfromelasticmetrics.metricsimportnode_performance_metricsfromelasticmetrics.formattersimportflatten_metricscollector=ElasticSearchCollector('es.example.org',scheme='https',user='testuser',password='testpassword')metrics_as_dotted_paths=flatten_metrics(node_performance_metrics(collector.node_stats()),prefix='example_es_server')# metrics_as_dotted_paths can be pushed to a time series backend, like GraphiteInstallation$pipinstallelasticmetricsThe only dependencies are Python 2.7+/3.4+ and setuptools.However on development (and test) environmentpytest,mockandpycodestyleare required.# on dev/test env$pipinstall-rrequirements/dev.txtCLI Toolelasticmetrics.toolis a CLI program that exposes some of the functionlaty of the library. It’ll execute when imported:$python-melasticmetrics.tool--helpElastic credentials can be passed as arguments, or set as environment variables.
The example below will connect to ElasticSearch listening on the default port on localhost
over HTTPS, and only collect node stats, and reads access credentials from environment variables.$exportELASTICSEARCH_USER="someuser"$exportELASTICSEARCH_PASSWORD="somepassword"$python-melasticmetrics.tool--ssl--quiet--collectnode_statsDevelopmentCode is onGitHubTestsToxis most convenient to run tests with, since it handles creation of virtualenvs$toxOr when development dependencies are installed (preferably with a virtual environment),
tests can be run by directly callingpytest.$pytestLicenseelasticmetrics is released under the terms of the MIT license.The MIT License (MIT)Copyright (c) 2019 Byte B.V.Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.