You can call the PutTimeseriesData operation to write multiple rows of time series data to a time series table at the same time.



A row of time series data (timeseriesRow) includes the time series identifier (timeseriesKey) and time series data. The time series data includes data points (fields) and the time (timeInUs) of the data points. The following table describes the parameters.

Parameter Description
timeseriesKey The identifier of the time series, which includes the following content:
  • measurementName: the metric name of the time series.
  • dataSource: the data source of the time series. You can leave this parameter empty.
  • tags: the tags of the time series, which are multiple key-value pairs of the string type.
timeInUs The time of the data point. Unit: microseconds.
fields The data points, which can be multiple pairs of names (FieldKey) and data values (FieldValue).


Write multiple rows of time series data to a time series table named test_timeseries_table.

private static void putTimeseriesData(TimeseriesClient client) {
    List<TimeseriesRow> rows = new ArrayList<TimeseriesRow>();
    for (int i = 0; i < 10; i++) {
        Map<String, String> tags = new HashMap<String, String>();
        tags.put("region", "hangzhou");
        tags.put("os", "Ubuntu16.04");
        // Use measurementName, dataSource, and tags to construct TimeseriesKey. 
        TimeseriesKey timeseriesKey = new TimeseriesKey("cpu", "host_" + i, tags);
        // Specify timeseriesKey and timeInUs to create timeseriesRow. 
        TimeseriesRow row = new TimeseriesRow(timeseriesKey, System.currentTimeMillis() * 1000 + i);
        // Add data values (fields). 
        row.addField("cpu_usage", ColumnValue.fromDouble(10.0));
        row.addField("cpu_sys", ColumnValue.fromDouble(5.0));
    String tableName = "test_timeseries_table";
    PutTimeseriesDataRequest putTimeseriesDataRequest = new PutTimeseriesDataRequest(tableName);
    // Write multiple rows of time series data at the same time. 
    PutTimeseriesDataResponse putTimeseriesDataResponse = client.putTimeseriesData(putTimeseriesDataRequest);
    // Check whether all time series data is written to the time series table. 
    if (!putTimeseriesDataResponse.isAllSuccess()) {
        for (PutTimeseriesDataResponse.FailedRowResult failedRowResult : putTimeseriesDataResponse.getFailedRows()) {