This documentation is for WSO2 API Manager 2.6.0. View documentation for the latest release.

All docs This doc
||
Skip to end of metadata
Go to start of metadata
In order to generate Geolocation based statistics, you need to pass an x-forwarded-for header with the relevant IP in the API request.

Note that this document uses MySQL as an example for configuring the GEO_LOCATION_DATA database.

  1. Use the Geolocation dataset that you created here.
  2. Unzip the file you downloaded.

  3. Create required tables in GEO_LOCATION_DATA database by executing one of the scripts in the Geolocation Data/dbscripts directory. In this example, mysql.sql is executed.

    This can be done using the MySQL Workbench.

    For detailed instructions to run the database script, see MySQL Documentation - The Workbench Scripting Shell.

  4. Restore data to the  BLOCKS and LOCATION tables by importing data from the BLOCKS.csv and LOCATION.csv from the .Geolocation Data/data directory of the extracted zip using the commands given below.

    • Importing Geolocation Data/data/ LOCATION .csv 
      mysqlimport -u root -p --ignore-lines=2 --fields-terminated-by=, --fields-optionally-enclosed-by='"' --local GEO_LOCATION_DATA <path_to_folder_location>/GeolocationData/data/LOCATION.csv  


    • Importing Geolocation Data/data/BLOCKS.csv 
      mysqlimport -u root -p --ignore-lines=2 --fields-terminated-by=, --fields-optionally-enclosed-by='"' --local GEO_LOCATION_DATA <Extracted_location>/GeolocationData/data/BLOCKS.csv

  5. Check whether your imported dataset is working properly by executing the following query in the MySQL Command Line.

    SELECT loc.country_name,loc.subdivision_1_name FROM BLOCKS block , LOCATION loc WHERE block.network_blocks = '<Network_part_of_ipv4>' AND
    <Long_value_of_publilc_IP> BETWEEN block.network AND block.broadcast AND block.geoname_id=loc.geoname_id;

    Example query

    SELECT loc.country_name,loc.subdivision_1_name FROM BLOCKS block , LOCATION loc WHERE block.network_blocks = '221.192' AND 3720398641 
    BETWEEN block.network AND block.broadcast AND block.geoname_id=loc.geoname_id;
  6. Download a JDBC provider depending on the database you are using (MySQL, in this example), and copy it to the <APIM_ANALYTICS_HOME>/lib directory.
  7. Configure the datasource for the Geo location.
    A default datasource for Geo location is packed by default in the <APIM_ANALYTICS_HOME>/conf/worker/deployment.yaml file under data sources.
    You can edit the following data source to point to his own db and import the geo location data.

        - name: GEO_LOCATION_DATA
          description: "The data source used for geo location database"
          jndiConfig:
            name: jdbc/GEO_LOCATION_DATA
          definition:
            type: RDBMS
            configuration:
              jdbcUrl: 'jdbc:h2:${sys:carbon.home}/wso2/worker/database/GEO_LOCATION_DATA;AUTO_SERVER=TRUE'
              username: wso2carbon
              password: wso2carbon
              driverClassName: org.h2.Driver
              maxPoolSize: 50
              idleTimeout: 60000
              validationTimeout: 30000
              isAutoCommit: false

For information on how to configure alerts, see Configuring Alerts.

  • No labels