

# Monitor Amazon Location Service
<a name="monitoring"></a>

When using Amazon Location Service, you can monitor your usage and resources over time by using: 
+ **Amazon CloudWatch**. Monitors your Amazon Location Service resources, and provides metrics with statistics in near-real time.
+ **AWS CloudTrail**. Provides event tracking of all calls to Amazon Location Service APIs.

Monitoring is an important part of maintaining the reliability, availability, and performance of Amazon Location Service and your AWS solutions. We recommend that you collect monitoring data from the resources that make up your AWS solution so that you can more easily debug a multi-point failure if one occurs. Before you start monitoring Amazon Location Service, however, you should create a monitoring plan that includes answers to the following questions:
+ What are your monitoring goals?
+ What resources will you monitor?
+ How often will you monitor these resources?
+ What monitoring tools will you use?
+ Who will perform the monitoring tasks?
+ Who should be notified when something goes wrong?

This section provides information about using these services.

**Topics**
+ [Monitor Amazon Location Service with Amazon CloudWatch](monitoring-using-cloudwatch.md)
+ [Log and monitor with AWS CloudTrail](logging-using-cloudtrail.md)

# Monitor Amazon Location Service with Amazon CloudWatch
<a name="monitoring-using-cloudwatch"></a>

Amazon CloudWatch monitors your AWS resources and the applications that you run on AWS in near-real time. You can monitor Amazon Location resources using CloudWatch, which collects raw data and processes metrics into meaningful statistics in near-real time. You can view historical information for up to 15 months, or search metrics to view in the Amazon CloudWatch console for more perspective about your Amazon Location resources. You can also set alarms by defining thresholds, and send notifications or take actions when those thresholds are met. 

 For more information, see the [Amazon CloudWatch User Guide](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/)

