Browse Source

Prototype (access.log parsing + geolocation)

master
Maxime Wack 6 years ago
parent
commit
03134c4260
1 changed files with 12 additions and 0 deletions
  1. +12
    -0
      geoip.R

+ 12
- 0
geoip.R View File

@@ -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


Loading…
Cancel
Save