

# Discover profile types, services, and labels

Before you retrieve a flame graph or a time series, you need a profile type ID and a label selector. The discovery operations return the profile types, label names, and label values in your account for a time range. For more information about profile type IDs and labels, see [Profile type IDs and labels](CloudWatch-Profiles-overview.md#CloudWatch-Profiles-overview-labels).

You can discover your profile data in the CloudWatch console or with the query API. This topic describes the console first, and then the API.

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

Before you begin, make sure that you have the following:
+ Profile data in your account. For instructions, see [Publish profile data to Amazon CloudWatch](CloudWatch-Profiles-publish.md).
+ 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.

## Discover profile data in the CloudWatch console
<a name="CloudWatch-Profiles-query-discover-console"></a>

In the CloudWatch console, each option in the **Service** list shows a service and its profile types. The **Filters** panel groups the label names and their values, for example, under **Host** and **Kubernetes**.

**To see which services and profile types have data 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. At the top of the page, choose the time range to search, for example, **1h**.

1. To see the services and their profile types, open the **Service** list.

1. Select a service, for example, `example-java-service`.

1. To see the profile types for that service, open the **Profile type** list.

**To browse label names and values 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 a service, for example, `example-java-service`.

1. In the **Filters** panel, expand a group, such as **Host** or **Kubernetes**.

Each group lists its label names, such as `k8s.namespace.name` or `k8s.pod.name`, with a check box for each value of the label. The groups are **Service**, **Process**, **Host**, **Kubernetes**, **Cloud**, **Thread & CPU**, **Other resource attributes**, **Other sample labels**, **AWS**, and **Instrumentation**.

## Find the data to query
<a name="CloudWatch-Profiles-query-discover-steps"></a>

To find the data to query with the API, use the discovery operations.

The following procedure finds the profile types for one service. The examples after it show each request.

**To find the profile types for a service**

1. List the services that sent profile data by calling `LabelValues` with the label name `service_name`.

1. List the profile types for one service by calling `LabelValues` with the label name `__profile_type__` and a matcher for the service.

1. Use the returned profile type ID and the service label selector in a flame graph or time series query.

For the request fields of these operations, see [ProfileTypes](CloudWatch-Profiles-query-api-reference.md#CloudWatch-Profiles-query-api-profiletypes), [LabelNames](CloudWatch-Profiles-query-api-reference.md#CloudWatch-Profiles-query-api-labelnames), [LabelValues](CloudWatch-Profiles-query-api-reference.md#CloudWatch-Profiles-query-api-labelvalues), and [Series](CloudWatch-Profiles-query-api-reference.md#CloudWatch-Profiles-query-api-series) in the query API reference.

Each example uses the request format described in [Authentication](CloudWatch-Profiles-query.md#CloudWatch-Profiles-query-auth). Replace the `start` and `end` values with your own time range.

**Example: list the services that sent profile data**  <a name="CloudWatch-Profiles-query-discover-services"></a>
This request calls `LabelValues` for the `service_name` label.  

```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 '{"name": "service_name", "start": 1793793600000, "end": 1793797200000}' \
  https://monitoring.us-east-1.amazonaws.com/querier.v1.QuerierService/LabelValues
```
Example response:  

```json
{"names": ["example-cpu-service", "example-aggregator", "example-processor", "example-java-service"]}
```

**Example: list the profile types for one service**  <a name="CloudWatch-Profiles-query-discover-service-types"></a>
This request calls `LabelValues` for the `__profile_type__` label, filtered to `example-java-service`. Use this request to find the types for a service, because `ProfileTypes` doesn't filter by service.  

```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 '{
    "name": "__profile_type__",
    "matchers": ["{service_name=\"example-java-service\"}"],
    "start": 1793793600000,
    "end": 1793797200000
  }' \
  https://monitoring.us-east-1.amazonaws.com/querier.v1.QuerierService/LabelValues
```
Example response:  

```json
{"names": ["process_cpu:cpu:nanoseconds:cpu:nanoseconds"]}
```

**Example: list every profile type in the account**  <a name="CloudWatch-Profiles-query-discover-types"></a>
This request body for `ProfileTypes` takes only a time range. The response lists every profile type in the account, with its parts.  

```json
{"start": 1793793600000, "end": 1793797200000}
```
Example response (trimmed):  

```json
{
  "profileTypes": [
    {
      "ID": "process_cpu:cpu:nanoseconds:cpu:nanoseconds",
      "name": "process_cpu",
      "sampleType": "cpu",
      "sampleUnit": "nanoseconds",
      "periodType": "cpu",
      "periodUnit": "nanoseconds"
    },
    {
      "ID": "process_samples:samples:count:cpu:nanoseconds",
      "name": "process_samples",
      "sampleType": "samples",
      "sampleUnit": "count",
      "periodType": "cpu",
      "periodUnit": "nanoseconds"
    }
  ]
}
```

**Example: list label names**  <a name="CloudWatch-Profiles-query-discover-labelnames"></a>
This request body for `LabelNames` returns every label name in the time range.  

```json
{"start": 1793793600000, "end": 1793797200000}
```
Example response (trimmed):  

```json
{"names": ["@aws.account", "@aws.region", "@resource.host.name", "@resource.service.name", "__profile_type__", "service_name"]}
```

**Example: list the hosts that run a service**  <a name="CloudWatch-Profiles-query-discover-series"></a>
This request body for `Series` returns one entry for each unique combination of the labels in `labelNames`. In this example, the request lists the hosts that sent profile data for `example-java-service`.  

```json
{
  "matchers": ["{service_name=\"example-java-service\"}"],
  "labelNames": ["service_name", "__profile_type__", "@resource.host.name"],
  "start": 1793793600000,
  "end": 1793797200000
}
```
Example response (trimmed):  

```json
{
  "labelsSet": [
    {
      "labels": [
        {"name": "@resource.host.name", "value": "host-a.example.internal"},
        {"name": "__profile_type__", "value": "process_cpu:cpu:nanoseconds:cpu:nanoseconds"},
        {"name": "service_name", "value": "example-java-service"}
      ]
    },
    {
      "labels": [
        {"name": "@resource.host.name", "value": "host-b.example.internal"},
        {"name": "__profile_type__", "value": "process_cpu:cpu:nanoseconds:cpu:nanoseconds"},
        {"name": "service_name", "value": "example-java-service"}
      ]
    }
  ]
}
```