I would suggest monitoring the R process itself, then you can log plumber input by writing to R console.
This is what we use internally (we deploy using docker with kubernetes). Log are redirected to stackdriver on GCP.
Docker file
FROM rstudio/r-base:4.1.0-focal
WORKDIR /src
RUN apt-get update && apt-get install -y --no-install-recommends \
gdal-bin \
git \
libcurl4-openssl-dev \
libgdal-dev \
libgeos-dev \
libicu-dev \
libproj-dev \
libsodium-dev \
libssl-dev \
libudunits2-dev \
make \
zlib1g-dev
RUN echo 'options(repos = c(REPO_NAME = "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"))' >> ~/.Rprofile
RUN Rscript -e "install.packages(c('curl','data.table','generics','globals','googleCloudStorageR','parsnip','remotes','sf','tidyr','yaml','future','hms','plumber', 'xml2'))"
COPY ./api/startup.R /etc
COPY ./api/plumber.R .
# Compile xgboost without OPENMP supports to avoid nthreads problems
RUN apt-get -qq -y install cmake
RUN git clone --recursive https://github.com/dmlc/xgboost
WORKDIR /src/xgboost
RUN git submodule init
RUN git submodule update
RUN mkdir build
WORKDIR /src/xgboost/build
RUN cmake .. -DR_LIB=ON -DUSE_OPENMP=OFF
RUN make -j$(nproc)
RUN make install
WORKDIR /src
EXPOSE 8004
ENTRYPOINT ["R", "-f", "/etc/startup.R", "--slave"]
api/plumber.R
#* Health check
#* @get /
#* @serializer unboxedJSON
function() {
list(status = "OK")
}
api/startup.R (logging happen here)
library(plumber)
pr <- plumb()
postroute = function(req) {
if (req$REQUEST_METHOD == "POST") {
cat("[", req$REQUEST_METHOD, req$PATH_INFO, "] - REQUEST - ", req$postBody, "\n", sep = "")
}
}
postserializewithoutpayload <- function(req, res) {
if (req$REQUEST_METHOD == "POST") {
cat("[", req$REQUEST_METHOD, req$PATH_INFO, "] - RESPONSE - ", res$status, "\n", sep = "")
}
}
postserializewithpayload <- function(req, res) {
if (req$REQUEST_METHOD == "POST") {
cat("[", req$REQUEST_METHOD, req$PATH_INFO, "] - RESPONSE - ", res$status, " - BODY - ", res$body, "\n", sep = "")
}
}
hooklist <- list(postserialize = postserializewithoutpayload)
debughooklist <- list(postserialize = postserializewithpayload, postroute = postroute)
if (Sys.getenv("DBG_ENABLE", FALSE) == TRUE) {
pr$setDebug(TRUE)
pr$registerHooks(debughooklist)
} else {
pr$registerHooks(hooklist)
}
pr$run(host = "0.0.0.0", port = 8004)
There are of course other ways to achieve a similar result. Let me know if that gives you enough to get started.