diff --git a/tools/monitor/Dockerfile b/tools/monitor/Dockerfile index 11b0610..8fc8190 100644 --- a/tools/monitor/Dockerfile +++ b/tools/monitor/Dockerfile @@ -1,28 +1,23 @@ FROM r-base RUN apt-get update && \ - apt-get install -y libssl-dev libcurl3-dev cron + apt-get install -y libssl-dev libcurl3-dev cron libgdal-dev libgeos-dev libproj-dev libudunits2-dev liblwgeom-dev # install dependencies -RUN Rscript -e 'install.packages("httr")' -RUN Rscript -e 'install.packages("dplyr")' +RUN Rscript -e 'install.packages("sf")' RUN Rscript -e 'install.packages("magrittr")' -#RUN Rscript -e 'install.packages("readr")' - -# install opensensemap package RUN Rscript -e 'install.packages("devtools")' RUN Rscript -e 'devtools::install_github("noerw/opensensmapR")' -COPY docker-entry.sh /docker-entry.sh -RUN chmod 0755 /docker-entry.sh - # install crontab COPY crontab /crontab RUN /usr/bin/crontab /crontab +RUN apt-get clean && apt-get autoremove -y # install script -COPY osem-monitor.R /script/osem-monitor.R -WORKDIR /script/data +COPY get-counts.R /script/get-counts.R +COPY get-boxes.R /script/get-boxes.R -CMD ["/docker-entry.sh"] +WORKDIR /script/data +CMD ["cron", "-f"] diff --git a/tools/monitor/analyze.R b/tools/monitor/analyze.R index 2f1d65f..11b8563 100644 --- a/tools/monitor/analyze.R +++ b/tools/monitor/analyze.R @@ -4,3 +4,6 @@ ts = osem_counts_ts # compute our own measurements per minute, to check against the provided computation ts$measurement_diff = c(diff(ts$measurements), 0) ts$measurement_minute = ts$measurement_diff / c(as.numeric(diff(ts$time), unit = 'mins'), 0) + +plot(measurements~time, ts) +plot(measurements_per_minute~time, ts) diff --git a/tools/monitor/crontab b/tools/monitor/crontab index dd7ed62..5ccb99f 100644 --- a/tools/monitor/crontab +++ b/tools/monitor/crontab @@ -1 +1,8 @@ -*/10 * * * * cd /script/data && /usr/bin/Rscript --save --restore ../osem-monitor.R > rscript.log +#!/bin/sh + +# once every 15 mins +*/15 * * * * cd /script/data && /usr/bin/Rscript --save --restore ../get-counts.R > get-counts.log 2>&1 + +# mondays, 12:02 +#(may not run simultanously, to avoid override of .RData save) +2 12 * * 1 cd /script/data && /usr/bin/Rscript --save --restore ../get-boxes.R > get-boxes.log diff --git a/tools/monitor/docker-entry.sh b/tools/monitor/docker-entry.sh deleted file mode 100644 index c11598a..0000000 --- a/tools/monitor/docker-entry.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -# start cron -cron -f -l 0 - diff --git a/tools/monitor/get-boxes.R b/tools/monitor/get-boxes.R new file mode 100644 index 0000000..d49a9b8 --- /dev/null +++ b/tools/monitor/get-boxes.R @@ -0,0 +1,22 @@ +library(magrittr) +library(opensensmapr) +library(sf) + +if (is.null(as.list(environment())$osem_boxes_ts)) + osem_boxes_ts = data.frame() + +b = osem_boxes() + +# only keep aggregated data +b_agg = data.frame(time = Sys.time(), boxcount = nrow(b)) +b_agg$model = b$model %>% table() %>% as.list() %>% list() +b_agg$exposure = b$exposure %>% table() %>% as.list() %>% list() +b_agg$geometry = b %>% osem_as_sf() %>% st_geometry() %>% list() +b_agg$phenomena = b %>% osem_phenomena() %>% list() + +# combine with existing time series +osem_boxes_ts = rbind(b_agg, osem_boxes_ts) + +# cleanup +rm(b) +rm(b_agg) diff --git a/tools/monitor/osem-monitor.R b/tools/monitor/get-counts.R similarity index 72% rename from tools/monitor/osem-monitor.R rename to tools/monitor/get-counts.R index 513d6b8..faf430d 100644 --- a/tools/monitor/osem-monitor.R +++ b/tools/monitor/get-counts.R @@ -1,6 +1,5 @@ -library(dplyr) library(magrittr) -library(opensensemap) +library(opensensmapr) if (is.null(as.list(environment())$osem_counts_ts)) osem_counts_ts = data.frame() @@ -8,5 +7,4 @@ if (is.null(as.list(environment())$osem_counts_ts)) osem_counts_ts = osem_counts() %>% list(time = Sys.time()) %>% as.data.frame() %>% - dplyr::bind_rows(osem_counts_ts) - + rbind(osem_counts_ts)