geostat/README.md

82 lines
2.9 KiB
Markdown
Raw Normal View History

2018-10-10 13:35:05 +02:00
# GeoStat
### Version 0.2
![Alt text](https://github.com/ratibor78/geostat/blob/master/geostat.png?raw=true "Grafana dashboard example")
2018-10-10 13:35:05 +02:00
2018-10-10 21:02:58 +02:00
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.
2018-10-10 13:35:05 +02:00
# Main Features:
- Parsing incoming ip's from web server log and convert them in to GEO metrics for the InfluxDB.
2018-10-11 05:30:41 +02:00
- Used standard python libs for the maximum compatibility.
2018-10-10 20:22:24 +02:00
- Having an external **settings.ini** for comfortable changing parameters.
2018-10-10 20:48:48 +02:00
Json format that script send to InfluxDB looks like:
2018-10-10 20:22:24 +02:00
```
[
{
'fields': {
'count': 1
},
'measurement': 'geo_cube',
'tags': {
2018-10-12 21:16:00 +02:00
'host': 'cube'
2018-10-10 20:22:24 +02:00
'geohash': 'u8mb76rpv69r',
'country_code': 'UA'
}
}
]
```
2018-10-12 21:16:00 +02:00
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.
2018-10-12 21:16:34 +02:00
2018-10-12 21:21:11 +02:00
You can see the example Grafana dashboard in **geomap.json** file.
### Tech
2018-10-10 14:52:34 +02:00
GeoStat uses a number of open source libs to work properly:
2018-10-10 14:53:15 +02:00
* [Geohash](https://github.com/vinsci/geohash) - Python module that provides functions for decoding and encoding Geohashes.
* [InfluxDB-Python](https://github.com/influxdata/influxdb-python) - Python client for InfluxDB.
# Installation
Using install.sh script:
1) Clone the repository.
2018-10-10 20:22:24 +02:00
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:
2018-10-11 05:27:41 +02:00
1) Clone the repository, create environment and install requirements
```sh
$ cd geostat
$ virtualenv venv && source venv/bin/activate
$ pip install -r requirements.txt
```
2018-10-11 05:27:41 +02:00
2) Modify **settings.ini** & **geostat.service** files and copy service to systemd.
```sh
2018-10-11 05:27:41 +02:00
$ cp settings.ini.bak settings.ini
$ vi settings.ini
$ cp geostat.service.template geostat.service
$ vi geostat.service
$ cp geostat.service /lib/systemd/system/
```
2018-10-10 20:49:52 +02:00
3) Download latest GeoLiteCity.dat from MaxMind
2018-10-10 20:48:48 +02:00
```sh
$ wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
$ gunzip GeoLiteCity.dat.gz
```
2018-10-10 20:49:52 +02:00
4) Then enable and start service
```sh
$ 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!**