Skip to content
Snippets Groups Projects
Commit 9de9401a authored by Jan David Mol's avatar Jan David Mol
Browse files

Reroute Jupyter Notebook logs to ELK

parent a31b4e7f
Branches
Tags
1 merge request!7Resolve #2021 "03 16 branched from master elk stack"
...@@ -33,5 +33,5 @@ services: ...@@ -33,5 +33,5 @@ services:
- --timeout=30 - --timeout=30
- --strict - --strict
- -- - --
- /usr/bin/tini -- jupyter notebook --port=8888 --no-browser --ip=0.0.0.0 --allow-root --NotebookApp.token= --NotebookApp.password= - /usr/bin/tini -- /usr/local/bin/jupyter-notebook --port=8888 --no-browser --ip=0.0.0.0 --allow-root --NotebookApp.token= --NotebookApp.password=
restart: on-failure restart: on-failure
ARG VERSION=latest ARG VERSION=latest
FROM nexus.engageska-portugal.pt/ska-docker/tango-itango:${VERSION} FROM nexus.engageska-portugal.pt/ska-docker/tango-itango:${VERSION}
RUN pip3 install jupyter RUN sudo pip3 install jupyter
RUN pip3 install ipykernel RUN sudo pip3 install ipykernel
RUN pip3 install jupyter_bokeh RUN sudo pip3 install jupyter_bokeh
# Configure jupyter_bokeh # Configure jupyter_bokeh
RUN sudo mkdir -p /usr/share/jupyter /usr/etc RUN sudo mkdir -p /usr/share/jupyter /usr/etc
...@@ -16,6 +16,10 @@ COPY ipython-profiles /opt/ipython-profiles/ ...@@ -16,6 +16,10 @@ COPY ipython-profiles /opt/ipython-profiles/
RUN sudo chown tango.tango -R /opt/ipython-profiles RUN sudo chown tango.tango -R /opt/ipython-profiles
COPY jupyter-kernels /usr/local/share/jupyter/kernels/ COPY jupyter-kernels /usr/local/share/jupyter/kernels/
# Install patched jupyter executable
RUN sudo pip3 install python-logstash-async
COPY jupyter-notebook /usr/local/bin/jupyter-notebook
# Add Tini. Tini operates as a process subreaper for jupyter. This prevents kernel crashes. # Add Tini. Tini operates as a process subreaper for jupyter. This prevents kernel crashes.
ENV TINI_VERSION v0.6.0 ENV TINI_VERSION v0.6.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /usr/bin/tini ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /usr/bin/tini
......
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# An adjustment of the `jupyter-notebook' executable patched to:
# - log to the ELK stack
#
# We go straight for the notebook executable here, as the "jupyter" command
# execvp's into the requested notebook subcommand, erasing all configuration
# we set here.
import re
import sys
from notebook.notebookapp import main
from logstash_async.handler import AsynchronousLogstashHandler, LogstashFormatter
import logging
if __name__ == '__main__':
# log to the tcp_input of logstash in our ELK stack
handler = AsynchronousLogstashHandler("elk", 5959, database_path='/tmp/pending_log_messages.db')
# add to logger of Jupyter traitlets Application. As that logger is configured not to propagate
# messages upward, we need to configure it directly.
logger = logging.getLogger("NotebookApp")
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment