Class: Lstash::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/lstash/client.rb

Defined Under Namespace

Classes: ConnectionError, ShardMismatchError

Constant Summary collapse

PER_PAGE =

best time, lowest resource usage

5000
COUNT_STEP =

1 hours

3600
GREP_STEP =

1 hour

3600

Instance Method Summary collapse

Constructor Details

#initialize(es_client, options = {}) ⇒ Client

Returns a new instance of Client.

Raises:



22
23
24
25
26
27
28
# File 'lib/lstash/client.rb', line 22

def initialize(es_client, options = {})
  raise ConnectionError, "No elasticsearch client specified" if es_client.nil?

  @es_client = es_client
  @logger = options[:logger] || (options[:debug] ? debug_logger : NullLogger.new)
  @wildcard = options[:wildcard]
end

Instance Method Details

#count(query) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/lstash/client.rb', line 30

def count(query)
  @logger.debug "count from=#{query.from} to=#{query.to}"

  count = 0
  use_wildcard = @wildcard.nil? ? true : @wildcard
  if use_wildcard
    count = count_messages(query.wildcard_indices, query)
  else
    count = 0
    query.each_period(COUNT_STEP) do |index, hour_query|
      count += count_messages(index, hour_query)
    end
  end
  @logger.debug "total count=#{count}"
  count
end

#grep(query) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/lstash/client.rb', line 47

def grep(query)
  @logger.debug "grep from=#{query.from} to=#{query.to}"

  count = 0
  use_wildcard = @wildcard.nil? ? false : @wildcard
  if use_wildcard
    grep_messages(query.wildcard_indices, query) do |message|
      count += 1
      yield message if block_given?
    end
  else
    query.each_period(GREP_STEP) do |index, hour_query|
      grep_messages(index, hour_query) do |message|
        count += 1
        yield message if block_given?
      end
    end
  end

  @logger.debug "total count=#{count}"
  count
end