

# Setting up observability with the SageMaker HyperPod observability extension

The SageMaker HyperPod observability extension, `sagemaker-observability`, installs metrics exporters and collectors on the instances of your Slurm cluster. The extension gives you visibility into cluster health, job performance, and GPU utilization.

This topic describes version 1.0.0 of the extension. Version 1.0.0 supports the following features:
+ Metrics in Amazon CloudWatch. Amazon CloudWatch is the default metric store. With Amazon CloudWatch, you don't create an Amazon Managed Service for Prometheus workspace or give the execution roles access to it.
+ Metrics in Amazon Managed Service for Prometheus, when you specify the remote write URL of an Amazon Managed Service for Prometheus workspace.

The extension sends metrics to one metric store. It can't send metrics to both Amazon CloudWatch and Amazon Managed Service for Prometheus at the same time.

## Prerequisites for the observability extension
<a name="sagemaker-hyperpod-cluster-observability-slurm-extension-prerequisites"></a>
+ Your cluster uses continuous provisioning. SageMaker HyperPod supports cluster extensions only on clusters that have `NodeProvisioningMode` set to `Continuous`. For more information, see [Continuous provisioning for enhanced cluster operations with Slurm](sagemaker-hyperpod-scaling-slurm.md).
+ The execution role of each instance group has the permissions in [Permissions for the observability extension](#sagemaker-hyperpod-cluster-observability-slurm-extension-iam).
+ To view Amazon CloudWatch metrics in Amazon Managed Grafana, use a workspace that runs Grafana version 12 or later.
+ No other process uses the ports of the extension's exporters. The extension uses port 9100 for the node exporter on every node, port 9400 for the NVIDIA Data Center GPU Manager (DCGM) exporter on GPU compute nodes, and port 9109 for the Elastic Fabric Adapter (EFA) exporter on compute nodes with EFA. If another process uses one of these ports, the installation fails. The error message names the port and the metric type that you can turn off.

  If you set up observability with the lifecycle scripts (`enable_observability=True`), the exporter containers of the lifecycle scripts use these ports. For more information, see [Installing metrics exporter packages on your HyperPod cluster](sagemaker-hyperpod-cluster-observability-slurm-install-exporters.md). Before you install the extension, do one of the following:
  + Replace the lifecycle-script exporters with the extension. In the `config.py` file of your lifecycle scripts, set `enable_observability = False`, and upload the file to the Amazon S3 location of your lifecycle scripts. New and replaced nodes then don't start the containers. Then remove the containers on each node. The current lifecycle scripts name them `node-exporter`, `dcgm-exporter`, `efa-exporter`, and `otel-collector`.

    ```sh
    $ sudo docker rm -f node-exporter dcgm-exporter efa-exporter otel-collector
    ```

    A node that doesn't have one of these containers reports an error for that name. If your lifecycle scripts are older, run `sudo docker ps` to find the container names. After you remove the containers, the metrics of the lifecycle scripts stop, and the extension collects the metrics.
  + Set `metricsProvider.nodeMetrics.level`, `metricsProvider.acceleratedComputeMetrics.level`, and `metricsProvider.networkMetrics.level` to `DISABLED`. The extension then doesn't use ports 9100, 9400, and 9109, and it doesn't collect these metric types. When `ncclMetrics` is `ENABLED`, `nodeMetrics` can't be `DISABLED`.

## Installing the observability extension with the console
<a name="sagemaker-hyperpod-cluster-observability-slurm-extension-console"></a>

**To install the observability extension**

1. Open the Amazon SageMaker AI console at [https://console.amazonaws.cn/sagemaker/](https://console.amazonaws.cn/sagemaker/).

1. Go to your cluster's details page.

1. Choose the **Extensions** tab.

1. On the **Amazon SageMaker HyperPod observability** card, choose **Actions**, and then choose **Install**.

1. On the **Install HyperPod observability** page, under **Observability metrics**, configure which metrics the extension collects from your cluster instances.

1. Under **Metric store**, choose **Amazon CloudWatch** or **Amazon Managed Service for Prometheus**. **Amazon CloudWatch** is the default, unless the setup stack of the cluster sends metrics to Amazon Managed Service for Prometheus. If you choose Amazon Managed Service for Prometheus, under **Prometheus workspace**, choose **Create a new workspace** or **Choose an existing workspace**.

1. Under **Grafana workspace**, choose **Create a new workspace**, **Choose an existing workspace**, or **None**. If the setup stack of the cluster set up a Grafana workspace, that workspace is the default. If the setup stack set up no Grafana workspace, **None** is the default. Otherwise, **Create a new workspace** is the default in the Amazon Web Services Regions where Amazon Managed Grafana is available. In other Amazon Web Services Regions, the page doesn't show **Create a new workspace**, and **None** is the default. Choose **None** if you plan to connect the metrics to your own observability stack.

1. Submit the page.

When you choose Amazon Managed Service for Prometheus, the console tries to give the execution roles of the cluster the `aps:RemoteWrite` permission on the workspace. If the console can't add the permission, it shows a warning. Add the permission to each execution role yourself.

To change the configuration later, on the **Amazon SageMaker HyperPod observability** card, choose **Actions**, and then choose **Edit**. The **Edit HyperPod observability** page has the same settings.

When you create a cluster with **Quick setup**, the console installs the observability extension with **Amazon CloudWatch** as the metric store.

## Installing the observability extension with the API
<a name="sagemaker-hyperpod-cluster-observability-slurm-extension-api"></a>

To install the extension, use the `CreateClusterExtension` API operation. To change the configuration of an installed extension, use the `UpdateClusterExtension` API operation. Pass the configuration of the extension as a JSON string in `ConfigurationValues`.

The following example is a `CreateClusterExtension` request that installs version 1.0.0 with Amazon CloudWatch as the metric store.

```json
{
    "ClusterArn": "{{arn:aws:sagemaker:us-west-2:111122223333:cluster/abcde1234567}}",
    "ExtensionName": "sagemaker-observability",
    "ExtensionVersion": "1.0.0",
    "ConfigurationValues": "{}"
}
```

The following Amazon CLI command sends the same request.

```
aws sagemaker create-cluster-extension \
    --cluster-arn {{arn:aws:sagemaker:us-west-2:111122223333:cluster/abcde1234567}} \
    --extension-name sagemaker-observability \
    --extension-version 1.0.0 \
    --configuration-values '{}'
```

To change the configuration, use the `aws sagemaker update-cluster-extension` command.

`UpdateClusterExtension` applies `ConfigurationValues` to the stored configuration as a JSON merge patch (RFC 7396). Keys that you don't specify keep their stored values. A key with the value `null` is deleted. SageMaker HyperPod then validates the merged configuration against the schema of the extension. For example, to send metrics to Amazon CloudWatch instead of Amazon Managed Service for Prometheus, delete the `prometheus` key with the following command. Replace {{extension-arn}} with the ARN of the installed extension. To get the ARN, use the `ListClusterExtensions` API operation.

```
aws sagemaker update-cluster-extension \
    --cluster-arn {{arn:aws:sagemaker:us-west-2:111122223333:cluster/abcde1234567}} \
    --extension-arn {{extension-arn}} \
    --configuration-values '{"prometheus":null}'
```

To change back to Amazon Managed Service for Prometheus, specify `prometheus.remoteWriteUrl` again. The execution role of each instance group needs `aps:RemoteWrite` on the workspace.

After you change the metric store, the extension sends new metrics only to the new metric store. It doesn't copy the metrics that are already in the old metric store. Metrics in an Amazon Managed Service for Prometheus workspace stay there for the retention period of the workspace.

If the extension has a Grafana workspace, the console replaces the SageMaker HyperPod Slurm dashboards in that workspace with the dashboards for the new metric store the next time that you view the cluster in the console. If other SageMaker HyperPod clusters use the workspace, the console asks you before it replaces the dashboards.

To check the status of the extension, use the `DescribeClusterExtension` API operation. When the installation is complete, the status is `Active`.

The extension accepts the following configuration values.


**Configuration values for the observability extension**  

| Key | Description | 
| --- | --- | 
| prometheus.remoteWriteUrl | The remote write URL of your Amazon Managed Service for Prometheus workspace, for example `https://aps-workspaces.{{us-west-2}}.amazonaws.com/workspaces/{{ws-11111111-2222-3333-4444-555555555555}}/api/v1/remote_write`. The workspace must be in the same Amazon Web Services Region as the cluster.<br />If you don't specify `prometheus` when you install the extension, the extension sends metrics to Amazon CloudWatch. To change an installed extension to Amazon CloudWatch, set `prometheus` to `null`. | 
| metricsProvider.{{type}}.level | The collection level for a metric type:+  `nodeMetrics` and `acceleratedComputeMetrics`—`BASIC` (default), `ADVANCED`, or `DISABLED`. <br />+  `clusterMetrics`, `networkMetrics`, and `jobMetrics`—`ENABLED` (default) or `DISABLED`. <br />+  `ncclMetrics`—`ENABLED` or `DISABLED` (default). When `ncclMetrics` is `ENABLED`, `nodeMetrics` can't be `DISABLED`.  | 
| metricsProvider.{{type}}.collectionIntervalSeconds | The collection interval for a metric type, from 30 to 300 seconds. The default is 30. | 

The following configuration values install the extension with Amazon CloudWatch as the metric store.

```json
{}
```

The following configuration values send metrics to an Amazon Managed Service for Prometheus workspace.

```json
{
    "prometheus": {
        "remoteWriteUrl": "https://aps-workspaces.{{us-west-2}}.amazonaws.com/workspaces/{{ws-11111111-2222-3333-4444-555555555555}}/api/v1/remote_write"
    }
}
```

## Permissions for the observability extension
<a name="sagemaker-hyperpod-cluster-observability-slurm-extension-iam"></a>

The extension runs with the execution role of each instance group. The role needs the following actions for the features that you use:
+ Metrics in Amazon CloudWatch—`cloudwatch:PutMetricData`
+ Metrics in Amazon Managed Service for Prometheus—`aps:RemoteWrite` on the workspace

When the console creates the execution role, the role allows `cloudwatch:PutMetricData`.

The Amazon managed policy [AmazonSageMakerClusterInstanceRolePolicy](security-iam-awsmanpol-AmazonSageMakerClusterInstanceRolePolicy.md) allows `cloudwatch:PutMetricData`. If your execution role has this policy, the role needs no other permissions for Amazon CloudWatch metrics. The policy doesn't allow `aps:RemoteWrite`. To send metrics to Amazon Managed Service for Prometheus, add a statement like the following to the execution role.

```json
{
    "Version": "2012-10-17", 		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "aps:RemoteWrite",
            "Resource": "arn:aws:aps:{{us-west-2}}:{{111122223333}}:workspace/{{workspace-ID}}"
        }
    ]
}
```

## Viewing the metrics of the observability extension
<a name="sagemaker-hyperpod-cluster-observability-slurm-extension-view-metrics"></a>

When Amazon CloudWatch is the metric store, the extension sends the metrics to the CloudWatch OpenTelemetry Protocol (OTLP) endpoint. You can query the metrics with the Prometheus Query Language (PromQL) in Query Studio in the CloudWatch console, with the Prometheus-compatible query API, or in Amazon Managed Grafana. To query the metrics, you need the `cloudwatch:GetMetricData` and `cloudwatch:ListMetrics` permissions. For more information, see [Query metrics with PromQL](https://docs.amazonaws.cn/AmazonCloudWatch/latest/monitoring/CloudWatch-PromQL.html) in the *Amazon CloudWatch User Guide*.

The extension adds the resource attributes `aws.sagemaker.hyperpod.cluster.name`, `aws.sagemaker.hyperpod.cluster.arn`, `aws.sagemaker.hyperpod.cluster.id`, `aws.sagemaker.hyperpod.instance_group.name`, `cloud.resource_id`, and `host.name` to each metric. In PromQL, add the prefix `@resource.` to a resource attribute and put the label name in quotation marks, for example `{"@resource.aws.sagemaker.hyperpod.cluster.name"="{{my-cluster}}"}`.

When you choose an Amazon Managed Grafana workspace in the console, the console sets up a data source for the metric store and the SageMaker HyperPod dashboards in the workspace. The **Grafana dashboards** row on the **Amazon SageMaker HyperPod observability** card shows the status of this setup. For Amazon CloudWatch, the workspace must run Grafana version 12 or later, because the dashboards need the Amazon Managed Service for Prometheus data source plugin.