Sha256: de43cfc1ac45666f9031e1671857c4529d396792fafdf086266541d2f361713f

Contents?: true

Size: 892 Bytes

Versions: 45

Compression:

Stored size: 892 Bytes

Contents

require 'thread'
require 'socket'

module Aws
  module ClientSideMonitoring
    # @api private
    class Publisher
      attr_reader :agent_port

      def initialize(opts = {})
        @agent_port = opts[:agent_port]
        @mutex = Mutex.new
      end

      def agent_port=(value)
        @mutex.synchronize do
          @agent_port = value
        end
      end

      def publish(request_metrics)
        send_datagram(request_metrics.api_call.to_json)
        request_metrics.api_call_attempts.each do |attempt|
          send_datagram(attempt.to_json)
        end
      end

      def send_datagram(msg)
        if @agent_port
          socket = UDPSocket.new
          begin
            socket.connect("127.0.0.1", @agent_port)
            socket.send(msg, 0)
          rescue Errno::ECONNREFUSED
            # Drop on the floor
          end
        end
      end
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
aws-sdk-core-3.55.0 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.54.2 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.54.1 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.54.0 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.53.1 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.53.0 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.52.1 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.52.0 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.51.0 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.50.0 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.49.0 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.48.6 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.48.5 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.48.4 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.48.3 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.48.2 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.48.1 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.48.0 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.47.0 lib/aws-sdk-core/client_side_monitoring/publisher.rb
aws-sdk-core-3.46.2 lib/aws-sdk-core/client_side_monitoring/publisher.rb