エッジについて

はじめに

ABEJA Platform では、モデルハンドラー関数を、クラウド上だけでなく、IoT Device や x86 PC 等、いわゆるエッジ環境で実行させることも可能です。 また、fluent-bit を使う事で、デバイスのメトリクスやログをクラウド上で確認する事ができます。

エッジ機能を利用するには、以下の2つのソフトウェアをデバイスにインストールします。 - abeja-device-agent: クラウド上で行われたデプロイメントをデバイスと同期するプログラムです。 - fluent-bit / fluent-bit-plugin-out-abeja-platform: デバイスのメトリクスとログの収集を行うプログラムです。

インストール

device リソースの作成

ABEJA Platform で、デバイスの登録、および公開鍵の登録を行ってください。以下の API エンドポイントから作成する事ができます。 - デバイスの作成 - 公開鍵の登録

設定には以下の情報が必要となります。 - オーガニゼーションID - デバイスID - 公開鍵ID - 公開鍵に対応する秘密鍵

abeja-device-agent

以下の手順に従ってインストールします。

$ sudo mkdir -p /opt/abeja-device-agent/bin/

## For x86_64 machine
ARCH=amd64
## For arm machine
ARCH=arm64

AGENT_URL=https://abeja-device-resources.s3-ap-northeast-1.amazonaws.com/v2/abeja-device-agent/0.2.1/abeja-device-agent_linux_${ARCH}.tar.gz
$ curl -fsSL ${AGENT_URL} | sudo tar -zx -C /opt/abeja-device-agent/bin/
$ sudo chmod 755 /opt/abeja-device-agent/bin/abeja-device-agent

SYSTEM_CONFIG_URL=https://abeja-device-resources.s3-ap-northeast-1.amazonaws.com/v2/abeja-device-agent/0.2.1/abeja-device-agent.service
$ sudo curl ${SYSTEM_CONFIG_URL} -o /usr/lib/systemd/system/abeja-device-agent.service

$ sudo mkdir -p /etc/abeja-device-agent
$ sudo vim /etc/abeja-device-agent/abeja-device-agent.conf
# Please edit config as below and replace abeja-device resource information

$ sudo systemctl status abeja-device-agent
$ sudo systemctl start abeja-device-agent
$ sudo journalctl -f -u  abeja-device-agent

/etc/abeja-device-agent/abeja-device-agent.conf に以下の設定を追加し、デバイスの情報を設定してください。

organization-id = {organization-id}
device-id = {device-id}
private-key = {device-key}
public-key-id = {public-key-id}

fluent-bit

以下の手順に従ってインストールします。 - fluent-bit installation requirements - fluent-bit download source code - fluent-bit build and install

インストール後、以下のコマンドを実行します。

# setup config files
$ sudo cp -r /usr/local/etc/fluent-bit /etc/

# Modify systemd configuration
$ sudo vim /lib/systemd/system/fluent-bit.service
> etc/fluent-bit/fluent-bit.conf -> /etc/fluent-bit/fluent-bit.conf

# check status and restart
$ sudo systemctl status fluent-bit
$ sudo systemctl start fluent-bit
$ sudo journalctl -f -u fluent-bit
$ sudo systemctl stop fluent-bit

fluent-bit-plugin-out-abeja-platform

以下の手順に従ってインストールします。

# Install plugin
## For x86_64 machine
ARCH=amd64
## For arm machine
ARCH=arm64

PLUGIN_URL=https://abeja-device-resources.s3-ap-northeast-1.amazonaws.com/v2/fluentbit-plugin-out-abeja-platform/0.1.1/out_abejaplatform_linux_${ARCH}.tar.gz
curl -fsSL ${PLUGIN_URL} | sudo tar -zx -C /usr/local/lib/fluent-bit

# Update configs
sudo bash -c 'echo  "    Path /usr/local/lib/fluent-bit/out_abejaplatform.so" >> /etc/fluent-bit/plugins.conf'
sudo vim /etc/fluent-bit/fluent-bit.conf
# Please append config as below and replace abeja-device resource information
# Organization_Id, Device_Id, Credential_Path, Public_Key_Id

$ sudo systemctl start fluent-bit
$ sudo journalctl -f -u fluent-bit

/etc/fluent-bit/fluent-bit.confに以下の設定を追加し、デバイスの情報を設定してください。

################
# For Service
################

# [INPUT]
#     Name        tail
#     Tag         abeja.io.device.metric.service.http*
#     Parser      json
#     Path        /var/abeja-device-agent/logs/services/*/json_access.log
#     DB          /etc/fluent-bit/tail.db
#     Path_Key    filepath

# [INPUT]
#     Name        tail
#     Tag         abeja.io.device.metric.service.http*
#     Parser      apache
#     Path        /var/abeja-device-agent/logs/services/*/access.log
#     DB          /etc/fluent-bit/tail.db
#     Path_Key    filepath


[INPUT]
    Name        tail
    Tag         abeja.io.device.log.service*
    Path        /var/abeja-device-agent/logs/services/*/*
    DB          /etc/fluent-bit/tail.db
    Path_Key    filepath

################
# For device
################

[INPUT]
    Name cpu
    Tag  abeja.io.device.metric.system.cpu

[INPUT]
    Name   mem
    Tag    abeja.io.device.metric.system.memory

[INPUT]
    Name          disk
    Tag           abeja.io.device.metric.system.disk.io
    Interval_Sec  1
    Interval_NSec 0

[INPUT]
    Name          netif
    Tag           abeja.io.device.metric.system.netif
    Interval_Sec  1
    Interval_NSec 0
    Interface     eth0

[INPUT]
    Name        tail
    Tag         abeja.io.device.log.system*
    Path        /var/log/*
    Exclude_Path /var/log/btmp
    DB          /etc/fluent-bit/tail.db
    Path_Key    filepath

##############
# Output
#############

[OUTPUT]
    Name abejaplatform
    Match abeja.io.device.*
    Organization_Id {Organization_Id}
    Device_Id {Device_Id}
    Credential_Path {Credential_Path}
    Public_Key_Id {Public_Key_Id}
    Log_Service_Id_Regexp ^abeja\.io\.device\.log\.service\.var\.abeja-device-agent\.logs\.services\.(?P<serviceId>[^.]+)\..+$
    Access_Log_Service_Id_Regexp ^abeja\.io\.device\.metric\.service\.http\.var\.abeja-device-agent\.logs\.services\.(?P<serviceId>[^.]+)\.[^.]*access[^.]*\.log$