]> git.vanrenterghem.biz Git - R/project-using-kafka-in-R.git/commitdiff
Initiate project.
authorFrederik Vanrenterghem <frederik@vanrenterghem.io>
Thu, 23 Aug 2018 11:28:47 +0000 (19:28 +0800)
committerFrederik Vanrenterghem <frederik@vanrenterghem.io>
Thu, 23 Aug 2018 11:28:47 +0000 (19:28 +0800)
.gitignore [new file with mode: 0644]
collectd.R [new file with mode: 0644]
predictWebsiteHits.R [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..8fce603
--- /dev/null
@@ -0,0 +1 @@
+data/
diff --git a/collectd.R b/collectd.R
new file mode 100644 (file)
index 0000000..9fd157b
--- /dev/null
@@ -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 (file)
index 0000000..ec74310
--- /dev/null
@@ -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)