From 027602ba76ffbda23f8b02859a72687e4b68b16f Mon Sep 17 00:00:00 2001 From: Frederik Vanrenterghem Date: Thu, 23 Aug 2018 19:28:47 +0800 Subject: [PATCH] Initiate project. --- .gitignore | 1 + collectd.R | 40 ++++++++++++++++++++++++++++++++++++++++ predictWebsiteHits.R | 19 +++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 .gitignore create mode 100644 collectd.R create mode 100644 predictWebsiteHits.R diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8fce603 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +data/ diff --git a/collectd.R b/collectd.R new file mode 100644 index 0000000..9fd157b --- /dev/null +++ b/collectd.R @@ -0,0 +1,40 @@ +#devtools::install_github("pldimitrov/rrd") +library(rrd) + +rrd_laysan_apache_bytes <- system.file("/home/frederik/apache_bytes.rrd", package = "rrd") + +apache_bytes <- read_rrd("/home/frederik/apache_bytes.rrd") +describe_rrd("/home/frederik/apache_bytes.rrd") + +end_time <- as.POSIXct("2018-08-15") # timestamp with data in example +start_time <- as.POSIXct("2018-04-15") +avg_26350 <- read_rra("/home/frederik/apache_bytes.rrd", cf = "AVERAGE", + #step = 86400, + step = 26350, + #n_steps = 24 * 60, + start = start_time, + end = end_time) + +avg_10 <- read_rra("/home/frederik/apache_bytes.rrd", cf = "AVERAGE", + #step = 86400, + step =1, + n_steps = 120 , + end = end_time) + +names(apache_bytes) +library(ggplot2) +ggplot(avg_10, aes(x = timestamp, y = value)) + + geom_line() + + stat_smooth(method = "loess", span = 0.125, se = FALSE) + + ggtitle("apache bytes, data read from RRD file") + +#devtools::install_github("tidyverts/fable") +library(fable) +library(tsibble) +ts_avg_bytes <- as.tsibble(avg_10, regular = TRUE) + +ts_avg_bytes %>% + fill_na(value = as.integer(median(value))) %>% + ETS(value) %>% + forecast(h=50) %>% + autoplot diff --git a/predictWebsiteHits.R b/predictWebsiteHits.R new file mode 100644 index 0000000..ec74310 --- /dev/null +++ b/predictWebsiteHits.R @@ -0,0 +1,19 @@ +setwd("~/work") +library(jsonlite) +library(fable) +library(tsibble) +library(lubridate) + +logfile <- file("photos.vanrenterghem.biz.access.kvp.log") + +apachelog <- stream_in(logfile) + +#apachelog$time <- gsub("\\[|\\]", "", apachelog$time) +apachelog %>% + mutate(time = gsub("\\[|\\]", "", time), + time = dmy_hms(time)) %>% + group_by(time) %>% + summarise(hits = n()) -> + apachelog + +as.tsibble(apachelog, index = time) -- 2.39.5