diff --git a/geoip.R b/geoip.R index 5387615..21a16ce 100644 --- a/geoip.R +++ b/geoip.R @@ -1,6 +1,8 @@ library(tidyverse) library(RSQLite) library(ipapi) +library(leaflet) + # sqlite3 access.db # create table access(ip, null1, user, timestamp, zone, req, status, size, referer, agent, null2); # .separator " " @@ -36,3 +38,16 @@ if (length(ips) > 0) dbConnect(SQLite(), "access.db") %>% dbWriteTable("geoip", geoip, append = T) } + +src_sqlite("access.db") %>% + tbl("access") %>% + collect %>% + left_join(geoip, by = c("ip" = "query")) %>% + select(-null1, -user, -zone, -size, -null2, -as, -countryCode, -org, -region, -regionName, -status.y, -timezone, -zip, -isp) %>% + mutate(timestamp = timestamp %>% str_sub(2) %>% as.POSIXct(format = "%d/%b/%Y:%H:%M:%S"), + req = req %>% str_replace("(HEAD|GET|POST) ", ""), + req = req %>% str_replace("/(.*?/).*", "\\1")) -> geoaccess + +leaflet(data = geoaccess) %>% + addProviderTiles(providers$CartoDB.Positron) %>% + addMarkers(~lon, ~lat, clusterOptions = markerClusterOptions())