Overview
1 Create Pulse Docker (Thing) Template
2 Whitelist Docker Template as a Gateway Connected Thing
3 Retrieve files via Github & configure Linux DockerMonitor Service
4 Test Docker Monitor
This guide will show you the steps necessary to enable Docker Container Monitoring with Pulse IoT Center v2.0 managed Gateways utilizing a Bash Script on the Gateway. All of the steps indicated below (including installing Docker) could be automated and pushed to Gateways via Pulse Campaign Scripts; however, for the purposes of better understanding the process, manual steps are indicated below.
NOTE: This process is verified on Raspbian and Ubuntu (PhotonOS would most likely require modifications to script/linux service portion). This process assumes that Docker is already installed on your Gateway(s).
Create Pulse Docker (Thing) Template
1A Select Device Templates
1B Click CREATE
2A Enter Template Name : T-DockerContainer
2B Select Device Type : Thing
2C (Optional) +UPLOAD IMAGE
2D Click NEXT
3A Select +Add and create each the following System Properties
- container-name
- image-name
- image-id
- container-status
- container-pid
- ip-address
3B Click NEXT
4A Select +Add and create each of the following Metrics
- Name: CPU-Utilization Value Type: Double
- Name: Container-Runstate Value Type: Boolean
4B Click NEXT
5A Click NEXT
6A Review and Click SAVE
Whitelist (allow) Docker Template as a Gateway Connected Thing
In this step, we will edit the Gateway Template of your choice in order to allow/whitelist our newly created Docker Template
1A Edit the Gateway Device Template (Pulse\Device Templates) by Clicking the Pencil Icon
2A Click NEXT until you are on the Connected Device Templates Step
2B Select +Add (Not Shown)
2C Select the T-DockerContainer template that you created previously and click DONE
3A Click NEXT until you reach the last step of the Wizard then select SAVE
Retrieve files via Github & configure Linux DockerMonitor Service
1 Login to Gateway(s) where DockerMonitor is desired and issue the following commands (note: Git must be installed and github.com accessible via the Gateway. Alternatively, you can download the files via a web browser (link) elsewhere and transport to the Gateway however you choose, e.g. WinSCP, SCP, etc.)
sudo su
cd /tmp
git clone https://github.com/IoT-Ken/dockermonitor.git
2 Next we will create a new directory within /opt, copy our dockermonitor.sh script to this location and then make it executable
mkdir /opt/dockermonitor
cp dockermonitor.sh /opt/dockermonitor
chmod +x /opt/dockermonitor/dockermonitor.sh
3 Let’s copy our Linux Service descriptor file to the proper location, reload Services and set this new Service to start at boot. (If you examine the contents of the dockermonitor.service file, you will note that it is configured to point to the script in the location that we configure previously in Step 2)
cp dockermonitor.service /etc/systemd/system
chmod 644 /etc/systemd/system/dockermonitor.service
systemctl daemon-reload
systemctl enable dockermonitor.service
4 Validate that the ’TEMPLATE’ variable in dockermonitor.sh matches your Docker Template Thing name
nano /opt/dockermonitor/dockermonitor.sh
5 Issue the following command to check that the service is in place (we do not expect the service to be running yet - we’ll start it in a moment - so the ‘inactive (dead)’ response is expected at this time
service dockermonitor status
Test Docker Monitor
1 Let’s spin up some new Docker Containers (type or copy/paste the following Docker commands)
docker run -td --name ubuntu ubuntu
docker run -td --name alpine alpine
docker run --name busybox busybox
2 List out the newly created Containers
docker ps -a
(Note that two of the containers are running and that the busybox container exited - that is because we purposely did not pass in the -td flag at docker run for the busybox container)
3 Start the DockerMonitor service
service dockermonitor start
4 Return to the Pulse Console, select Devices, then drill-down on the Gateway containing your Docker Containers
5 Select Properties and note that we are now tracking whether or not Docker is installed as well as the number of docker-containers that are on this Gateway
6A Select Connected Devices
6B Note that we are visually illustrating the relationship between the Gateway and the Docker Containers
6C Click T-DockerContainer-busybox
7A Click T-DockerContainer-busybox (via the panel that appeared after step 6C)
8A Click Properties and note container-status is in an exited state (this is the container that we ran previously but did not tell Docker to keep running). If we wanted to, we could configure Pulse Alerts to notify of this condition via SMTP or REST API calls.
9A Click Metrics and note that we two Metrics configured for CPU-Utilization and Container-Runstate (Up/Down state in boolean form). We can also configure Pulse Alerts for Metrics. As a reminder, these Metrics were configured in the Docker Template. The dockermonitor.sh script that we configured previously is sending these Metrics from the gateway every 15 seconds (Note that it can take a few minutes for these Metrics to start populating)
Thank you - this concludes our DockerMonitor Lesson.
comments powered by Disqus