

# Retrieve a profile time series

The `SelectSeries` operation returns the total value of a profile type for each time step in a range. You can group the result by labels, for example, to get one series for each host. Use a time series to find when resource usage changed, and then retrieve a flame graph for that period. For more information about profile types and labels, see [Profile type IDs and labels](CloudWatch-Profiles-overview.md#CloudWatch-Profiles-overview-labels).

You can view a profile time series in the CloudWatch console or retrieve it with the query API. This topic describes the console first, and then the API.

## Prerequisites
<a name="CloudWatch-Profiles-query-timeseries-prereqs"></a>

Before you begin, make sure that you have the following:
+ An identity with the `cloudwatch:GetProfileRecords` permission. For more information, see [IAM permissions required](CloudWatch-Profiles-query.md#CloudWatch-Profiles-query-iam). You need this permission to view profiles in the CloudWatch console and to call the query API.
+ The profile type ID and the labels to query. For instructions, see [Discover profile types, services, and labels](CloudWatch-Profiles-query-discover.md).

## View a profile time series in the CloudWatch console
<a name="CloudWatch-Profiles-query-timeseries-console"></a>

In the CloudWatch console, the results show a time series chart of the profile value over the selected time range, together with the flame graph.

**To view a profile time series in the CloudWatch console**

1. Open the CloudWatch console at [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/).

1. In the navigation pane, choose **Profiles**.

1. In the navigation bar at the top, select the Region where you send your profile data.

1. For **Service**, select the service name that your application reports in `service.name`, for example, `example-java-service`.

1. For **Profile type**, select the profile type that your profiler sends, for example, `process_cpu`.

1. At the top of the page, choose the time range that you want to analyze, for example, **1h**.

1. Choose **Run**.

The chart title shows the unit of the profile type, for example, CPU cores. The chart legend shows the name of the profile type.

To get one series for each value of a label, such as one series for each host, use the `groupBy` field of the `SelectSeries` API operation. For an example, see [Example: CPU time for each host of a service](#CloudWatch-Profiles-query-timeseries-host).

## Time series examples
<a name="CloudWatch-Profiles-query-timeseries-requests"></a>

To retrieve a profile time series with the API, send a `SelectSeries` request. The following examples show common requests and a response.

A `SelectSeries` request requires `step`, in seconds. The time range can't be longer than 24 hours. CloudWatch raises a smaller `step` to the minimum resolution for the time range: 300 seconds for windows of 1 hour or less, and 900 seconds for longer windows. For all request fields, see [SelectSeries](CloudWatch-Profiles-query-api-reference.md#CloudWatch-Profiles-query-api-selectseries) in the query API reference.

**Note**  
Always include `profileTypeID`. If you omit it, CloudWatch adds together the values of every profile type that matches the label selector, even types with different units such as nanoseconds and counts. To see each type separately, group by `__profile_type__`.

**Example: CPU time for each host of a service**  <a name="CloudWatch-Profiles-query-timeseries-host"></a>
This request returns the CPU time of `example-java-service` in 10-minute steps, with one series for each host.  

```bash
curl --request POST \
  --aws-sigv4 "aws:amz:us-east-1:monitoring" \
  --user "$AWS_ACCESS_KEY_ID:$AWS_SECRET_ACCESS_KEY" \
  --header "x-amz-security-token: $AWS_SESSION_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
    "profileTypeID": "process_cpu:cpu:nanoseconds:cpu:nanoseconds",
    "labelSelector": "{service_name=\"example-java-service\"}",
    "step": 600,
    "groupBy": ["@resource.host.name"],
    "start": 1793793600000,
    "end":   1793797200000
  }' \
  https://monitoring.us-east-1.amazonaws.com/querier.v1.QuerierService/SelectSeries
```
Example response (trimmed):  

```json
{
  "series": [
    {
      "labels": [{"name": "@resource.host.name", "value": "host-a.example.internal"}],
      "points": [
        {"value": 1461305600.0, "timestamp": "1793796000000"},
        {"value": 7860000000.0, "timestamp": "1793796600000"}
      ]
    },
    {
      "labels": [{"name": "@resource.host.name", "value": "host-b.example.internal"}],
      "points": [...]
    }
  ]
}
```
Each point has a value in the unit of the profile type and a timestamp in milliseconds, returned as a string. Without `groupBy`, the response contains one series with no `labels`.

**Example: average CPU time, limited to one series**  <a name="CloudWatch-Profiles-query-timeseries-average"></a>
This request body averages the values in each step instead of adding them, and `limit` restricts the response to one series.  

```json
{
  "profileTypeID": "process_cpu:cpu:nanoseconds:cpu:nanoseconds",
  "labelSelector": "{service_name=\"example-java-service\"}",
  "step": 600,
  "groupBy": ["@resource.host.name"],
  "limit": 1,
  "aggregation": "TIME_SERIES_AGGREGATION_TYPE_AVERAGE",
  "start": 1793793600000,
  "end":   1793797200000
}
```

**Example: one series for each profile type**  <a name="CloudWatch-Profiles-query-timeseries-types"></a>
This request body omits `profileTypeID` and groups by `__profile_type__`, so the response contains a separate series for each profile type in the account.  

```json
{
  "labelSelector": "{}",
  "step": 900,
  "groupBy": ["__profile_type__"],
  "start": 1793793600000,
  "end":   1793797200000
}
```