**Topics**
+ [Amazon Location Service metrics exported to Amazon CloudWatch](#metrics-exported-to-cloudwatch)
+ [View Amazon Location Service metrics](#view-metrics)
+ [Create CloudWatch alarms for Amazon Location Service metrics](#create-alarms)
+ [Use CloudWatch to monitor usage against quotas](#alarms-on-quotas)
+ [CloudWatch metric examples for Amazon Location Service](#example-alarms)

## Amazon Location Service metrics exported to Amazon CloudWatch
<a name="metrics-exported-to-cloudwatch"></a>

Metrics are time-ordered data points that are exported to CloudWatch. A dimension is a name/value pair that identifies the metric. For more information, see [Using CloudWatch metrics](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/working_with_metrics.html) and [CloudWatch](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#Dimension) dimensions in the Amazon CloudWatch User Guide.

The following are metrics that Amazon Location Service exports to CloudWatch in the `AWS/Location` namespace.


| Metric | Description | 
| --- | --- | 
|  `CallCount`  |  The number of calls made to a given API endpoint.  Valid Dimensions: Amazon Location Service API names Valid Statistic: Sum Units: Count  | 
|  `ErrorCount`  |  The number of error responses from calls made to a given API endpoint. Valid Dimensions: Amazon Location Service API names Valid Statistic: Sum Units: Count  | 
|  `SuccessCount`  |  The number of successful calls made to a given API endpoint.  Valid Dimensions: Amazon Location Service API names Valid Statistic: Sum Units: Count  | 
|  `CallLatency`  | The amount of time the operation takes to process and return a response when a call is made to a given API endpoint. Valid Dimensions: Amazon Location Service API names Valid Statistic: AverageUnits: Milliseconds | 

## View Amazon Location Service metrics
<a name="view-metrics"></a>

You can view metrics for Amazon Location Service on the Amazon CloudWatch console or by using the Amazon CloudWatch API.

**To view metrics using the CloudWatch console**

**Example**  

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

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

1. On the **All metrics tab**, choose the Amazon Location namespace.

1. Select the type of metric to view.

1. Select the metric and add it to the chart.
For more information, see [View Available Metrics](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/viewing_metrics_with_cloudwatch.html) in the *Amazon CloudWatch User Guide*. 

## Create CloudWatch alarms for Amazon Location Service metrics
<a name="create-alarms"></a>

You can use CloudWatch to set alarms on your Amazon Location Service metrics. For example, you can create an alarm in CloudWatch to send an email whenever an error count spike occurs. 

The following topics give you a high-level overview of how to set alarms using CloudWatch. For detailed instructions, see [Using Alarms](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html) in the *Amazon CloudWatch User Guide*. 

**To set alarms using the CloudWatch console**

**Example**  

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

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

1. Choose **Create Alarm**.

1. Choose **Select metric**.

1. On the **All metrics** tab, select the Amazon Location namespace.

1. Select a metric category.

1. Find the row with the metric you want to create an alarm for, then select the check box next to this row.

1. Choose **Select metric**.

1. Under **Metric**, fill in the values .

1. Specify the alarm **Conditions** .

1. Choose **Next**.

1. If you want to send a notification when the alarm conditions are met:
   + Under **Alarm state trigger**, select the alarm state to prompt a notification to be sent.
   + Under **Select an SNS topic**, choose **Create new topic** to create a new Amazon Simple Notification Service (Amazon SNS) topic. Enter the topic name and the email to send the notification to. 
   + Under **Send a notification to** enter additional email addresses to send the notification to.
   + Choose** Add notification**. This list is saved and appears in the field for future alarms.

1. When done, choose **Next**.

1. Enter a name and description for the alarm, then choose **Next**.

1. Confirm the alarm details, then choose **Next**.

**Note**  
When creating a new Amazon SNS topic, you must verify the email address before a notification can be sent. If the email is not verified, the notification will not be received when an alarm is initiated by a state change.

For more information about how to set alarms using the CloudWatch console, see [Create an Alarm that Sends Email](https://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/AlarmThatSendsEmail.html) in the *Amazon CloudWatch User Guide*. 

## Use CloudWatch to monitor usage against quotas
<a name="alarms-on-quotas"></a>

You can create Amazon CloudWatch alarms to notify you when your utilization of a given quota exceeds a configurable threshold. This enables you to recognize when you are close to your quota limits, and either adapt your utilization to avoid cost overruns, or request a quota increase, if needed. For information about how to use CloudWatch to monitor quotas, see [ Visualizing your service quotas and setting alarms](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Quotas-Visualize-Alarms.html) in the * Amazon CloudWatch User Guide*.

## CloudWatch metric examples for Amazon Location Service
<a name="example-alarms"></a>

You can use the [GetMetricData](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_GetMetricData.html) API to retrieve metrics for Amazon Location. 
+ For example, you can monitor `CallCount` and set an alarm for when a drop in number occurs. 

  Monitoring the `CallCount` metrics for `SendDeviceLocation` can help give you perspective on tracked assets. If the `CallCount` drops, it means that tracked assets, such as a fleet of trucks, have stopped sending their current locations. Setting an alarm for this can help notify you an issue has occurred.
+ For another example, you can monitor `ErrorCount` and set an alarm for when a spike in number occurs.

  Trackers must be associated with geofence collections in order for device locations to be evaluated against geofences. If you have a device fleet that requires continuous location updates, seeing the `CallCount` for `BatchEvaluateGeofence` or `BatchPutDevicePosition` drop to zero indicates that updates are no longer flowing.

The following is an example output for [GetMetricData](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_GetMetricData.html) with the metrics for `CallCount` and `ErrorCount` for creating map resources.

```
{
  "StartTime": 1518867432,
  "EndTime": 1518868032,
  "MetricDataQueries": [
    {
      "Id": "m1",
      "MetricStat": {
        "Metric": {
          "Namespace": "AWS/Location",
          "MetricName": "CallCount",
          "Dimensions": [
            {
              "Name": "SendDeviceLocation",
              "Value": "100"
            }
          ]
        },
        "Period": 300,
        "Stat": "SampleCount",
        "Unit": "Count"
      }
    },
    {
      "Id": "m2",
      "MetricStat": {
        "Metric": {
          "Namespace": "AWS/Location",
          "MetricName": "ErrorCount",
          "Dimensions": [
            {
              "Name": "AssociateTrackerConsumer",
              "Value": "0"
            }
          ]
        },
        "Period": 1,
        "Stat": "SampleCount",
        "Unit": "Count"
      }
    }
  ]
}
```

# Log and monitor with AWS CloudTrail
<a name="logging-using-cloudtrail"></a>

AWS CloudTrail is a service that provides a record of actions taken by a user, role, or an AWS service. CloudTrail records all API calls as events. You can use Amazon Location Service with CloudTrail to monitor your API calls, which include calls from the Amazon Location Service console and AWS SDK calls to the Amazon Location Service API operations. 

When you create a trail, you can enable continuous delivery of CloudTrail events to an S3 bucket, including events for Amazon Location Service. If you don't configure a trail, you can still view the most recent events in the CloudTrail console in **Event history**. Using the information collected by CloudTrail, you can determine the request that was made to Amazon Location Service, the IP address from which the request was made, who made the request, when it was made, and additional details. 

For more information about CloudTrail, see the [AWS CloudTrail User Guide](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/).

**Topics**
+ [Amazon Location Service Information in CloudTrail](#service-name-info-in-cloudtrail)
+ [Learn about Amazon Location Service log file entries](#understanding-service-name-entries)

## Amazon Location Service Information in CloudTrail
<a name="service-name-info-in-cloudtrail"></a>

CloudTrail is enabled on your AWS account when you create the account. When activity occurs in Amazon Location Service, that activity is recorded in a CloudTrail event along with other AWS service events in **Event history**. You can view, search, and download recent events in your AWS account. For more information, see [Viewing Events with CloudTrail Event History](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/view-cloudtrail-events.html). 

For an ongoing record of events in your AWS account, including events for Amazon Location Service, create a trail. A *trail* enables CloudTrail to deliver log files to an S3 bucket. By default, when you create a trail in the console, the trail applies to all AWS Regions. The trail logs events from all Regions in the AWS partition and delivers the log files to the S3 bucket that you specify. Additionally, you can configure other AWS services to further analyze and act upon the event data collected in CloudTrail logs. 

For more information, see the following: 
+ [Overview for Creating a Trail](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-create-and-update-a-trail.html)
+ [CloudTrail Supported Services and Integrations](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-aws-service-specific-topics.html#cloudtrail-aws-service-specific-topics-integrations)
+ [Configuring Amazon SNS Notifications for CloudTrail](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/getting_notifications_top_level.html)
+ [Receiving CloudTrail Log Files from Multiple Regions](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/receive-cloudtrail-log-files-from-multiple-regions.html) and [Receiving CloudTrail Log Files from Multiple Accounts](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-receive-logs-from-multiple-accounts.html)

All Amazon Location Service actions are logged by CloudTrail and are documented in the [Amazon Location Service API references](https://docs.aws.amazon.com/location/previous/APIReference/index.html). For example, calls to the `CreateTracker`, `UpdateTracker` and `DescribeTracker` actions generate entries in the CloudTrail log files. 

Every event or log entry contains information about who generated the request. The identity information helps you determine whether the request was made: 
+ With root or AWS Identity and Access Management (IAM) user credentials.
+ With temporary security credentials for a role or federated user.
+ By another AWS service.

For more information, see the [CloudTrail userIdentity Element](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-event-reference-user-identity.html).

## Learn about Amazon Location Service log file entries
<a name="understanding-service-name-entries"></a>

A trail is a configuration that enables delivery of events as log files to an S3 bucket that you specify, or to Amazon CloudWatch Logs. For more information, see [Working with CloudTrail log files](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-working-with-log-files.html) in the *AWS CloudTrail User Guide*. 

CloudTrail log files contain one or more log entries. An event represents a single request from any source and includes information about the requested operation, the date and time of the operation, request parameters, and so on. 

**Note**  
CloudTrail log files aren't an ordered stack trace of the public API calls, so they don't appear in any specific order. To determine the order of operations, use `[eventTime](https://docs.aws.amazon.com/awscloudtrail/latest/APIReference/API_Event.html)`.

The following example shows a CloudTrail log entry that demonstrates the `CreateTracker` operation, which creates a tracker resource.

```
{
    "eventVersion": "1.05",
    "userIdentity": {
        "type": "AssumedRole",
        "principalId": "123456789012",
        "arn": "arn:aws:geo:us-east-1:123456789012:tracker/ExampleTracker"
        "accountId": "123456789012",
        "accessKeyId": "123456789012",
        "sessionContext": {
            "sessionIssuer": {
                "type": "Role",
                "principalId": "123456789012",
                "arn": "arn:aws:geo:us-east-1:123456789012:tracker/ExampleTracker",
                "accountId": "123456789012",
                "userName": "exampleUser",
            },
            "webIdFederationData": {},
            "attributes": {
                "mfaAuthenticated": "false",
                "creationDate": "2020-10-22T16:36:07Z"
            }
        }
    },
    "eventTime": "2020-10-22T17:43:30Z",
    "eventSource": "geo.amazonaws.com",
    "eventName": "CreateTracker",
    "awsRegion": "us-east-1",
    "sourceIPAddress": "192.0.2.0/24—TEST-NET-1",
    "userAgent": "aws-internal/3 aws-sdk-java/1.11.864 Linux/4.14.193-110.317.amzn2.x86_64 OpenJDK_64-Bit_Server_VM/11.0.8+10-LTS java/11.0.8 kotlin/1.3.72 vendor/Amazon.com_Inc. exec-env/AWS_Lambda_java11",
    "requestParameters": {
        "TrackerName": "ExampleTracker",
        "Description": "Resource description"
    },
    "responseElements": {
        "TrackerName": "ExampleTracker",
        "Description": "Resource description"
        "TrackerArn": "arn:partition:service:region:account-id:resource-id",
        "CreateTime": "2020-10-22T17:43:30.521Z"
    },
    "requestID": "557ec619-0674-429d-8e2c-eba0d3f34413",
    "eventID": "3192bc9c-3d3d-4976-bbef-ac590fa34f2c",
    "readOnly": false,
    "eventType": "AwsApiCall",
    "recipientAccountId": "123456789012",
}
```

The following shows a log entry for the `DescribeTracker` operation, which returns the details of a tracker resource.

```
{
    "eventVersion": "1.05",
    "userIdentity": {
        "type": "AssumedRole",
        "principalId": "123456789012",
        "arn": "arn:partition:service:region:account-id:resource-id",
        "accountId": "123456789012",
        "accessKeyId": "123456789012",
        "sessionContext": {
            "sessionIssuer": {
                "type": "Role",
                "principalId": "123456789012",
                "arn": "arn:partition:service:region:account-id:resource-id",
                "accountId": "123456789012",
                "userName": "exampleUser",
            },
            "webIdFederationData": {},
            "attributes": {
                "mfaAuthenticated": "false",
                "creationDate": "2020-10-22T16:36:07Z"
            }
        }
    },
    "eventTime": "2020-10-22T17:43:33Z",
    "eventSource": "geo.amazonaws.com",
    "eventName": "DescribeTracker",
    "awsRegion": "us-east-1",
    "sourceIPAddress": "192.0.2.0/24—TEST-NET-1",
    "userAgent": "aws-internal/3 aws-sdk-java/1.11.864 Linux/4.14.193-110.317.amzn2.x86_64 OpenJDK_64-Bit_Server_VM/11.0.8+10-LTS java/11.0.8 kotlin/1.3.72 vendor/Amazon.com_Inc. exec-env/AWS_Lambda_java11",
    "requestParameters": {
        "TrackerName": "ExampleTracker"
    },
    "responseElements": null,
    "requestID": "997d5f93-cfef-429a-bbed-daab417ceab4",
    "eventID": "d9e0eebe-173c-477d-b0c9-d1d8292da103",
    "readOnly": true,
    "eventType": "AwsApiCall",
    "recipientAccountId": "123456789012",
}
```