

Amazon Timestream for LiveAnalytics に類似した機能をご希望の場合は Amazon Timestream for InfluxDB をご検討ください。リアルタイム分析に適した、シンプルなデータインジェストと 1 桁ミリ秒のクエリ応答時間を特徴としています。詳細については、[こちら](https://docs.aws.amazon.com//timestream/latest/developerguide/timestream-for-influxdb.html)を参照してください。

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# オープンソース Telegraf
<a name="Telegraf"></a>

 Telegraf 用の Timestream for LiveAnalytics 出力プラグインを使用して、オープンソース Telegraf から直接 Timestream for LiveAnalytics にメトリクスを書き込むことができます。

 このセクションでは、Timestream for LiveAnalytics 出力プラグインを使用して Telegraf をインストールする方法、Timestream for LiveAnalytics 出力プラグインを使用して Telegraf を実行する方法、オープンソース Telegraf と Timestream for LiveAnalytics の連携方法について説明します。

**Topics**
+ [Timestream for LiveAnalytics 出力プラグインを使用して Telegraf をインストールする](Telegraf.installing-output-plugin.md)
+ [Timestream for LiveAnalytics 出力プラグインを使用して Telegraf を実行する](Telegraf.running-output-plugin.title.md)
+ [Telegraf/InfluxDB メトリクスを Timestream for LiveAnalytics モデルにマッピングする](Telegraf.how-it-works.md)

# Timestream for LiveAnalytics 出力プラグインを使用して Telegraf をインストールする
<a name="Telegraf.installing-output-plugin"></a>

バージョン 1.16 以降、Timestream for LiveAnalytics 出力プラグインを公式 Telegraf リリースで利用できます。出力プラグインをほとんどの主要なオペレーティングシステムにインストールするには、[InfluxData Telegraf ドキュメント](https://docs.influxdata.com/telegraf/v1.16/introduction/installation/)に記載されている手順に従ってください。Amazon Linux 2 OS にインストールするには、以下の手順に従います。

## Amazon Linux 2 に Timestream for LiveAnalytics 出力プラグインを使用して Telegraf をインストールする
<a name="w2aab7c44c35b9b5"></a>

 Amazon Linux 2 に Timestream 出力プラグインを使用して Telegraf をインストールするには、次の手順を実行します。

1. `yum` パッケージマネージャーを使用して Telegraf をインストールします。

   ```
   cat <<EOF | sudo tee /etc/yum.repos.d/influxdb.repo
   [influxdb]
   name = InfluxDB Repository - RHEL \$releasever
   baseurl = https://repos.influxdata.com/rhel/\$releasever/\$basearch/stable
   enabled = 1
   gpgcheck = 1
   gpgkey = https://repos.influxdata.com/influxdb.key
   EOF
   ```

1. 以下のコマンドを実行してください。

   ```
   sudo sed -i "s/\$releasever/$(rpm -E %{rhel})/g" /etc/yum.repos.d/influxdb.repo
   ```

1. Telegraf をインストールして起動します。

   ```
   sudo yum install telegraf
   sudo service telegraf start
   ```

# Timestream for LiveAnalytics 出力プラグインを使用して Telegraf を実行する
<a name="Telegraf.running-output-plugin.title"></a>

以下の手順に従い、Timestream for LiveAnalytics プラグインを使用して Telegraf を実行できます。

1. Telegraf を使用してサンプル設定を生成します。

   ```
   telegraf --section-filter agent:inputs:outputs --input-filter cpu:mem --output-filter timestream config > example.config
   ```

1. [マネジメントコンソール](console_timestream.md#console_timestream.db.using-console)、[CLI](https://docs.aws.amazon.com/cli/latest/reference/timestream-write/create-database.html)、または [SDK](getting-started-sdks.md) を使用して、Timestream でデータベースを作成します。

1. `example.config` ファイルの `[[outputs.timestream]] ` セクションで次のキーを編集して、データベース名を追加します。

   ```
   database_name = "yourDatabaseNameHere"
   ```

1. デフォルトでは、Telegraf がテーブルを作成します。テーブルを手動で作成する場合は、`create_table_if_not_exists` を `false` に設定し、[マネジメントコンソール](console_timestream.md#console_timestream.table.using-console)、[CLI](https://docs.aws.amazon.com/cli/latest/reference/timestream-write/create-table.html)、または [SDK](getting-started-sdks.md) を使用してテーブルを作成する手順に従います。

1. *example.config* ファイルの `[[outputs.timestream]] ` セクションで、認証情報を設定します。認証情報では、次のオペレーションを許可する必要があります。

   ```
   timestream:DescribeEndpoints
   timestream:WriteRecords
   ```
**注記**  
`create_table_if_not_exists` を `true` に設定されたままにする場合は、以下を含めます。  

   ```
   timestream:CreateTable
   ```
**注記**  
`describe_database_on_start` を `true` に設定する場合は、以下を含めます。  

   ```
   timestream:DescribeDatabase
   ```

1. 設定の残りの部分は、好みに応じて編集できます。

1. 設定ファイルの編集が完了したら、以下を使用して Telegraf を実行します。

   ```
   ./telegraf --config example.config
   ```

1. エージェントの設定に応じて、数秒以内にメトリクスが表示されます。Timestream コンソールに新しいテーブル *cpu* と *mem* も表示されます。

# Telegraf/InfluxDB メトリクスを Timestream for LiveAnalytics モデルにマッピングする
<a name="Telegraf.how-it-works"></a>

 Telegraf から Timestream for LiveAnalytics にデータを書き込む場合、データは次のようにマッピングされます。
+ タイムスタンプは時間フィールドとして書き込まれます。
+ タグはディメンションとして書き込まれます。
+ フィールドはメジャーとして書き込まれます。
+ メジャーメントは主にテーブル名として書き込まれます (詳細は以下を参照)。

Telegraf 用の Timestream for LiveAnalytics 出力プラグインには、データを整理して Timestream for LiveAnalytics に保存するための複数のオプションが用意されています。これは、ラインプロトコル形式のデータで始まる例で説明できます。

`weather,location=us-midwest,season=summer temperature=82,humidity=71 1465839830100400200 airquality,location=us-west no2=5,pm25=16 1465839830100400200`

以下がデータの説明です。
+ メジャーメント名は `weather` と `airquality` です。
+ タグは `location` と `season` です。
+ フィールドは `temperature`、`humidity`、`no2`、および `pm25` です。

**Topics**
+ [複数のテーブルにデータを保存する](#Telegraf.how-it-works.multi-table-single-measure.title)
+ [単一のテーブルにデータを保存する](#Telegraf.how-it-works.single-table-single-measure.title)

## 複数のテーブルにデータを保存する
<a name="Telegraf.how-it-works.multi-table-single-measure.title"></a>

メジャーメントごとに個別のテーブルを作成し、各フィールドを各テーブルの個別の行に保存できます。

設定は `mapping_mode = "multi-table"` です。
+ Timestream for LiveAnalytics アダプターは、`weather` と `airquality` の 2 つのテーブルを作成します。
+ 各テーブル行に 1 つのフィールドのみが含まれます。

結果の Timestream for LiveAnalytics テーブル `weather` と `airquality` は次のようになります。


**`weather`**  

| 時間 | location | season | measure\$1name | measure\$1value::bigint | 
| --- | --- | --- | --- | --- | 
|  2016-06-13 17:43:50  |  us-midwest  |  summer  |  温度  |  82  | 
|  2016-06-13 17:43:50  |  us-midwest  |  summer  |  humidity  |  71  | 


**`airquality`**  

| 時間 | location | measure\$1name | measure\$1value::bigint | 
| --- | --- | --- | --- | 
|  2016-06-13 17:43:50  |  us-midwest  |  no2   |  5  | 
|  2016-06-13 17:43:50  |  us-midwest  |  pm25   |  16  | 

## 単一のテーブルにデータを保存する
<a name="Telegraf.how-it-works.single-table-single-measure.title"></a>

すべてのメジャーメントを単一のテーブルに保存し、各フィールドを個別のテーブル行に保存できます。

設定は `mapping_mode = "single-table"` です。`single-table`、`single_table_name`、および `single_table_dimension_name_for_telegraf_measurement_name` を使用する場合は、2 つの追加設定があります。
+ Timestream for LiveAnalytics 出力プラグインは、*<single\$1table\$1dimension\$1name\$1for\$1telegraf\$1measurement\$1name>* 列を含む *<single\$1table\$1name>* という名前の単一のテーブルを作成します。
+ このテーブルでは、単一のテーブル行に複数のフィールドを含めることができます。

結果の Timestream for LiveAnalytics テーブルは次のようになります。


**`weather`**  

| 時間 | location | season | *<single\$1table\$1dimension\$1name\$1 for\$1telegraf\$1measurement\$1name>* | measure\$1name | measure\$1value::bigint | 
| --- | --- | --- | --- | --- | --- | 
|  2016-06-13 17:43:50  |  us-midwest  |  summer  |  weather  |  温度  |  82  | 
|  2016-06-13 17:43:50  |  us-midwest  |  summer  |  weather  |  humidity  |  71  | 
|  2016-06-13 17:43:50  |  us-midwest  |  summer  |  airquality  |  no2  |  5  | 
|  2016-06-13 17:43:50  |  us-midwest  |  summer  |  weather  |  pm25  |  16  | 