In this tutorial, you will learn how to monitor the availability of Edge containers and perform automatic restarts when the node goes down.
We will use the curl command inside the Edge container to perform a prediction request to verify that the node is working properly. This is what the bash script looks like. You need to replace <test-image-in-base64>
with your image data encoding in Base64. Do not forget to assign this file executable permission in the end.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
#!/bin/bash rm -rf /tmp/edge-check* img_base64="<test-image-in-base64>" payload=$( cat <<EOF { "instances":[ { "image_bytes":{ "b64":"img-b64-str" }, "key":"00-00-00" } ] } EOF ) timestamp=$(date +%s) payload=$(echo "$payload" | sed "s@img-b64-str@$img_base64@") payload=$(echo "$payload" | sed "s@00-00-00@$timestamp@") tmpfile=$(mktemp /tmp/edge-check.XXXXXXX) echo "$payload" >> ${tmpfile} [[ $(curl -L -X POST -d "@$tmpfile" http://127.0.0.1:8501/v1/models/default:predict -o /dev/null -w '%{http_code}\n' -s) == '200' ]] && rm -f ${tmpfile} && echo 0 |
The Edge container does not have the curl installed by default. So we create a Dockfile to do that. We run apt-get update
with exit 0
to discard any errors of keys.
1 2 3 4 5 6 |
FROM gcr.io/cloud-devrel-public-resources/gcloud-container-1.14.0-gpu:latest USER root COPY check.sh /check.sh RUN apt-get update; exit 0 RUN apt-get install curl wget -y |
Next, we are going to build the docker-compose file, in which using willfarrell/autoheal to restart the potential unhealthy Edge container.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
version: '3.5' services: main: build: context: ./ volumes: - type: bind source: ./ target: /tmp/mounted_model/0001 tty: true runtime: nvidia network_mode: "bridge" ports: - "8501:8501" healthcheck: test: [ "CMD", "/check.sh" ] interval: 30s timeout: 5s retries: 2 start_period: 20s restart: unless-stopped labels: "autoheal": "true" autoheal: image: willfarrell/autoheal volumes: - '/var/run/docker.sock:/var/run/docker.sock' |
Then, we create a .dockerignore
file to ignore exported weight files.
1 |
*.pb |
This is the structure overview of the working directory. The .gitignore
has the same content as the .dockerignore
to prevent uploading weight files to the git repository. Your weight files saved_model.pb
should be in the same directory.
1 2 3 4 5 6 7 |
. ├── check.sh ├── docker-compose.yml ├── Dockerfile ├── .dockerignore ├── .gitignore └── saved_model.pb |
Finally, you can run docker-compose up
command to start the predicting service as well as the monitoring service. To view the status of Edge container, use docker ps
command.
1 2 3 |
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1976c289b514 edge_main "/bin/sh -c '/usr/bi…" About a minute ago Up About a minute (healthy) 8500/tcp, 0.0.0.0:8501->8501/tcp, :::8501->8501/tcp edge_main_1 e2bd2e0eab0a willfarrell/autoheal "/docker-entrypoint …" About a minute ago Up About a minute (healthy) edge_autoheal_1 |