Showing posts with label elasticsearch-curator. Show all posts
Showing posts with label elasticsearch-curator. Show all posts

Tuesday, 12 May 2015

Elasticsearch curator - delete commands

If you wish to delete some old elasticsearch indices, curator is the de-facto standard. The program provides so many useful options and I appreciate the versatility. Although, curator has a wiki and elasticsearch page, things were not that clear to me in one go. So, here are my notes on deleting elasticsearch indices:

[admin@mgr ~]$ curator --version
curator, version 3.0.0

[admin@mgr ~]$ /usr/bin/curator --host 10.4.0.46 delete --help
Usage: curator delete [OPTIONS] COMMAND [ARGS]...

  Delete indices or snapshots

Options:
  --disk-space FLOAT  Delete indices beyond DISK_SPACE gigabytes.
  --reverse BOOLEAN   Only valid with --disk-space. Affects sort order of the
                      indices.  True means reverse-alphabetical (if dates are
                      involved, older is deleted first).  [default: True]
  --help              Show this message and exit.

Commands:
  indices    Index selection.
  snapshots  Snapshot selection.


[admin@mgr ~]$ /usr/bin/curator --host 10.4.0.46 delete indices --help
Usage: curator delete indices [OPTIONS]

  Get a list of indices to act on from the provided arguments, then perform
  the command [alias, allocation, bloom, close, delete, etc.] on the
  resulting list.

Options:
  --newer-than INTEGER            Include only indices newer than n time_units
  --older-than INTEGER            Include only indices older than n time_units
  --prefix TEXT                   Include only indices beginning with prefix.
  --suffix TEXT                   Include only indices ending with suffix.
  --time-unit [hours|days|weeks|months]
                                  Unit of time to reckon by
  --timestring TEXT               Python strftime string to match your index
                                  definition, e.g. 2014.07.15 would be
                                  %Y.%m.%d
  --regex TEXT                    Provide your own regex, e.g
                                  '^prefix-.*-suffix$'
  --exclude TEXT                  Exclude matching indices. Can be invoked
                                  multiple times.
  --index TEXT                    Include the provided index in the list. Can
                                  be invoked multiple times.
  --all-indices                   Do not filter indices.  Act on all indices.
  --help                          Show this message and exit.

If you wish to use dry-run feature in curator:

[admin@mgr ~]$ /usr/bin/curator --host 10.4.0.46 --dry-run --debug delete indices --time-unit days --timestring "\%Y.\%m.\%d" --older-than 7 --prefix logstash- --all-indices

You should always specify logfile and loglevel (CRITICAL = 50, ERROR=40, WARNING=30, INFO=20, DEBUG=10, NOTSET=0) to capture curator program output for ease of debugging and specify sufficient timeout period. The timeout period becomes important when you are taking snapshots of indices. So, always  give sufficient timeout period:

[admin@mgr ~]$ /usr/bin/curator --host 10.4.0.47 --timeout 300 --logfile curator_log.txt --loglevel 10 --debug delete indices --time-unit days --timestring "\%Y.\%m.\%d" --older-than 7 --prefix logstash- --all-indices


[admin@mgr ~]$ /usr/bin/curator --host 10.4.0.46 --timeout 300 --logfile curator_log.txt --loglevel 10 --debug delete indices --time-unit days --timestring "\%Y.\%m.\%d" --older-than 7 --prefix logstash-apache --all-indices

If you wish to delete the indices on the basis of hard disk space,use the following command:

[admin@mgr ~]$ /usr/bin/curator --host 10.4.0.46 --timeout 300 --logfile ttt.txt --loglevel 10 --debug delete --disk-space 40 indices --all-indices




Sunday, 19 April 2015

Issue in Elasticsearch Curator cron job

I learned a lesson that cron treats '%' character as  a special character.

I have written "elasticsearch-curator" cronjob for closing the elasticsearch indexes older than 2 days and the elasticsearch index was not getting closed for some reason. However, I was able to execute the same command in bash shell without any issues.

0 8 * * * /usr/bin/curator --host 10.1.0.46 close indices --time-unit days --timestring "%Y.%m.%d" --older-than 2 > /dev/null 2>&1

The google search pointed me to the link:
http://www.ducea.com/2008/11/12/using-the-character-in-crontab-entries/

and then, I realized that I have to escape % character in my cron job!!

0 8 * * * /usr/bin/curator --host 10.1.0.46 close indices --time-unit days --timestring "\%Y.\%m.\%d" --older-than 2 > /dev/null 2>&1

Similarly, if you wish to delete older indices, you can use:

$ /usr/bin/curator --host 10.44.0.46 delete indices --older-than 10 --time-unit days --timestring '%Y.%m.%d' --prefix netflow- 

Friday, 13 February 2015

ImportError: No module named version

I have installed python beaver package and wanted to install elasticsearch-curator. That's when I encountered this error:

File "/usr/lib64/python2.6/distutils/dist.py", line 975, in run_commands

        self.run_command(cmd)

      File "/usr/lib64/python2.6/distutils/dist.py", line 995, in run_command

        cmd_obj.run()

      File "<string>", line 12, in replacement_run

      File "/usr/lib/python2.6/site-packages/pkg_resources/__init__.py", line 2310, in load

        return self.resolve()

      File "/usr/lib/python2.6/site-packages/pkg_resources/__init__.py", line 2316, in resolve

        module = __import__(self.module_name, fromlist=['__name__'], level=0)

    ImportError: No module named version

It turned out that python-daemon package with the culprit!

To get rid of, do the following:
    # pip uninstall python-daemon
    # pip install python-daemon
  
    If you wish, you may install specific version also, say
    # pip install python-daemon==1.6.1
    # pip install beaver --upgrade
    # pip install elasticsearch-curator


Monday, 8 December 2014

Fix DistributionNotFound error argparse>=1.1.0 in elasticsearch-curator installation

I wanted to install elasticsearch-curator package(ver. 2.0.2) on my CentOS machine to manage my old elasticsearch(ver. 1.2.0) indices. I encountered the following weird error while installing:

$ curator --versionTraceback (most recent call last):  File "/usr/bin/curator", line 5, in <module>    from pkg_resources import load_entry_point  File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 2655, in <module>    working_set.require(__requires__)  File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 648, in require    needed = self.resolve(parse_requirements(requirements))  File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 546, in resolve    raise DistributionNotFound(req)pkg_resources.DistributionNotFound: argparse>=1.1.0

After searching on google, it became apparent that the error is peculiar to CentOS/RHEL variants only!!

Finally, I found a way..... Un-install existing installation and then re-install...

$ sudo pip uninstall argparse
$ sudo pip uninstall elasticsearch
$ sudo pip uninstall elasticsearch-curator
$ sudo pip install argparse
$ sudo pip install elasticsearch
$ sudo pip install elasticsearch-curator

Not a perfect way to solve the issue... But still, the
This thread on github might be useful - https://github.com/elasticsearch/curator/issues/56

I found another reason for this type of error: it happens when the version of setuptools and distribute libraries of python on the system are old. So, update them using pip installer:

$ sudo pip install distribute --upgrade
$ sudo pip install setuptools --upgrade