lib/logstash/outputs/scalyr.rb
# Sends a status update to Scalyr by posting a log entry under the special logfile of 'logstash_plugin.log'
# Instead of creating a separate thread, let this method be invoked once at startup and then every 5 minutes
# at most.  (If no events are received, no status update will be sent even if 5 minutes has elapsed).
# Finally, note that there could be multiple instances of this plugin (one per worker), in which case each worker
# thread sends their own status updates.  This is intentional so that we know how much data each worker thread is
# uploading to Scalyr over time.
Sends a status update to Scalyr by posting a log entry under the special logfile of 'logstash_plugin.log'
Instead of creating a separate thread, let this method be invoked once at startup and then every 5 minutes
at most.  (If no events are received, no status update will be sent even if 5 minutes has elapsed).
Finally, note that there could be multiple instances of this plugin (one per worker), in which case each worker
thread sends their own status updates.  This is intentional so that we know how much data each worker thread is
uploading to Scalyr over time.
Sends a status update to Scalyr by posting a log entry under the special logfile of ' logstash_plugin . log ' Instead of creating a separate thread let this method be invoked once at startup and then every 5 minutes at most . ( If no events are received no status update will be sent even if 5 minutes has elapsed ) . Finally note that there could be multiple instances of this plugin ( one per worker ) in which case each worker thread sends their own status updates . This is intentional so that we know how much data each worker thread is uploading to Scalyr over time .
def send_status(client_session = nil)
    client_session = @client_session if client_session.nil?
    status_event = {
      :ts => (Time.now.to_f * (10**9)).round,
      :attrs => {
        'logfile' => "scalyr_logstash.log",
        'plugin_id' => self.id,
      }
    }
    @send_stats.synchronize do
      if !@last_status_transmit_time
        status_event[:attrs]['message'] = sprintf("Started Scalyr LogStash output plugin %s (compression_type=%s,compression_level=%s,json_library=%s)." %
                                                  [PLUGIN_VERSION, @compression_type, @compression_type, @json_library])
        status_event[:attrs][EVENT_LEVEL_SERVER_HOST_ATTRIBUTE_NAME] = @node_hostname
      else
        cur_time = Time.now()
        return if (cur_time.to_i - @last_status_transmit_time.to_i) < @status_report_interval
        msg = 'plugin_status: '
        cnt = 0
        client_session.get_stats.each do |k, v|
          val = v.instance_of?(Float) ? sprintf("%.4f", v) : v
          val = val.nil? ? 0 : val
          msg << ' ' if cnt > 0
          msg << "#{k.to_s}=#{val}"
          cnt += 1
        end
        get_stats.each do |k, v|
          val = v.instance_of?(Float) ? sprintf("%.4f", v) : v
          val = val.nil? ? 0 : val
          msg << ' ' if cnt > 0
          msg << "#{k.to_s}=#{val}"
          cnt += 1
        end
        status_event[:attrs]['message'] = msg
        status_event[:attrs][EVENT_LEVEL_SERVER_HOST_ATTRIBUTE_NAME] = @node_hostname
        status_event[:attrs]['parser'] = @status_parser
      end
      multi_event_request = create_multi_event_request([status_event], nil, nil, nil)
      begin
        client_session.post_add_events(multi_event_request[:body], true, 0)
      rescue => e
        if e.body
          @logger.warn(
            "Unexpected error occurred while uploading status to Scalyr",
            :error_message => e.message,
            :error_class => e.class.name,
            :body => Scalyr::Common::Util.truncate(e.body, 512)
          )
        else
          @logger.warn(
            "Unexpected error occurred while uploading status to Scalyr",
            :error_message => e.message,
            :error_class => e.class.name
          )
        end
        return
      end
      @last_status_transmit_time = Time.now()
    end
    if @log_status_messages_to_stdout
      @logger.info msg
    end
    status_event
  end
def send_status ( client_session = nil ) client_session = @client_session if client_session . nil? status_event = { :ts => ( Time . now . to_f * ( 10 ** 9 ) ) . round , :attrs => { 'logfile' => "scalyr_logstash.log" , 'plugin_id' => self . id , } } @send_stats . synchronize do if ! @last_status_transmit_time status_event [ :attrs ] [ 'message' ] = sprintf ( "Started Scalyr LogStash output plugin %s (compression_type=%s,compression_level=%s,json_library=%s)." % [ PLUGIN_VERSION , @compression_type , @compression_type , @json_library ] ) status_event [ :attrs ] [ EVENT_LEVEL_SERVER_HOST_ATTRIBUTE_NAME ] = @node_hostname else cur_time = Time . now ( ) return if ( cur_time . to_i - @last_status_transmit_time . to_i ) < @status_report_interval msg = 'plugin_status: ' cnt = 0 client_session . get_stats . each do | k , v | val = v . instance_of? ( Float ) ? sprintf ( "%.4f" , v ) : v val = val . nil? ? 0 : val msg << ' ' if cnt > 0 msg << "#{k.to_s}=#{val}" cnt += 1 end get_stats . each do | k , v | val = v . instance_of? ( Float ) ? sprintf ( "%.4f" , v ) : v val = val . nil? ? 0 : val msg << ' ' if cnt > 0 msg << "#{k.to_s}=#{val}" cnt += 1 end status_event [ :attrs ] [ 'message' ] = msg status_event [ :attrs ] [ EVENT_LEVEL_SERVER_HOST_ATTRIBUTE_NAME ] = @node_hostname status_event [ :attrs ] [ 'parser' ] = @status_parser end multi_event_request = create_multi_event_request ( [ status_event ] , nil , nil , nil ) begin client_session . post_add_events ( multi_event_request [ :body ] , true , 0 ) rescue => e if e . body @logger . warn ( "Unexpected error occurred while uploading status to Scalyr" , :error_message => e . message , :error_class => e . class . name , :body => Scalyr :: Common :: Util . truncate ( e . body , 512 ) ) else @logger . warn ( "Unexpected error occurred while uploading status to Scalyr" , :error_message => e . message , :error_class => e . class . name ) end return end @last_status_transmit_time = Time . now ( ) end if @log_status_messages_to_stdout @logger . info msg end status_event end
Sends a status update to Scalyr by posting a log entry under the special logfile of 'logstash_plugin.log'
Instead of creating a separate thread, let this method be invoked once at startup and then every 5 minutes
at most.
Sends a status update to Scalyr by posting a log entry under the special logfile of ' logstash_plugin . log ' Instead of creating a separate thread let this method be invoked once at startup and then every 5 minutes at most .
# echee TODO: get instance stats from session and create a status log line
client_session