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::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

#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
# File 'lib/logstash/outputs/sumologic/monitor.rb', line 13

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

  @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



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

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

#build_stats_payloadObject

def stop



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

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

#startObject

initialize



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

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_input_events.value > 0
          @queue.enq(build_stats_payload())
        end
      end # while
    }
  end # if
end

#stopObject

def start



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

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