Method: Common::Utils#detect_platform

Defined in:
lib/fluent/plugin/common.rb

#detect_platform(use_metadata_service) ⇒ Object

Determine what platform we are running on by consulting the metadata service (unless the user has explicitly disabled using that).

[View source]

107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/fluent/plugin/common.rb', line 107

def detect_platform()
  unless 
    @log.info 'use_metadata_service is false; not detecting platform'
    return Platform::OTHER
  end

  begin
    open('http://' + METADATA_SERVICE_ADDR, proxy: false) do |f|
      if f.meta['metadata-flavor'] == 'Google'
        @log.info 'Detected GCE platform'
        return Platform::GCE
      end
      if f.meta['server'] == 'EC2ws'
        @log.info 'Detected EC2 platform'
        return Platform::EC2
      end
    end
  rescue StandardError => e
    @log.error 'Failed to access metadata service: ', error: e
  end

  @log.info 'Unable to determine platform'
  Platform::OTHER
end