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
# File 'lib/logstash/outputs/application_insights/shutdown.rb', line 27

def initialize
  configuration = Config.current

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

end

Class Method Details

.instanceObject



94
95
96
# File 'lib/logstash/outputs/application_insights/shutdown.rb', line 94

def self.instance
  @@instance
end

Instance Method Details

#display_msg(msg) ⇒ Object



85
86
87
88
# File 'lib/logstash/outputs/application_insights/shutdown.rb', line 85

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

#startObject



35
36
37
38
# File 'lib/logstash/outputs/application_insights/shutdown.rb', line 35

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

#submitObject



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
81
82
83
# File 'lib/logstash/outputs/application_insights/shutdown.rb', line 40

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