An Elasticsearch tail
Project description
Follow Elasticsearch continuously
Overview
elasticsearch_follow is library helping to query Elasticsearch continuously.
It needs https://github.com/elastic/elasticsearch-py as a dependency.
elasticsearch_follow acts as a wrapper for elasticsearch-py and handles various use-cases, like following logs by polling elasticsearch continuously and fetching loglines via a generator. It is possible to easily fetch lines surrounding a given logline.
How to poll Elasticsearch continuously
The polling logic is implemented in the class ElasticsearchFollow, which needs an Elasircsearch object from elasticsearch-py. The class Follower takes an ElasticsearchFollow-object and has a method to create a generator which yields loglines until all elements of a query have been returned. After this a new generator has to be created and used.
How to fetch log-lines from Elasticsearch
To just fetch loglines, one can use ElasticsearchFetch which has a search_surrounding. This returns a list of lists, where each list contains the queried loglines and the lines before and after as requested by the parameters num_before and num_after.
Installation
You can install the elasticsearch
package with pip:
pip install elasticsearch_follow
See also: https://pypi.org/project/elasticsearch-follow/
Example use
from elasticsearch import Elasticsearch
from elasticsearch_follow import ElasticsearchFollow, Follower
es = Elasticsearch()
es_follow = ElasticsearchFollow(elasticsearch=es)
# The Follower is used to get a generator which yields new
# elements until it runs out. time_delta give the number of
# seconds to look into the past.
follower = Follower(elasticsearch_follow=es_follow, index='some-index', time_delta=60)
while True:
entries = follower.generator()
for entry in entries:
print(entry)
time.sleep(0.1)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for elasticsearch_follow-0.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c59b0d2c4c31e1e2935e7bebe5f65edc8eb0e9cba550391b2162d3d754fcd48 |
|
MD5 | c0b7adc07e86212370a437fb975bef2f |
|
BLAKE2b-256 | b898ea47a014957b3d0d50e2ba2f33de5e134c2b9c5fa7c5bddac4948b7e752c |
Hashes for elasticsearch_follow-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20ba52d5f03b0732b576b03e67da909d95e3f8664771f46b3ab078a0e330237e |
|
MD5 | 367dac598fb6da55e4e77c199975b686 |
|
BLAKE2b-256 | fcc502cbe47c9c7b17ab2864ea40e7d386fcbbbc1b99d4dfe9d7bf17a01a0ded |