Module: Fluent::Geoip
- Included in:
- HttpVikiInput
- Defined in:
- lib/fluent/plugin/geoip.rb
Instance Method Summary collapse
- #city_of_ip(ip) ⇒ Object
- #country_code_of_ip(ip) ⇒ Object
- #geoip_db_path ⇒ Object
- #global_geoip ⇒ Object
Instance Method Details
#city_of_ip(ip) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/fluent/plugin/geoip.rb', line 8 def city_of_ip(ip) city = global_geoip.lookup(ip) record = {} record['dma_code'] = city.location.metro_code record['city_name'] = city.city && city.city.name record['latitude'] = city.location.latitude.to_s record['longitude'] = city.location.longitude.to_s record['postal_code'] = city.postal.code record['region_name'] = city.subdivisions.first && city.subdivisions.first.iso_code record end |
#country_code_of_ip(ip) ⇒ Object
3 4 5 6 |
# File 'lib/fluent/plugin/geoip.rb', line 3 def country_code_of_ip(ip) iso_code = global_geoip.lookup(ip).country.iso_code iso_code && iso_code.downcase end |
#geoip_db_path ⇒ Object
24 25 26 |
# File 'lib/fluent/plugin/geoip.rb', line 24 def geoip_db_path '/etc/GeoIP2-City.mmdb' end |
#global_geoip ⇒ Object
20 21 22 |
# File 'lib/fluent/plugin/geoip.rb', line 20 def global_geoip @@global_geoip ||= ::MaxMindDB.new(geoip_db_path) end |