Class: LogStash::Outputs::Application_insights::Telemetry
- Inherits:
-
Object
- Object
- LogStash::Outputs::Application_insights::Telemetry
- Defined in:
- lib/logstash/outputs/application_insights/telemetry.rb
Constant Summary collapse
- LOGSTASH_TELEMETRY_INSTRUMENTATION_KEY =
"52fe6bb7-5528-4b4e-b2cc-12ef128633b4"
- @@instance =
Telemetry.new
Instance Attribute Summary collapse
-
#telemetry_channel ⇒ Object
readonly
Returns the value of attribute telemetry_channel.
Class Method Summary collapse
Instance Method Summary collapse
- #create_async_channel(ikey) ⇒ Object
- #flush ⇒ Object
-
#initialize ⇒ Telemetry
constructor
A new instance of Telemetry.
- #set_async_channel_properties(tc) ⇒ Object
- #set_channel_context(tc) ⇒ Object
- #track_event ⇒ Object
- #track_metric ⇒ Object
- #track_request ⇒ Object
Constructor Details
#initialize ⇒ Telemetry
Returns a new instance of Telemetry.
31 32 33 34 35 36 37 38 39 |
# File 'lib/logstash/outputs/application_insights/telemetry.rb', line 31 def initialize configuration = Config.current @enable_telemetry_to_microsoft = configuration[:enable_telemetry_to_microsoft] if @enable_telemetry_to_microsoft @telemetry_channel = create_async_channel( LOGSTASH_TELEMETRY_INSTRUMENTATION_KEY ) set_async_channel_properties( @telemetry_channel ) set_channel_context( @telemetry_channel ) end end |
Instance Attribute Details
#telemetry_channel ⇒ Object (readonly)
Returns the value of attribute telemetry_channel.
25 26 27 |
# File 'lib/logstash/outputs/application_insights/telemetry.rb', line 25 def telemetry_channel @telemetry_channel end |
Class Method Details
.instance ⇒ Object
111 112 113 |
# File 'lib/logstash/outputs/application_insights/telemetry.rb', line 111 def self.instance @@instance end |
Instance Method Details
#create_async_channel(ikey) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/logstash/outputs/application_insights/telemetry.rb', line 42 def create_async_channel ( ikey ) sender = ApplicationInsights::Channel::AsynchronousSender.new queue = ApplicationInsights::Channel::AsynchronousQueue.new( sender ) channel = ApplicationInsights::Channel::TelemetryChannel.new( nil, queue ) ApplicationInsights::TelemetryClient.new( ikey, channel ) end |
#flush ⇒ Object
101 102 103 104 105 |
# File 'lib/logstash/outputs/application_insights/telemetry.rb', line 101 def flush if @enable_telemetry_to_microsoft @telemetry_channel.flush end end |
#set_async_channel_properties(tc) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/logstash/outputs/application_insights/telemetry.rb', line 49 def set_async_channel_properties ( tc ) # flush telemetry if we have 10 or more telemetry items in our queue tc.channel.queue.max_queue_length = 10 # send telemetry to the service in batches of 5 tc.channel.sender.send_buffer_size = 5 # the background worker thread will be active for 5 seconds before it shuts down. if # during this time items are picked up from the queue, the timer is reset. tc.channel.sender.send_time = 5 # the background worker thread will poll the queue every 0.5 seconds for new items tc.channel.sender.send_interval = 0.5 end |
#set_channel_context(tc) ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/logstash/outputs/application_insights/telemetry.rb', line 61 def set_channel_context ( tc ) # tc.context.application.id = 'logstash-output-Application-Insights plugin' tc.context.application.ver = VERSION tc.context.application.build = LOGSTASH_CORE_VERSION tc.context.device.id = Socket.gethostname.strip # tc.context.device.oem_name = 'Asus' # tc.context.device.model = 'X31A' tc.context.device.type = Utils.os # tc.context.user.id = '[email protected]' end |
#track_event ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/logstash/outputs/application_insights/telemetry.rb', line 72 def track_event if @enable_telemetry_to_microsoft = yield name = .delete( :name ) @telemetry_channel.track_event( name, ) end end |
#track_metric ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/logstash/outputs/application_insights/telemetry.rb', line 80 def track_metric if @enable_telemetry_to_microsoft = yield name = .delete( :name ) value = .delete( :value ) @telemetry_channel.track_metric( name, value, ) end end |
#track_request ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/logstash/outputs/application_insights/telemetry.rb', line 89 def track_request if @enable_telemetry_to_microsoft = yield id = .delete( :id ) start_time = .delete( :start_time ) duration = .delete( :duration ) response_code = .delete( :response_code ) success = .delete( :success ) @telemetry_channel.track_request( id, start_time, duration, response_code, success, ) end end |