elasticshelf 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -1
- data/README.md +33 -7
- data/elasticshelf.gemspec +1 -0
- data/lib/elasticshelf.rb +50 -0
- data/lib/elasticshelf/version.rb +1 -1
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abdcc3dbfb9c017411bb49eada9cef12bfbad2f8
|
4
|
+
data.tar.gz: 9b0b0c3f1351b5eccff17774921fe84cd97349f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5038aa06df2f86dc47092ffead86f9cbedf5729885ce531b2eee1b074ab956f8d9734fb53f5581c578e834dd79ab415619f0a3e1128be1283548998349444d57
|
7
|
+
data.tar.gz: 7849cc89dc49c8bdba15df9f67b0bad84ce910aa2d67b6f9c9b572f8fedbc3f42794eadaeafff4f77e81cad9859f46abcaf7905910c9e8fbf433f35004adf7b9
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -5,26 +5,51 @@ Ruby integrations for Elasticsearch indices management using close, open, delete
|
|
5
5
|
Inspired by Curator at https://github.com/elasticsearch/curator.git, but if
|
6
6
|
you are an ophidiophobe, no worries, this is written in Ruby :-)
|
7
7
|
|
8
|
+
Honestly, there is nothing special here that can not already be done with the elasticsearch-ruby gem,
|
9
|
+
but it's just packaged up as a convenience gem.
|
10
|
+
|
11
|
+
The goal is to perform the following on Elasticsearch indices:
|
12
|
+
* **wither** (aka disable bloom filter)
|
13
|
+
* **close**
|
14
|
+
* **open**
|
15
|
+
* **delete**
|
16
|
+
* **snapshot**
|
17
|
+
* **restore**
|
18
|
+
|
19
|
+
## TODO's:
|
20
|
+
|
21
|
+
Loop thru expired indices hash and perform an action:
|
22
|
+
close, open, delete, wither, snapshot, or restore
|
23
|
+
|
8
24
|
## Installation
|
9
25
|
|
10
26
|
Add this line to your application's Gemfile:
|
11
27
|
|
12
|
-
gem 'elasticshelf'
|
28
|
+
```gem 'elasticshelf'```
|
13
29
|
|
14
30
|
And then execute:
|
15
31
|
|
16
|
-
|
32
|
+
```$ bundle```
|
17
33
|
|
18
34
|
Or install it yourself as:
|
19
35
|
|
20
|
-
|
36
|
+
```$ gem install elasticshelf```
|
21
37
|
|
22
38
|
## Usage
|
23
39
|
|
24
|
-
|
40
|
+
```
|
41
|
+
$ es = Elasticshelf::Client.new(:host => '127.0.0.1:9200')
|
42
|
+
|
43
|
+
$ es.wither_index("index_name") ... only if it's not closed already
|
44
|
+
|
45
|
+
$ es.index_closed?("index_name")
|
46
|
+
|
47
|
+
$ es.find_expired_indices() ... default is 'logstash-*' is not specified
|
48
|
+
```
|
25
49
|
|
26
|
-
|
50
|
+
Other lesser goodies:
|
27
51
|
|
52
|
+
```
|
28
53
|
$ es = Elasticshelf::Client.new(:host => '127.0.0.1:9200')
|
29
54
|
|
30
55
|
$ es.version
|
@@ -35,9 +60,10 @@ But for now you can:
|
|
35
60
|
|
36
61
|
$ es.get_info
|
37
62
|
|
38
|
-
$ es.get_cluster_state("
|
63
|
+
$ es.get_cluster_state("index_name")
|
39
64
|
|
40
|
-
$ es.get_index_state("
|
65
|
+
$ es.get_index_state("index_name")
|
66
|
+
```
|
41
67
|
|
42
68
|
## Contributing
|
43
69
|
|
data/elasticshelf.gemspec
CHANGED
data/lib/elasticshelf.rb
CHANGED
@@ -4,6 +4,7 @@ require "elasticshelf/version"
|
|
4
4
|
module Elasticshelf
|
5
5
|
|
6
6
|
module Client
|
7
|
+
|
7
8
|
attr_reader :client, :get_info, :version
|
8
9
|
|
9
10
|
def new(arguments={})
|
@@ -12,6 +13,48 @@ module Elasticshelf
|
|
12
13
|
end
|
13
14
|
extend self
|
14
15
|
|
16
|
+
# ************************************************************
|
17
|
+
# * TODO: loop thru expired indices hash and perform action:
|
18
|
+
# * close, open, delete, wither, snapshot, or restore
|
19
|
+
# ************************************************************
|
20
|
+
|
21
|
+
def find_expired_indices(cutoff_days, prefix='logstash-', separator='.')
|
22
|
+
expired_indices = {}
|
23
|
+
cutoff_date = DateTime.now.utc - cutoff_days
|
24
|
+
cutoff_date_beginning_of_day = set_time_to_beginning_of_day(cutoff_date.strftime("%Y.%m.%d"))
|
25
|
+
required_date_parts = 3 # for now, we only do days not hours
|
26
|
+
# the following should only return 'closed' indices but it returns all indices ???
|
27
|
+
sorted_indices = @client.indices.get_settings(:index => prefix, :expand_wildcards => 'closed').keys
|
28
|
+
sorted_indices.each do |index_name|
|
29
|
+
unprefixed_index_name = index_name.slice(prefix.size-1..-1)
|
30
|
+
date_parts = unprefixed_index_name.split(separator)
|
31
|
+
next unless date_parts.size == required_date_parts
|
32
|
+
index_time = set_time_to_beginning_of_day(unprefixed_index_name, separator=separator)
|
33
|
+
if (cutoff_date_beginning_of_day - index_time).to_i >= cutoff_days
|
34
|
+
expired_indices[index_name] = (cutoff_date_beginning_of_day - index_time).to_i
|
35
|
+
puts "index #{index_name} expired #{expired_indices[index_name]} days ago!"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
expired_indices
|
39
|
+
end
|
40
|
+
|
41
|
+
def index_closed?(index_name)
|
42
|
+
index_metadata = @client.cluster.state(:index => index_name, :metric => 'metadata')
|
43
|
+
index_metadata['metadata']['indices'][index_name]['state'] == 'close'
|
44
|
+
end
|
45
|
+
|
46
|
+
def wither_index(index_name)
|
47
|
+
# don't try to disable bloom filter on a closed index, it will re-open them:
|
48
|
+
if index_closed?(index_name)
|
49
|
+
puts "Unable to wither (disable bloom filter) index #{index_name}: It's already closed."
|
50
|
+
return true
|
51
|
+
else
|
52
|
+
result = @client.indices.put_settings(:index => index_name, :body => 'index.codec.bloom.load=false')
|
53
|
+
puts "result=#{result.inspect}"
|
54
|
+
end
|
55
|
+
result
|
56
|
+
end
|
57
|
+
|
15
58
|
def get_index_state(index_name, metric='metadata')
|
16
59
|
index_metadata = @client.cluster.state(:index => index_name, :metric => metric)
|
17
60
|
index_metadata['metadata']['indices'][index_name]['state']
|
@@ -47,6 +90,13 @@ module Elasticshelf
|
|
47
90
|
def version
|
48
91
|
Elasticshelf::VERSION
|
49
92
|
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
def set_time_to_beginning_of_day(index_timestamp, separator='.')
|
97
|
+
return DateTime.strptime(index_timestamp, ['%Y', '%m', '%d'].join(separator))
|
98
|
+
end
|
99
|
+
|
50
100
|
end
|
51
101
|
|
52
102
|
end
|
data/lib/elasticshelf/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elasticshelf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cLee Smith
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.0.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: time_diff
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.3.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.3.0
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|