/ipv4-heatmap

IPv4 Heatmap using Go and Leaflet

Primary LanguageGoMIT LicenseMIT

ipv4-heatmap

Setup

Create 2 VMs with CentOS 7 (other OSes work too). I created one VM and cloned it into the other once it was configured using Digital Ocean's tools but that is up to you. Install Maria DB using the instructions found here. Then install Go using the instructions found here. Use the files in /etc/sysconfig and /etc/systemd to impelement main.go as the system service heatmap. I placed my Go files in /home but the server location is up to you as long as you follow the instructions to configure Go correctly and edit the systemd config files accordingly.

Database

The heatmap data is stored in a single MySQL table. Only the latitude, longitude and IP count are stored for effeciency. The coordinates are stored to 4 decimals of precision which is enough for this use. Create a database and a user for that database, then

Data

Originally used data from GeoLite Data by MaxMind, imported via import.go. Now uses GeoLite 2 data from GeoLite2 Data, also from MaxMind.

Importing the Data

After the database is configured, run main.go import to import the GeoLite data or run main.go import2 to import the GeoLite2 data.

Endpoint Main.go

The main.go file powers the endpoint and also delegates data importing.

Endpoint API

The APIs return the data encoded in a protocol buffer object for the caller to decode and use. There are 2 APIs:

  • /locations - Used to fetch a list of all location/IP data.
  • /locations/{latitude1}/{longitude1}/{latitude2}/{longitude2} - Used to fetch location/IP data within a Lat/Lon bounding box.

Frontend Main.go

The main.go file in the frontend fetches the data and decodes it. It also serves the static assets needed for the map.

Testing

Currently, you can run a basic endpoint test by visiting test page. The page triggers two endpoint calls and does a basic check on the results.

TODO/Issues

  • The heat intensities are not bright enough when zoomed in at the city level.
  • When zooming in from world view to state-level the heatmap doesn't appear to update correctly until you zoom back out one step.
  • Some mid-level zoom layers could be improved in terms of heatmap display.
  • Create a way to cancel previous pending requests when a new request is issued. Helps when the user changes the display multiple times in a row.
  • Expand testing and use the go language testing framework to perform more tests.