A strong advantage of the Torizon platform is the possibility to work with microservices architecture. This software development technique provides great advantages such as modularity, scalability, integration, and distributed development. TorizonCore is the base operating system in which Torizon is built and provides Docker for microservices implementation using containers.
In this article we will show an example implementation using Grafana, Collectd, and InfluxDB to show how to orchestrate multiple containers and manage the inter-communication process.
This article complies to the Typographic Conventions for Torizon Documentation.
Although the same rules apply for Docker Compose, this example will not use Toradex's Visual Studio Plugin. For an example of Multi-Container application using the Toradex's Visual Studio plugin, see C / C++ Developer Workflow on Windows
Compose is a tool for defining and running multi-container Docker applications. Compose uses a YAML file to configure the application’s services. With the Compose file, in a single command, you create and start all the services from your configuration.
When executing a system with multiple containers, some methods can be applied for communication and message passing between containers. Some of these methods are files/directories sharing and IP sockets. In this example we will show communication through IP sockets (The communication will be done through HTTP requests).
By default, Docker Compose sets up a single network for your app. Each container for a service joins the default network and is both reachable by other containers on that network, and discoverable by them at a hostname identical to the container name. For more information, please, refer to Networking in Compose page.
In this example, we will show a multi-container application that displays the performance data of a Toradex's Computer-on-Module (CoM) using the following open-source software: Grafana, Collectd, and InfluxDB.
Grafana is a data query and presenting tool, which lets us build a graph chart based on InfluxDB. InfluxDB is our time-series database. Grafana sends a query to InfluxDB (port 8086) by an HTTP request.
Collectd is a Unix daemon that collects, transfers and stores performance data of computers and network equipment and sends it to InfluxDB.
In summary, Collectd will produce data and store it in the database (controlled by InfluxDB). Grafana will consume the data in the database and display it. In this example, we want to have 1 Docker container for each of the components - Grafana, Collectd, and InfluxDB. Hence, our application contains 3 containers and a single YAML (.yml) file.
First, obtain the files of this example. To do that, clone the repository to your PC:
$ git clone https://github.com/toradex/torizon-samples
Copy grafana directory from your PC to your module using
X.X.X.X by your module’s IP-address):
$ scp -r ./torizon-samples/grafana/ torizon@X.X.X.X:/home/torizon/
Connect to your module's shell by using SSH:
In your module's terminal, change the current directory to the ”grafana” directory:
# cd /home/torizon/grafana
version: '2.4' services: grafana: container_name: grafana networks: - backend - frontend volumes: - 'grafana-storage:/var/lib/grafana' ports: - '3000:3000' image: grafana/grafana influxdb: container_name: influxdb networks: - backend volumes: - '$PWD/influxdb.conf:/etc/influxdb/influxdb.conf:ro' - '$PWD/types.db:/usr/share/collectd/types.db:ro' - 'influxdb-grafana:/var/lib/influxdb' image: influxdb collectd:Multiple Docker Containers build: . container_name: collectd networks: - backend volumes: - '$PWD/collectd.conf:/etc/collectd/collectd.conf' networks: backend: internal: true frontend: internal: false volumes: grafana-storage: influxdb-grafana:
To execute the application defined by the YAML file, just use the following command:
Note: The option
--detach runs the containers in the background in detached mode.
# docker-compose up -d
To show the data in the video output, add the following content to the docker-compose.yml file:
Note: For Apalis-iMX8 use torizon/arm64v8-debian-weston-vivante:latest image.
weston: environment: - ACCEPT_FSL_EULA=1 container_name: weston image: torizon/arm32v7-debian-weston:latest # For Apalis iMX8 use this image # image: torizon/arm64v8-debian-weston-vivante:latest # Required to get udev events from host udevd via netlink network_mode: host volumes: - type: bind source: /tmp target: /tmp - type: bind source: /dev target: /dev - type: bind source: /run/udev target: /run/udev cap_add: - CAP_SYS_TTY_CONFIG # Add device access rights through cgroup... device_cgroup_rules: # ... for tty0 - 'c 4:0 rmw' # ... for tty7 - 'c 4:7 rmw' # ... for /dev/input devices - 'c 13:* rmw' - 'c 199:* rmw' # ... for /dev/dri devices - 'c 226:* rmw' kiosk: container_name: kiosk image: torizon/arm32v7-debian-kiosk-mode-browser:latest command: --window-mode http://grafana:3000 networks: - frontend volumes: - type: bind source: /tmp target: /tmp - type: bind source: /var/run/dbus target: /var/run/dbus - type: bind source: /dev/dri target: /dev/dri depends_on: - weston - grafana - influxdb shm_size: '256mb' device_cgroup_rules: # ... for /dev/dri devices - 'c 226:* rmw'
Open a browser on your computer, on the same network as the board, and access the board IP address on port 3000
http://X.X.X.X:3000/ and log in with default (
Note: If you are using the optional local ui the Grafana login page will open automatically on a screen attached on the device board.
Click Add data source:
select InfluxDB as a data source type
set URL to http://influxdb:8086 (we use docker link, so we can access it by container name)
write the name of your database (“collectd“ in our case)
Create a new Dashboard: