見出し画像

Log Service に Kafka でログを送る

はじめに

Alibaba Cloud Log Service にログを送る方法をまとめ、その中で Kafka をピックアップして紹介します。

ログを送る方法一覧

$$
\begin{array}{|l|l|l|l|l|} \hline
\textbf{方法} & \textbf{概要} & \textbf{使用方法} & \textbf{サポート対象} & \textbf{公式ドキュメント ページ} \\ \hline \hline
\text{Logtail} & \text{Alibaba Cloud 純正のエージェント型ログ収集ミドルウェア} & \text{実行環境へのセットアップ} & \text{Linux, Windows, Docker} & \text{https://www.alibabacloud.com/help/ja/sls/user-guide/use-logtail-to-collect-data} \\ \hline
\text{SDK} & \text{Log Service API をラップした SDK} & \text{プログラム中で SDK を呼ぶ} & \text{Java, C, Python, PHP, .NET, C++, Go, Node.js, JavaScript, iOS, Android} & \text{https://www.alibabacloud.com/help/ja/sls/developer-reference/overview-of-log-service-sdk} \\ \hline
\text{API} & \text{Log Service API} & \text{HTTPS経由で呼び出す} &  \text{ } & \text{https://www.alibabacloud.com/help/ja/sls/developer-reference/api-reference-overview} \\ \hline
\text{Kafka} & \text{Apache Kafkaのストリーム処理ミドルウェア} & \text{実行環境へのセットアップ} & \text{ミドルウェアに準ずる} & \text{https://www.alibabacloud.com/help/ja/sls/user-guide/use-the-kafka-protocol-to-upload-logs} \\ \hline
\text{Logstash} & \text{Elastic Stackのログ収集ミドルウェア} & \text{実行環境へのセットアップ} & \text{ミドルウェアに準ずる} & \text{https://www.alibabacloud.com/help/ja/sls/user-guide/create-logstash-configurations-for-log-collection-and-processing} \\ \hline
\text{Flume} & \text{Apache Flumeのログ収集ミドルウェア} & \text{実行環境へのセットアップ} & \text{ミドルウェアに準ずる} & \text{https://www.alibabacloud.com/help/ja/sls/user-guide/use-flume-to-consume-log-data} \\ \hline
\text{Flink} & \text{Apache Flinkのストリーム処理ミドルウェア} & \text{実行環境へのセットアップ} & \text{ミドルウェアに準ずる} & \text{https://www.alibabacloud.com/help/ja/sls/user-guide/use-flink-to-consume-data} \\ \hline
\text{Syslog} & \text{Unix系OSのログ収集ライブラリ} & \text{実行環境へのセットアップ} & \text{Unix} & \text{https://www.alibabacloud.com/help/ja/sls/user-guide/collect-syslogs} \\ \hline
\text{Alibaba Cloud サービス} & \text{サービス連携がサポートされている} & \text{サービスに準ずる} & \text{ECS, ACK, Function Compute, OSS, NAS, Anti-DDos Pro \& Premium, Security Center, WAF, Cloud Firewall, SLB, VPC, EIP, APIGateway, ApsaraDB for RDS, ApsaraDB for Redis, ApsaraDB for MongoDB, ActionTrail, Message Service, IoT Platform, MaxCompute} & \text{https://www.alibabacloud.com/help/ja/sls/user-guide/alibaba-cloud-service-logs} \\ \hline
\end{array}
$$

Kafka によるログ送信方法

前提条件

  • 送るログはセンサーが記録した気温のテレメトリデータです

  • Kafka Producer は IoT ダッシュボード ThingsBoard の Kafka Node です

    • Kafka については以下をご覧ください

      • https://kafka.apache.org/23/documentation/streams/architecture

    • ThingsBoard については以下をご覧ください

      • https://thingsboard.io/

    • Kafka Node については以下をご覧ください

      • https://thingsboard.io/docs/user-guide/rule-engine-2-0/external-nodes/#kafka-node

  • Kafka Consumer は Log Service Logstore です

    • Log Service Logstore については以下をご覧ください

      • https://www.alibabacloud.com/help/doc-detail/48874.htm

  • Kafka のトピックには Log Service の Logstore 名を使用し、Logstore 名には ThingsBoard の概念である顧客名を使用します

    • 顧客については以下をご覧ください

      • https://thingsboard.io/docs/user-guide/ui/customers/

  • Log Service のプロジェクト名には ThingsBoard の概念であるテナント名を使用します

    • Log Service のプロジェクトについては以下をご覧ください

      • https://www.alibabacloud.com/help/doc-detail/48873.htm

    • テナントについては以下をご覧ください

      • https://thingsboard.io/docs/user-guide/ui/tenants/

  • ThingsBoard には AliyunLogFullAccess の権限を持つ Resource Access Management ユーザーを割り当てています

    • Resource Access Management については以下をご覧ください

      • https://www.alibabacloud.com/product/ram

  • ThingsBoard は Alibaba Cloud Kubernetes 上で起動しています

    • Kubernetes については以下をご覧ください

      • https://www.alibabacloud.com/product/kubernetes

方法

  1. ルールチェーンから Root Rule Chain を選択し、Kafka Node をセットアップします

    • ルールチェーンについては以下をご覧ください

      • https://thingsboard.io/docs/user-guide/rule-engine-2-0/re-getting-started/

  2. Kakfa トピックと Kafka Broker を入力します

    • Kafka トピックには顧客名を取得できる変数 customer_additionalInfo を使用して、Logstore 名をセットします

    • Kafka Broker には Log Service のエンドポイント プロジェクト名.リージョン.log.aliyuncs.com:10011 を入力します

  3. Log Service 固有のプロパティを入力します

    • security.protocol : SASL_SSL

    • sasl.mechanism : PLAIN

    • sasl.jaas.config : org.apache.kafka.common.security.scram.ScramLoginModule required username="プロジェクト名" password="RAMユーザーのアクセスキーID#RAMユーザーのアクセスキー";

    • ssl.endpoint.identification.algorithm : https

  4. Log Service のプロジェクトと Logstore を選択すると、Logstore にテレメトリデータが送られていることが確認できました

tb01
tb01
tb02
tb02
tb03
tb03
tb04
tb04

まとめ

ThingsBoard から簡単に Log Service にログを送ることができました。

この記事が気に入ったらサポートをしてみませんか?