openstack-ansible-ops/elk_metrics_6x/createElasticIndexes.yml
Kevin Carter 814622cc6c
Improve logstash and elasticsearch performance
The logstash and elasticsearch performance can be improved by using
async index options, pulling back the refresh interval, and by not
fingerprinting every document.

* Async translog allows elasticsearch to using run fsync in the
  background instead of blocking
* the refresh interval will now be 5x the number of replicas with a cap
  of 30. This integer is representitive of the seconds between index
  refresh calls which greatly lowers the load generated across the
  cluster.
* All documents were fingerprinted before writting to the cluster. This
  was a costly operation as elasticsearch will do a forward lookup on all
  documents with a preset ID resulting in 100's, if not 1000's, of extra
  reads. The purpose of the fingerprint function is to limit repeading
  writes so to keep some of this functionality the fingerprint function is
  now only added to documents with messages.
* G1 garbage collection is now enabled by default when the heap size is
  > 6GiB. Early versions of elasticsearch did not recommend this setting
  however its since stabalized in recent releases.
* JVM options have been moved into the elasticsearch and logstash roles
  allowing these tasks to trigger service restarts when changes are made.

Change-Id: I805129b207ad4db182ae6e59b6ec78eb3e246b54
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
2018-09-21 21:47:07 -05:00

128 lines
4.1 KiB
YAML

---
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- name: Create/Setup known indexes in Elasticsearch
hosts: "elastic-logstash[0]"
become: true
vars:
elastic_refresh_interval: "{{ (elasticsearch_number_of_replicas | int) * 5 }}"
vars_files:
- vars/variables.yml
environment: "{{ deployment_environment_variables | default({}) }}"
roles:
- role: elastic_retention
post_tasks:
- name: Create basic indexes
uri:
url: http://127.0.0.1:9200/{{ item.name }}
method: PUT
body: "{{ item.index_options | to_json }}"
status_code: 200,400
body_format: json
register: elk_indexes
until: elk_indexes is success
retries: 3
delay: 10
with_items:
- name: "osprofiler-notifications"
index_options:
settings:
index:
codec: "best_compression"
mapping:
total_fields:
limit: "10000"
refresh_interval: "5s"
- name: "_all/_settings?preserve_existing=true"
index_options:
index.queries.cache.enabled: "true"
indices.queries.cache.size: "5%"
- name: "_all/_settings"
index_options:
index.number_of_replicas: "{{ elasticsearch_number_of_replicas | int }}"
index.translog.durability: "async"
index.refresh_interval: "{{ ((elastic_refresh_interval | int) > 30) | ternary(30, elastic_refresh_interval) }}s"
- name: Check for basic index template
uri:
url: http://127.0.0.1:9200/_template/basic-index-template
method: HEAD
failed_when: false
register: check_basicIndexTemplate
register: check_basicIndexTemplate
until: check_basicIndexTemplate is success
retries: 3
delay: 10
- name: Check for basic index template
uri:
url: http://127.0.0.1:9200/_template/basic-index-template
method: DELETE
status_code: 200
register: delete_basicIndexTemplate
until: delete_basicIndexTemplate is success
retries: 3
delay: 10
when:
- check_basicIndexTemplate.status == 200
- name: Create basic index template
uri:
url: http://127.0.0.1:9200/_template/basic-index-template
method: PUT
body: "{{ index_option | to_json }}"
status_code: 200
body_format: json
register: create_basicIndexTemplate
until: create_basicIndexTemplate is success
retries: 3
delay: 10
vars:
index_option:
index_patterns: >-
{{
(elastic_beat_retention_policy_hosts.keys() | list)
| map('regex_replace', '(.*)', '\1-' ~ '*')
| list
}}
settings:
number_of_replicas: "{{ elasticsearch_number_of_replicas | int }}"
index:
mapping:
total_fields:
limit: "3072"
- name: Create custom monitoring index template
uri:
url: http://127.0.0.1:9200/_template/custom_monitoring
method: PUT
body: "{{ index_option | to_json }}"
status_code: 200
body_format: json
register: create_basicIndexTemplate
until: create_basicIndexTemplate is success
retries: 3
delay: 10
vars:
index_option:
template: ".monitoring-*"
order: 1
settings:
number_of_replicas: "{{ elasticsearch_number_of_replicas | int }}"
number_of_shards: "{{ ((elasticsearch_number_of_replicas | int) * 2) + 1 }}"