From 03134c4260f724008d6600a2296ccdc86f24c490 Mon Sep 17 00:00:00 2001 From: Maxime Wack Date: Thu, 11 Jan 2018 09:38:46 +0100 Subject: [PATCH] Prototype (access.log parsing + geolocation) --- geoip.R | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/geoip.R b/geoip.R index e69de29..891970c 100644 --- a/geoip.R +++ b/geoip.R @@ -0,0 +1,12 @@ +library(tidyverse) +library(ipapi) + +system("grep GraphTV /var/log/nginx/access.log | grep -vi bot | cut -d ' ' -f 1 | sort | uniq", intern = T) -> ips + +read_delim("/var/log/nginx/access.log", delim = " ", col_names = c("ip", "null", "user", "timestamp", "zone", "req", "status", "size", "referer", "agent")) %>% + select(-null, -user, -zone, -size) %>% + mutate(timestamp = timestamp %>% str_sub(2) %>% as.POSIXct(format = "%d/%b/%Y:%H:%M:%S")) %>% + mutate_at(vars(status), factor) -> access + +geolocate(ips) -> geoip +