すべてのプロダクト
Search
ドキュメントセンター

Tablestore:時系列データの書き込み

最終更新日:Sep 30, 2026

PutTimeseriesData API を呼び出して、複数行の時系列データを時系列テーブルに同時に書き込めます。

前提条件

パラメーター

時系列データの各行 (timeseriesRow) は、時系列識別子 (timeseriesKey) とデータ自体で構成されます。 データには、タイムスタンプ (timeInUs) と 1 つ以上のフィールド値 (fields) が含まれます。

timeseriesKey は、メトリックタイプ (例えば CPU や NETWORK など)、データソースホスト、およびキーと値のラベルを識別します。 fields は、各データポイントの測定値を保持します。

パラメーター

必須

説明

timeseriesKey

はい

時系列識別子。以下の情報が含まれます。

  • measurementName: 時系列の測定名。

  • dataSource: データソース。空にすることができます。

  • tags: 時系列のタグ。文字列のキーと値のペアとして表されます。

timeInUs

はい

データポイントのタイムスタンプ (マイクロ秒単位) 。

fields

はい

データポイント。1 つ以上の FieldKey–FieldValue ペア。

例

次の例では、PutTimeseriesData を使用して、CPU メトリクス用とネットワークメトリクス用の 2 行の時系列データを時系列テーブルに書き込みます。

timeseriesKeyは、関連するデータポイントをグループ化する ID を定義します。timeseriesRowは、その ID にタイムスタンプとフィールド値を関連付けます。

func PutTimeseriesDataSample(client *tablestore.TimeseriesClient , timeseriesTableName string) {
    fmt.Println("[Info]: Begin to PutTimeseriesDataSample !")

    // 時系列行 timeseriesRow を構築します。
    // timeseriesKey は、時系列 (メジャーメント名、ソースホスト、タグ) を識別します。
    timeseriesKey := tablestore.NewTimeseriesKey()
    timeseriesKey.SetMeasurementName("CPU")
    timeseriesKey.SetDataSource("127.0.0.1")
    timeseriesKey.AddTag("City" , "Hangzhou")
    timeseriesKey.AddTag("Region" , "Xihu")

    // timeseriesRow は、キーにタイムスタンプとフィールド値を付加します。
    timeseriesRow := tablestore.NewTimeseriesRow(timeseriesKey)
    timeseriesRow.SetTimeInus(time.Now().UnixNano() / 1000)
    timeseriesRow.AddField("temperature" , tablestore.NewColumnValue(tablestore.ColumnType_INTEGER , 98))
    timeseriesRow.AddField("status" , tablestore.NewColumnValue(tablestore.ColumnType_STRING , "ok"))

    // 時系列行 timeseriesRow1 を構築します。
    timeseriesKey1 := tablestore.NewTimeseriesKey()
    timeseriesKey1.SetMeasurementName("NETWORK")
    timeseriesKey1.SetDataSource("127.0.0.1")
    timeseriesKey1.AddTag("City" , "Hangzhou")
    timeseriesKey1.AddTag("Region" , "Xihu")

    timeseriesRow1 := tablestore.NewTimeseriesRow(timeseriesKey1)
    timeseriesRow1.SetTimeInus(time.Now().UnixNano() / 1000)
    timeseriesRow1.AddField("in" , tablestore.NewColumnValue(tablestore.ColumnType_INTEGER , 1000))
    timeseriesRow1.AddField("data" , tablestore.NewColumnValue(tablestore.ColumnType_BINARY , []byte("tablestore")))
    timeseriesRow1.AddField("program" , tablestore.NewColumnValue(tablestore.ColumnType_STRING , "tablestore.d"))
    timeseriesRow1.AddField("status" , tablestore.NewColumnValue(tablestore.ColumnType_BOOLEAN, true))
    timeseriesRow1.AddField("lossrate" , tablestore.NewColumnValue(tablestore.ColumnType_DOUBLE , float64(1.9098)))

    // 時系列データを書き込むリクエストを構築します。
    putTimeseriesDataRequest := tablestore.NewPutTimeseriesDataRequest(timeseriesTableName)
    putTimeseriesDataRequest.AddTimeseriesRows(timeseriesRow , timeseriesRow1)

    // 時系列クライアントを呼び出して時系列データを書き込みます。
    putTimeseriesDataResponse , err := client.PutTimeseriesData(putTimeseriesDataRequest)
    if err != nil {
        fmt.Println("[Error]: Failed to put time series data. Error: " , err)
        return
    }

    // バッチ書き込みは部分的に成功する場合があります。失敗した行は、インデックスと
    // エラーメッセージと共に返され、正常に書き込まれた行は即座にコミットされます。
    if len(putTimeseriesDataResponse.GetFailedRowResults()) > 0 {
        fmt.Println("[Warning]: Put time series data finished. Some rows failed to be written: ")
        for i := 0; i < len(putTimeseriesDataResponse.GetFailedRowResults()); i++ {
            FailedRow := putTimeseriesDataResponse.GetFailedRowResults()[i]
            fmt.Println("[Warning]: Failed Row: Index: " , FailedRow.Index , " Error: " , FailedRow.Error)
        }
    } else {
        fmt.Println("[Info]: PutTimeseriesDataSample finished. RequestId: " , putTimeseriesDataResponse.RequestId)
    }
}

よくある質問

関連ドキュメント

  • API オペレーションの詳細については、「PutTimeseriesData」をご参照ください。

  • データを書き込んだ後、時系列テーブルからデータをクエリすることができます。詳細については、「時系列データのクエリ」をご参照ください。

  • 特定の条件を満たす時系列を取得するには、「時系列の取得」をご参照ください。

  • 時系列メタデータを更新または削除するには、「時系列の更新」および「時系列の削除」をご参照ください。

  • Kafka データソースから Tablestore 時系列テーブルにデータを移行するには、Tablestore Sink Connector を使用します。詳細については、「Kafka データの時系列テーブルへの同期」をご参照ください。