Class: LogStash::Outputs::Application_insights::Shutdown

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/outputs/application_insights/shutdown.rb

Constant Summary collapse

@@instance =
Shutdown.new

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeShutdown

Returns a new instance of Shutdown.



27
28
29
30
31
32
33
34
35
# File 'lib/logstash/outputs/application_insights/shutdown.rb', line 27

def initialize
  configuration = Config.current

  @logger_progname = configuration[:logger_progname]
  @logger = configuration[:logger]

  @state = State.instance
  @channels = Channels.instance
end

Class Method Details

.instanceObject



91
92
93
# File 'lib/logstash/outputs/application_insights/shutdown.rb', line 91

def self.instance
  @@instance
end

Instance Method Details

#display_msg(msg) ⇒ Object



82
83
84
85
# File 'lib/logstash/outputs/application_insights/shutdown.rb', line 82

def display_msg ( msg )
    puts "+++ #{@logger_progname} #{msg}"
    # @logger.info { "#{msg}" }

end

#submitObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/logstash/outputs/application_insights/shutdown.rb', line 37

def submit
  display_msg( "start graceful shutdown, flush all events" )

  # wait for all uploads to finish

  start_bytes_in_memory = @state.bytes_in_memory
  bytes_in_memory = start_bytes_in_memory
  while bytes_in_memory > 0 do 
    sleep( 1 )
    bytes_in_memory = @state.bytes_in_memory
    percent = 100 * (1 - ( bytes_in_memory.to_f / start_bytes_in_memory ) )
    display_msg( "#{percent.to_i}% events were uploaded to Azure storage" ) if percent < 100.0
  end
  display_msg( "all events were uploaded to Azure storage" )

  # close all blobs activity

  Blob.close

  # close all channels activity

  @channels.close

  # wait for all uploads to commit

  start_pending_commits = @state.pending_commits
  pending_commits = start_pending_commits
  while pending_commits > 0 do 
    sleep( 1 )
    pending_commits = @state.pending_commits
    percent = 100 * (1 - ( pending_commits.to_f / start_pending_commits ) )
    display_msg( "#{percent.to_i}% events were commited to Azure storage" ) if percent < 100.0
  end
  display_msg( "all events were commited to Azure storage" )

  # wait for all blobs to be notified

  start_pending_notifications = @state.pending_notifications
  pending_notifications = start_pending_notifications
  while pending_notifications > 0 do 
    sleep( 1 ) 
    pending_notifications = @state.pending_notifications
    percent = 100 * (1 - ( pending_notifications.to_f / start_pending_notifications ) )
    display_msg( "#{percent.to_i}% events were notified to Application Insights Analytics" ) if percent < 100.0
  end

  # done

  display_msg( "all events were notified to Application Insights Analytics" )
end