add monitor docker container
parent
6bd59a71c4
commit
e60776a499
@ -0,0 +1,28 @@
|
|||||||
|
FROM r-base
|
||||||
|
|
||||||
|
RUN apt-get update && \
|
||||||
|
apt-get install -y libssl-dev libcurl3-dev cron
|
||||||
|
|
||||||
|
# install dependencies
|
||||||
|
RUN Rscript -e 'install.packages("httr")'
|
||||||
|
RUN Rscript -e 'install.packages("dplyr")'
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
# install script
|
||||||
|
COPY osem-monitor.R /script/osem-monitor.R
|
||||||
|
WORKDIR /script/data
|
||||||
|
|
||||||
|
CMD ["/docker-entry.sh"]
|
@ -0,0 +1,25 @@
|
|||||||
|
# osem-monitor
|
||||||
|
|
||||||
|
Get the state of sensors and measurement counts for later analysis every 10 minutes.
|
||||||
|
The dataframe will reside in `./data/.RData`.
|
||||||
|
|
||||||
|
Further analysis can be done with the script `analyze.R`.
|
||||||
|
|
||||||
|
## docker image
|
||||||
|
```bash
|
||||||
|
# build
|
||||||
|
docker build --tag osem-monitor .
|
||||||
|
|
||||||
|
# run
|
||||||
|
docker run -v $(pwd)/data:/script/data osem-monitor
|
||||||
|
```
|
||||||
|
|
||||||
|
## run manually
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# install dependencies once
|
||||||
|
Rscript -e 'install.packages(c("dplyr", "magrittr", "devtools"))'
|
||||||
|
Rscript -e 'devtools::install_github("noerw/opensensmapR")'
|
||||||
|
|
||||||
|
Rscript --save --restore osem-monitor.R
|
||||||
|
```
|
@ -0,0 +1,6 @@
|
|||||||
|
# create a working copy, so we cant accidentally loose all data
|
||||||
|
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)
|
@ -0,0 +1 @@
|
|||||||
|
*/10 * * * * cd /script/data && /usr/bin/Rscript --save --restore ../osem-monitor.R > rscript.log
|
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# start cron
|
||||||
|
cron -f -l 0
|
||||||
|
|
@ -0,0 +1,12 @@
|
|||||||
|
library(dplyr)
|
||||||
|
library(magrittr)
|
||||||
|
library(opensensemap)
|
||||||
|
|
||||||
|
if (is.null(as.list(environment())$osem_counts_ts))
|
||||||
|
osem_counts_ts = data.frame()
|
||||||
|
|
||||||
|
osem_counts_ts = osem_counts() %>%
|
||||||
|
list(time = Sys.time()) %>%
|
||||||
|
as.data.frame() %>%
|
||||||
|
dplyr::bind_rows(osem_counts_ts)
|
||||||
|
|
Loading…
Reference in New Issue