Class: LogStash::Outputs::SumoLogic::Monitor

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/logstash/outputs/sumologic/monitor.rb

Constant Summary

Constants included from Common

Common::CARBON2, Common::CATEGORY_HEADER, Common::CATEGORY_HEADER_DEFAULT, Common::CATEGORY_HEADER_DEFAULT_STATS, Common::CLIENT_HEADER, Common::CLIENT_HEADER_VALUE, Common::CONTENT_ENCODING, Common::CONTENT_TYPE, Common::CONTENT_TYPE_CARBON2, Common::CONTENT_TYPE_GRAPHITE, Common::CONTENT_TYPE_LOG, Common::DEFAULT_LOG_FORMAT, Common::DEFLATE, Common::GRAPHITE, Common::GZIP, Common::HOST_HEADER, Common::LOG_TO_CONSOLE, Common::METRICS_NAME_PLACEHOLDER, Common::NAME_HEADER, Common::NAME_HEADER_DEFAULT, Common::STATS_TAG, Common::STOP_TAG

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Common

#blank?, #log_dbg, #log_err, #log_info, #log_warn, #set_logger

Constructor Details

#initialize(queue, stats, config) ⇒ Monitor

Returns a new instance of Monitor.



13
14
15
16
17
18
19
20
21
22
# File 'lib/logstash/outputs/sumologic/monitor.rb', line 13

def initialize(queue, stats, config)
  @queue = queue
  @stats = stats
  @stopping = Concurrent::AtomicBoolean.new(false)
  @header_builder = HeaderBuilder.new(config)

  @enabled = config["stats_enabled"] ||= false
  @interval = config["stats_interval"] ||= 60
  @interval = @interval < 0 ? 0 : @interval
end

Instance Attribute Details

#is_pileObject (readonly)

Returns the value of attribute is_pile.



11
12
13
# File 'lib/logstash/outputs/sumologic/monitor.rb', line 11

def is_pile
  @is_pile
end

Instance Method Details

#build_metric_line(key, value, timestamp) ⇒ Object

def build_stats_payload



72
73
74
# File 'lib/logstash/outputs/sumologic/monitor.rb', line 72

def build_metric_line(key, value, timestamp)
  "metric=#{key} interval=#{@interval}  category=monitor #{value} #{timestamp}"
end

#build_stats_payloadObject

def stop



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/logstash/outputs/sumologic/monitor.rb', line 48

def build_stats_payload()
  timestamp = Time.now().to_i
  
  counters = [
    "total_input_events", 
    "total_input_bytes", 
    "total_metrics_datapoints", 
    "total_log_lines", 
    "total_output_requests",
    "total_output_bytes",
    "total_output_bytes_compressed",
    "total_response_times",
    "total_response_success"
  ].map { |key|
    value = @stats.send(key).value
    log_dbg("stats",
      :key => key,
      :value => value)
    build_metric_line(key, value, timestamp)
  }.join($/)

  "#{STATS_TAG}#{counters}"
end

#headersObject

def build_metric_line



76
77
78
# File 'lib/logstash/outputs/sumologic/monitor.rb', line 76

def headers()
  @headers ||= @header_builder.build_stats()
end

#startObject

initialize



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/logstash/outputs/sumologic/monitor.rb', line 24

def start()
  log_info("starting monitor...", :interval => @interval)
  @stopping.make_false()
  if (@enabled)
    @monitor_t = Thread.new { 
      while @stopping.false?
        Stud.stoppable_sleep(@interval) { @stopping.true? }
        if @stats.total_log_lines.value > 0 || @stats.total_metrics_datapoints.value > 0
          @queue.enq(Batch.new(headers(), build_stats_payload()))
        end
      end # while
    }
  end # if
end

#stopObject

def start



39
40
41
42
43
44
45
46
# File 'lib/logstash/outputs/sumologic/monitor.rb', line 39

def stop()
  @stopping.make_true()
  if (@enabled)
    log_info("shutting down monitor...")
    @monitor_t.join
    log_info("monitor is fully shutted down")
  end
end