Enabling Geolocation Based Statistics¶
Follow the steps below to configure WSO2 IS Analytics Server to display the regions of the users authenticated though WSO2 Identity Server.
-
Create a Geo Location dataset by following the guide given here.
-
Create the database by executing one of the scripts in the
Geolocation Data/dbscripts
directory. In this example,mysql.sql
is executed.-
Sign in to the mysql client by executing the command.
mysql -u <MYSQL_USERNAME> -p
Provide the mysql password when prompted.
-
Create the database by executing the following command.
CREATE DATABASE GEO_LOCATION_DATA; USE GEO_LOCATION_DATA;
-
Run the
Geolocation Data/dbscripts/mysql.sql
script.source <PATH_OF_mysql.sql_SCRIPT>
Tip
You can also run the scripts using MySQL Workbench. For detailed instructions, see MySQL Documentation - The Workbench Scripting Shell .
-
-
Populate the data to the BLOCKS and LOCATION tables from the following files.
Geolocation Data/data/BLOCKS.csv
Geolocation Data/data/LOCATION.csv
Tip
For more information, see MySQL Documentation - Data Export and Import .
Alternatively you can navigate to the
Geolocation Data/data
directory and run the following commands.-
The command to populate data to the BLOCKS table:
mysqlimport -u <mysql username> -p --ignore-lines=2 --fields-terminated-by=, --fields-optionally-enclosed-by='"' --local GEO_LOCATION_DATA <PATH_OF_BLOCKS.csv_FILE>
Provide the mysql password when prompted.
-
The command to populate data to the LOCATION table:
mysqlimport -u <mysql username> -p --ignore-lines=2 --fields-terminated-by=, --fields-optionally-enclosed-by='"' --local GEO_LOCATION_DATA <PATH_OF_LOCATION.csv_FILE>
Provide the mysql password when prompted.
-
Download a JDBC provider depending on the database you are using (MySQL in this example) from here, and extract it.
- Copy the
mysql-connector-java-<VERSION>.jar
file to the<IS_ANALYTICS_HOME>/lib
directory. -
Configure the following in the
<IS_ANALYTICS_HOME>/conf/worker/deployment.yaml
file as given below.name: GEO_LOCATION_DATA description: "The data source used for geo location database" jndiConfig: name: jdbc/GEO_LOCATION_DATA definition: type: RDBMS configuration: jdbcUrl: '<GEO_LOCATION_DATBASE_URL>' username: <MYSQL_USERNAME> password: <MYSQL_PASSWORD> driverClassName: <MYSQL_DRIVER_CLASS_NAME> maxPoolSize: 50 idleTimeout: 60000 validationTimeout: 30000 isAutoCommit: false
-
jdbcUrl
: This is the URL of the geo location data base, e.g.,jdbc: mysql://localhost:3306/GEO_LOCATION_DATA
. -
username
: This is the mysql user name, e.g.,wso2carbon
. password
: This is the mysql password, e.g,wso2carbon
.driverClassName
: This is the package name of the JDBC driver of your mysql connector, e.g.,com.mysql.jdbc.Driver
.
-
-
Open the
<IS_ANALYTICS_HOME>/wso2/worker/deployment/siddhi-files/IS_ANALYTICS_AUTHENTICATION_COMMON.sidddhi
file.- Uncomment the line 120:
(ifThenElse(geo:findCountryFromIP(remoteIp)=="", "N/A", geo:findCountryFromIP(remoteIp)) as region,)
. - Comment out the line 121:
(region,)
.
Tip
For testing purposes
Follow the steps below to load test data to the system.
-
Navigate to the
<IS_ANALYTICS_HOME>/samples/sample-clients/is-analytics-client
directory on a command prompt. -
Run the following command.
ant -Dport=7612 -Dhost=0.0.0.0
- Uncomment the line 120:
-
Restart WSO2 IS Analytics worker node.