1.2. コンテナからデータを送信する

intdashサーバーに文字列"Hello"を送信するコンテナを新しく追加して、計測する方法を説明します。

習得する内容
  • 計測の仕組み

  • デバイスコネクターサービスの追加方法

計測を行うために必要なサービスが起動される仕組み

Terminal System 2は、アプリケーションの実行にDocker Composeを利用し、計測はDocker Composeのmeasurementプロジェクトとして実行します。

../../_images/about_measurement.png

図 1 Docker Composeにより、計測に必要なサービスを起動

デバイスコネクターは、measurementプロジェクトで使用するオーバーライドファイル(docker-compose.override.yml)の services として記載されています。

その内容を変更する場合は、オーバーライドファイル(docker-compose.override.yml)を直接更新するのではなく、デバイスコネクターサービスファイルを用意し、それをオーバーライドファイルに反映させるという手順をとります。

以降の手順で、新しいデバイスコネクターサービスを追加して計測する方法を説明します。

デバイスコネクターサービスの追加

新しいデバイスコネクターサービス Hello を追加します。

  1. 開発用PCで、以下のコードブロックをコピーして、デバイスコネクターサービスファイル Hello.yml を作成してください。

    image: python:stretch
    entrypoint: python3
    command: >
        -c
        "while True:
            import struct, sys, time;
            f = open('${DC_UPSTREAM_FIFO_0}', 'wb');
            now = int(time.clock_gettime(time.CLOCK_MONOTONIC_RAW) * 1_000_000_000);
            sec = int(now / 1_000_000_000);
            nsec = int(now - sec * 1_000_000_000);
            f.write(struct.pack('<LLHHL6s2s5s', sec, nsec, 6, 2, 5, b'string', b'ab', b'Hello'));
            time.sleep(1);
            f.close();
        "
    depends_on:
        intdash-edge-agent2:
            condition: service_healthy
    volumes:
        - /var/run/core/intdash:/var/run/intdash
    restart: unless-stopped
    substitution_variables:
        - key: DC_UPSTREAM_FIFO_0
          default: ""
          validation: "^/var/run/intdash/"
          display_strings_i18n:
            - locale: jpn
              name: FIFO Path
              description: intdash Edge Agent 2へデータを送信するためのFIFOのパス
    
    • この例では python:stretch イメージを利用します

    • DC_UPSTREAM_FIFO_0 で指定されたFIFOパス(自動生成)に、iscp-v2-compatフォーマットの文字列データ Hello を1秒間隔で書き込みます

    注釈

    デバイスコネクターサービスは、Composeファイルの services 相当の内容を設定可能です。

  2. scpまたはMenderのファイル転送などで、作成したファイルをエッジコンピューターの以下のパスにコピーします。

    /var/lib/core/docker-compose/measurement/services/Hello.yml
    
  3. Mender Web UIにアクセスし、デバイス画面の[Inventory]タブで、 device_connector_services を確認し Hello が追加されていることを確認します。

設定の変更

追加したデバイスコネクターサービス Hello を利用して計測するように、エッジコンピューターの設定を変更します。

  1. 事前に、エッジコンピューターで以下の設定が済んでいることを確認してください。

    • intdashサーバー接続設定

    • アップストリーム設定

  2. デバイスコネクターIPC設定で、 up-hello 設定を追加します。

    Mender Web UIにアクセスし、デバイス画面の[Configuration]タブで、 agent.device_connectors_upstream に以下を設定してください。

    例:

    [
       {
          "id": "device-inventory",
          "data_name_prefix": "v1/255",
          "dest_ids": [
             "default-upstream"
          ],
          "format": "iscp-v2-compat"
       },
       {
          "id": "up-hello",
          "data_name_prefix": "v1/10",
          "dest_ids": [
             "default-upstream"
          ],
          "format": "iscp-v2-compat"
       }
    ]
    
  3. デバイスコネクター設定で、デバイスコネクターサービス Hello を利用する設定に変更します。

    Mender Web UIにアクセスし、デバイス画面の[Configuration]タブで、 device_connectors に以下を設定してください。

    [
       {
          "id": "device-inventory",
          "upstream_ipc_ids": [
             "device-inventory"
          ],
          "downstream_ipc_ids": [],
          "service_id": "Device Inventory",
          "service_substitutions": []
       },
       {
          "id": "hello",
          "upstream_ipc_ids": [
             "up-hello"
          ],
          "downstream_ipc_ids": [],
          "service_id": "Hello",
          "service_substitutions": []
       }
    ]
    
  4. 設定をエッジコンピューターに適用します。

    注釈

    Mender Web UIからデバイスコネクター設定を変更すると、設定したデバイスコネクターサービスの内容に合わせて、計測時に利用するオーバーライドファイル(docker-compose.override.yml)を更新します(次章で説明するコミット操作を自動的に行います)。

  5. 計測を開始し、新しく追加したデバイスコネクターサービスで計測ができることを確認します。

    Mender Web UIの measurement-start リリースをデプロイするか、デバイスにログインして以下のコマンドを実行してください。

    $ curl -X POST http://localhost:8081/api/v3/docker/composes/measurement/start
    
    ../../_images/edge_finder_hello.png

    intdashサーバーに文字列"Hello"を送信するコンテナを新しく追加し、計測することができました。

  6. 動作確認後、計測を停止します。

    Mender Web UIの measurement-stop リリースをデプロイするか、デバイスにログインして以下のコマンドを実行してください。

    $ curl -X POST http://localhost:8081/api/v3/docker/composes/measurement/stop
    

次章では、コンテナを更新する方法を説明します。