No description
Find a file
2019-02-04 14:00:54 +01:00
.gitignore first commit 2018-10-08 18:13:00 +03:00
geomap.json Added Grafana dashboard geomap.json file, new. 2018-10-12 22:49:52 +03:00
geoparser.py Update to add ipv6 based lines 2019-02-04 13:59:41 +01:00
geostat.png add logo png 2018-10-10 14:35:05 +03:00
geostat.service.template added install.sh and changed some file names 2018-10-10 09:46:09 +03:00
install.sh Update install.sh 2018-10-10 22:17:03 +03:00
README.md Update README.md 2018-10-18 21:57:24 +03:00
requirements.txt Added nice README file and changed requirements 2018-10-10 15:47:23 +03:00
settings.ini.back Add geoip info to settings 2019-02-04 14:00:54 +01:00

GeoStat

Version 0.2

Alt text

GeoStat is a Python script for parsing Nginx logs files and getting GEO data from incoming IP's in it. This script convert parsed data in to Json format and send it to InfluxDB database so you can use it to build some nice Grafana dashboards for example. It runs as service by SystemD and parse log in "tailf" style.

Main Features:

  • Parsing incoming ip's from web server log and convert them in to GEO metrics for the InfluxDB.
  • Used standard python libs for the maximum compatibility.
  • Having an external settings.ini for comfortable changing parameters.

Json format that script send to InfluxDB looks like:

[
    {
        'fields': {
            'count': 1
        },
        'measurement': 'geo_cube',
        'tags': {
            'host': 'cube'
            'geohash': 'u8mb76rpv69r',
            'country_code': 'UA'
        }
     }
]

As you can see there is three tags fields, so you can build dashboards using geohash (with a point on the map) or country code, or build dashboards with variables based on host name tag. A count for any metric equal 1. This script don't parse log file from the begining but parse it line by line after runing. So you can build dashboards using count of geohashes or country codes after some time will pass.

You can find the example Grafana dashboard in geomap.json file or from grafana.com: https://grafana.com/dashboards/8342

Tech

GeoStat uses a number of open source libs to work properly:

  • Geohash - Python module that provides functions for decoding and encoding Geohashes.
  • InfluxDB-Python - Python client for InfluxDB.

Installation

Using install.sh script:

  1. Clone the repository.
  2. CD into dir and run install.sh, it will ask you to set a properly settings.ini parameters, like Nginx access.log path, and InfluxDB settings.
  3. After script will finished you only need to start SystemD service with systemctl start geostat.service.

Manually:

  1. Clone the repository, create environment and install requirements
$ cd geostat
$ virtualenv venv && source venv/bin/activate
$ pip install -r requirements.txt
  1. Modify settings.ini & geostat.service files and copy service to systemd.
$ cp settings.ini.bak settings.ini
$ vi settings.ini
$ cp geostat.service.template geostat.service
$ vi geostat.service
$ cp geostat.service /lib/systemd/system/
  1. Download latest GeoLiteCity.dat from MaxMind
$ wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
$ gunzip GeoLiteCity.dat.gz
  1. Then enable and start service
$ systemctl enable geostat.service
$ systemctl start geostat.service

After first metrics will go to the InfluxDB you can create nice Grafana dashboards.

Have fun !

License

MIT

Free Software, Hell Yeah!