

# Monitoring AWS Systems Manager Cloud Extensions

Monitor the health and performance of the AWS Systems Manager Cloud Extensions runtime and your extensions. Use runtime logs, Amazon CloudWatch metrics, and the Cloud Extensions API.

**Topics**
+ [Checking the configuration with the API](#cloud-extensions-monitoring-checking-the-configuration-with-the-api)
+ [Runtime logs](#cloud-extensions-monitoring-runtime-logs)
+ [CloudWatch metrics](#cloud-extensions-monitoring-cloudwatch-metrics)
+ [Telemetry that the runtime sends](#cloud-extensions-monitoring-telemetry-that-the-runtime-sends)
+ [Extension-specific details](#cloud-extensions-monitoring-extension-specific-details)
+ [Checking profiles and extension versions on the console](#cloud-extensions-monitoring-checking-profiles-and-extension-versions-on-the-console)
+ [Performance monitoring](#cloud-extensions-monitoring-performance-monitoring)
+ [Troubleshooting with monitoring data](#cloud-extensions-monitoring-troubleshooting-with-monitoring-data)
+ [Best practices](#cloud-extensions-monitoring-best-practices)
+ [Next steps](#cloud-extensions-monitoring-next-steps)

## Checking the configuration with the API
<a name="cloud-extensions-monitoring-checking-the-configuration-with-the-api"></a>

The Cloud Extensions API shows the configuration that the runtime loads. Use the following commands to confirm what you configured:

```bash
# List the profiles in your account
aws cloudextensions list-profiles
# List the extensions in a profile
aws cloudextensions list-profile-entries --profile-identifier my-application
# View the version policy, the settings, and the capabilities that you approved for one extension
aws cloudextensions get-profile-entry \
  --profile-identifier my-application \
  --identifier {{profile-entry-id}}
```

The `effectiveSettings` field shows the setting values that the extension uses, including default values. The `approved` field shows the capabilities that you approved. The `inherited` field shows the profile defaults that apply to the entry.

## Runtime logs
<a name="cloud-extensions-monitoring-runtime-logs"></a>

The runtime writes log messages that show which profile it loaded, which extensions it started, and which errors occurred.

### Log messages
<a name="cloud-extensions-monitoring-log-messages"></a>

At startup, the runtime logs the profile that it retrieved and the extensions that it loads. When the runtime shuts down, it logs that it removed the routes of the extensions. When the cached copy of an extension doesn't match the release, the runtime logs a warning and fetches the correct package.

### Where to find the logs
<a name="cloud-extensions-monitoring-where-to-find-the-logs"></a>
+ **Lambda** – The runtime writes its logs to the CloudWatch Logs log group of your function, `/aws/lambda/{{function-name}}`. The logs are JSON, with one event on each line.
+ **Containers** – The runtime writes its logs to the standard output of the container, as plain text. Use `docker logs`, or the log driver of your container platform.

A log line that comes from an extension, instead of from the runtime, has `"source": "extension"`.

To read the logs of a Lambda function, run the following command:

```bash
aws logs tail /aws/lambda/my-function --follow
```

### Log level
<a name="cloud-extensions-monitoring-log-level"></a>

In Lambda, the `AWS_CLOUDEXTENSIONS_LOG_LEVEL` environment variable sets the verbosity of the logs. For example, to see detailed messages, set the variable to `debug`. The valid values are:
+ `debug` - Detailed debugging information
+ `info` - General informational messages. This value is the default.
+ `warn` - Warning messages only
+ `error` - Error messages only
+ `none` - No logs

### Searching the logs
<a name="cloud-extensions-monitoring-searching-the-logs"></a>

To search the logs of a Lambda function for errors, run the following command:

```bash
aws logs filter-log-events \
  --log-group-name /aws/lambda/my-function \
  --filter-pattern "ERROR"
```

## CloudWatch metrics
<a name="cloud-extensions-monitoring-cloudwatch-metrics"></a>

Each extension sends its own metrics to Amazon CloudWatch. The metrics are OpenTelemetry metrics, so they don't have a classic CloudWatch namespace or dimensions, and the `list-metrics` command of CloudWatch doesn't list them. You query the metrics with Prometheus Query Language (PromQL) in CloudWatch, and you create PromQL alarms on them. You don't turn on a feature in your account. You don't pay for the metrics.

### Metric scopes and attributes
<a name="cloud-extensions-monitoring-metric-scopes-and-attributes"></a>

Each extension publishes its metrics under its own instrumentation scope. The scope has the form `cloudwatch.aws/<extension_name>/cloudextensions`. The following table lists the scopes:


| Extension | Scope | 
| --- | --- | 
| AWS AppConfig | `cloudwatch.aws/appconfig/cloudextensions` | 
| Parameter Store | `cloudwatch.aws/parameterstore/cloudextensions` | 
| Secrets Manager | `cloudwatch.aws/secretsmanager/cloudextensions` | 

Each data point has the attributes `extension.name` and `extension.version`. For the metrics of each extension, see the monitoring topic of the extension.

### Querying metrics
<a name="cloud-extensions-monitoring-querying-metrics"></a>

To query a metric, use a PromQL query in CloudWatch. For example, the following query is true when the AWS AppConfig extension fails to retrieve a configuration within the last five minutes:

```
sum(sum_over_time({"cache.load.failures"}[5m])) > 0
```

### Creating CloudWatch alarms
<a name="cloud-extensions-monitoring-creating-cloudwatch-alarms"></a>

Create PromQL alarms to detect problems early. Alarm on the failure counters of an extension. For example, the `cache.load.failures` and `cache.refresh.failures` metrics of the AWS AppConfig extension count failed retrievals and failed background polls.

## Telemetry that the runtime sends
<a name="cloud-extensions-monitoring-telemetry-that-the-runtime-sends"></a>

The runtime sends operational telemetry to AWS. For each reporting period, the telemetry includes the following:
+ The number of invocations, errors, and faults of each extension
+ The memory that each extension uses
+ How long calls to each extension take
+ The metrics of each extension

The telemetry labels this data with the ID and name of the profile and the name and version of the extension. When the runtime calls the Cloud Extensions service, it also identifies its own version, its operating system, and its architecture. In Lambda, it also identifies the Lambda environment. You can't turn telemetry off.

If the network is unavailable, the runtime buffers telemetry for retry.

## Extension-specific details
<a name="cloud-extensions-monitoring-extension-specific-details"></a>

For the metrics, logs, settings, and checks of each extension, see the topic for the extension:
+ [Monitoring the AWS AppConfig extension in AWS Systems Manager Cloud Extensions](cloud-extensions-ext-appconfig-monitoring.md)
+ [Monitoring the Parameter Store extension in AWS Systems Manager Cloud Extensions](cloud-extensions-ext-parameter-store-monitoring.md)
+ [Monitoring the Secrets Manager extension in AWS Systems Manager Cloud Extensions](cloud-extensions-ext-secrets-manager-monitoring.md)

## Checking profiles and extension versions on the console
<a name="cloud-extensions-monitoring-checking-profiles-and-extension-versions-on-the-console"></a>

**To check the version and the update method of each extension in a profile**

1. Open the Systems Manager console at [https://console.aws.amazon.com/systems-manager/](https://console.aws.amazon.com/systems-manager/).

1. In the navigation pane, choose **Cloud Extensions**.

1. Choose the **Profiles** tab, and then choose the name of the profile.

1. On the **Extensions** tab, review the **Version** and **Update method** columns for each extension.

1. If a version column shows **Update available**, a newer version of the extension exists. For more information, see [Updating an extension on the console](cloud-extensions-updates.md#cloud-extensions-updates-updating-an-extension-on-the-console).

To check the authentication setting and the execution role of the profile, choose the **Runtime settings** tab.

## Performance monitoring
<a name="cloud-extensions-monitoring-performance-monitoring"></a>

### Cache effectiveness
<a name="cloud-extensions-monitoring-cache-effectiveness"></a>

Use the cache metrics of an extension to see how well its cache works. Compare `cache.hits` with `cache.misses` to see the hit ratio. A low hit ratio means that more requests reach the AWS service. The cache might be too small, or the time to live (TTL) might be too short. For the metrics of each extension, see the monitoring topic of the extension.

### Memory
<a name="cloud-extensions-monitoring-memory"></a>

A steady rise in memory use can mean that a cache setting is too large for your compute. For example, the Parameter Store extension has a cache size setting. For more information, see [Configuration options for the Parameter Store extension in AWS Systems Manager Cloud Extensions](cloud-extensions-ext-parameter-store-configuration.md).

## Troubleshooting with monitoring data
<a name="cloud-extensions-monitoring-troubleshooting-with-monitoring-data"></a>
+ **An extension doesn't start** – Check the runtime logs for `ERROR failed to load extension` messages, and check the `approved` and `effectiveSettings` fields of the profile entry.
+ **Slow responses** – Check the logs of the extension in CloudWatch Logs after your next invocation. Then check the cache metrics. A low hit ratio means that more requests reach the AWS service.
+ **High memory use** – Review the cache settings of the extension.

For detailed steps, see [Troubleshooting AWS Systems Manager Cloud Extensions](cloud-extensions-troubleshooting.md).

## Best practices
<a name="cloud-extensions-monitoring-best-practices"></a>

1. **Set up alarms early** – Create alarms before you deploy to production.

1. **Establish a baseline** – Record the normal hit ratio of the cache of each extension so that you can compare it with later results.

1. **Watch metrics when versions change** – Check metrics closely after you move a profile entry to a new extension version.

1. **Check the logs after a change** – After you change a profile, check the logs of the extension in CloudWatch Logs after your next invocation.

1. **Retain logs** – Set a retention period for your CloudWatch Logs log groups.

1. **Review regularly** – Review your metrics periodically to find optimization opportunities.

## Next steps
<a name="cloud-extensions-monitoring-next-steps"></a>
+ [Troubleshooting AWS Systems Manager Cloud Extensions](cloud-extensions-troubleshooting.md)
+ [Managing AWS Systems Manager Cloud Extensions updates](cloud-extensions-updates.md)
+ [Security in AWS Systems Manager Cloud Extensions](cloud-extensions-security.md)