Machine Learning on LE via Jupyter
11 min
overview this solution describes how to run a machine learning application using jupyter on litmus edge after deploying the container, you will be able to log in to a jupyter notebook environment running on your litmusedge device and use the bundled example notebooks for classification, anomaly detection, and prediction prerequisites a running litmus edge instance with administrative access the jupyter ml toolkit image ( tar gz ) provided by litmus network access to the litmus edge ip from the machine you will browse from ssh access to the litmus edge host (used once to retrieve the jupyter login token) step 1 download and prepare the image obtain the jupyter ml toolkit tar gz file from the litmus repository or release artifact provided to you step 2 upload the image to litmus edge log in to your litmus edge instance navigate to applications > images upload the tar gz file downloaded in step 1 wait for the upload to complete and confirm that the image appears in the list of available images step 3 configure and run the container navigate to applications > containers create a new container using the image uploaded in step 2 use the following docker run command docker run p 8888 8888 \\ v /var/lib/loopedge/analytics2/models/ /home/loopedge/work/notes/savedmodels \ \<imgname> \<tagname> this command exposes the jupyter application on port 8888 mounts the litmusedge analytics models folder into the container at /home/loopedge/work/notes/savedmodels , so any models saved from a notebook are immediately available to the analytics engine tip if you want to skip the token lookup in step 5, you can pre set a token now by adding e jupyter token=\<your chosen token> to the command above step 4 open the jupyter application in a browser in a new browser tab, navigate to your litmus edge ip address followed by port 8888 http //\<le ip> 8888 for example, if your litmus edge instance is at 10 17 10 27 , open http //10 17 10 27 8888 you will be redirected to the jupyter login page, which prompts for a password or token step 5 log in to jupyter 5 1 retrieve the access token the jupyter container generates a one time token at startup to retrieve it ssh into the litmus edge host find the running jupyter container docker ps | grep jupyter read the token from the container logs docker logs \<container name> 2>&1 | grep oe 'token=\[a f0 9]+' | head 1 you will see output similar to token=8968cc8cf0480ed3b2b52c25fed0eb527f7ea2fc888b4ea copy the value after token= if you set jupyter token in the docker run command in step 3, skip the lookup above and use the value you set 5 2 log in using one of two options option a log in with the token (one time) paste the token into the password or token field at the top of the login page and click log in option b set a permanent password (recommended) on the same login page, scroll down to the setup a password section paste the token into the token field enter your chosen password in the new password field click log in and set new password you will be logged in and the password will be saved for future sessions, so you no longer need to look up the token note the login page contains links labeled "enable a password" and "the documentation on how to enable a password" these links point to legacy jupyter documentation that has been removed and will return a 404 use the setup a password form on the same page (option b above) instead step 6 use the bundled notebooks once logged in, you will see the jupyter file browser the following example notebooks are included under /home/loopedge/work/notes/ natsconnection ipynb example of connecting to the litmusedge nats broker influxconnection ipynb example of querying influxdb on litmusedge classification ipynb example classification model anomaly ipynb example anomaly detection model prediction ipynb example prediction model template prediction ipynb template you can copy as a starting point for new prediction models models saved into /home/loopedge/work/notes/savedmodels from any notebook will appear automatically in the litmusedge analytics engine, thanks to the volume mount configured in step 3 troubleshooting the "enable a password" or "the documentation on how to enable a password" links on the jupyter login page return a 404 this is a known issue with the upstream jupyter login template, which references documentation urls that have since moved use the setup a password form on the same login page (see step 5 2, option b) to set a password without needing the linked documentation docker logs does not show a token the container may have been started with jupyter token set to an empty value, or with token authentication disabled restart the container without overriding jupyter token , or set it explicitly using e jupyter token=\<your chosen token> in the docker run command from step 3 browser cannot reach \<le ip> 8888 verify that port 8888 is published in the container configuration in step 3, that the litmusedge firewall allows inbound traffic on 8888 , and that your browser machine has network access to the litmusedge ip