LoginSignup
0
2

More than 5 years have passed since last update.

elasticsearchのindexを整理するcuratorのactionファイルを整理した話

Posted at

これは何

elasticsearchのindexを削除するときにはcuratorを使うと思うが、そのactionファイルがわかりにくく、大きくなりがちだったのでメモ。
curator はver 4での記法(ver3だとちょっと違うみたいなので注意)

curator action fileの基本の書き方

1から順番に実行される。

actions:
  1:
    action: delete_indices
    description: "delete application log indices"
    options:
      disable_action: False
      ignore_empty_list: True
    filters:
    - filtertype: pattern
      kind: prefix
      value: "application."  # elasticsearchのindex名と"kind","value"設定が対応するようにする
      exclude: False
    - filtertype: age
      source: creation_date
      direction: older
      timestring: '%Y.%m.%d'
      unit: days
      unit_count: "30"   # 30日残す設定
  2:
    action: delete_indices
    description: "delete indices"
    options:
      disable_action: False
      ignore_empty_list: True
    filters:
    - filtertype: pattern
      kind: prefix
      value: "application."
      exclude: True   # ここでexcludeしておかないと30日保存したいのに10日までになってしまう
    - filtertype: kibana
      exclude: True  # kibanaを使っている場合には入れたほうがよい。.kibanaファイルが消えて、kibana indexを毎回登録しないといけなくなる。
    - filtertype: age
      source: creation_date
      direction: older
      timestring: '%Y.%m.%d'
      unit: days
      unit_count: 10

削除日数を細かく制御したい場合(ansible templateで解決)

上の例の1の記述のところみたいなのを並べて、さらに2のexcludeにも突っ込んでいかないといけない。コード量が増えて管理しづらい。
ansibleで配置するなら以下のようにすればvarsのリストに追加するだけで簡単。

  • varsで以下のように設定する
  • CURATOR_DELETE_LIST:
    - { TARGET: "application."          , DAYS: "30" }
    - { TARGET: "httpd.error."          , DAYS: "30" }
    - { TARGET: "httpd.access.hoge." , DAYS: "7" }
    - { TARGET: "httpd.access.hoge."     , DAYS: "7" }
    
  • loopでまわす

actions:
{# 明示的な削除対象のためのブロック-#}
{% for t in CURATOR_DELETE_LIST %}
  {{ loop.index }}: 
    action: delete_indices
    description: "delete {{ t.TARGET }} indices"
    options:
      disable_action: False
      ignore_empty_list: True
    filters:
    - filtertype: pattern
      kind: prefix
      value: "{{ t.TARGET }}"
      exclude: False
    - filtertype: age
      source: creation_date
      direction: older
      timestring: '%Y.%m.%d'
      unit: days
      unit_count: "{{ t.DAYS }}"
{% endfor %}

{# .kibana を除くその他の index は 10 日間保持。最後のactionになるように99としておく。 #}
  99: 
    action: delete_indices
    description: "delete indices"
    options:
      disable_action: False
      ignore_empty_list: True
    filters:
{% for t in CURATOR_DELETE_LIST %}
    - filtertype: pattern
      kind: prefix
      value: "{{ t.TARGET }}"
      exclude: True 
{% endfor %}
    - filtertype: kibana
      exclude: True
    - filtertype: age
      source: creation_date
      direction: older
      timestring: '%Y.%m.%d'
      unit: days
      unit_count: 10

もっとまとめて綺麗にできるかも。でもまあ役割ごとにブロックで分けれたからよし。

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2