|
| 1 | +# Existing Managed Prometheus Workspace Observability Pattern |
| 2 | + |
| 3 | +This example demonstrates how to use the AWS Observability Accelerator Terraform |
| 4 | +modules with Amazon Managed Prometheus (AMP) workspace monitoring enabled. |
| 5 | + |
| 6 | +The current example deploys a dashboard into an existing Amazon Managed Grafana (AMG) workspace to provide observability over an existing AMP workspace. It also deploys CloudWatch alarms for AMP usage service limits. |
| 7 | + |
| 8 | +## Prerequisites |
| 9 | + |
| 10 | +Ensure that you have the following tools installed locally: |
| 11 | + |
| 12 | +1. [aws cli](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) |
| 13 | +2. [terraform](https://learn.hashicorp.com/tutorials/terraform/install-cli) |
| 14 | + |
| 15 | +It is also required to have existing AMP and Grafana workspaces. These could be created through the [other example modules](../) in this repository. |
| 16 | + |
| 17 | +## Setup |
| 18 | + |
| 19 | +This example uses a local terraform state. If you need states to be saved remotely, |
| 20 | +on Amazon S3 for example, visit the [terraform remote states](https://www.terraform.io/language/state/remote) documentation |
| 21 | + |
| 22 | +1. **Clone the repo using the command below** |
| 23 | + |
| 24 | +```sh |
| 25 | +git clone https://github.com/aws-observability/terraform-aws-observability-accelerator.git |
| 26 | +``` |
| 27 | + |
| 28 | +2. **Initialize terraform** |
| 29 | + |
| 30 | +```sh |
| 31 | +cd examples/amp-monitoring |
| 32 | +terraform init |
| 33 | +``` |
| 34 | + |
| 35 | +3. **AWS Region** |
| 36 | + |
| 37 | +Specify the AWS Region where the resources will be deployed. Edit the `terraform.tfvars` file and modify `aws_region="..."`. You can also use environement variables `export TF_VAR_aws_region=xxx`. |
| 38 | + |
| 39 | +4. **Amazon Managed Service for Prometheus workspace** |
| 40 | + |
| 41 | +If you have an existing workspace, add `managed_prometheus_workspace_id=ws-xxx` |
| 42 | +or use an environment variable `export TF_VAR_managed_prometheus_workspace_id=ws-xxx`. |
| 43 | + |
| 44 | +If you would like to create CloudWatch alarms for multiple workspaces in a region you can pass them in a comma seperated string. |
| 45 | + |
| 46 | +`managed_prometheus_workspace_id = "ws-xxx,ws-xxx"` |
| 47 | + |
| 48 | +You can use the following export command to create alarms for all of the workspaces in a region. |
| 49 | + |
| 50 | +```sh |
| 51 | +export TF_VAR_managed_prometheus_workspace_id=$(aws amp list-workspaces --query 'workspaces[].workspaceId' --output text | sed -E 's/\t/,/g') |
| 52 | +``` |
| 53 | + |
| 54 | +5. **Amazon Managed Grafana workspace** |
| 55 | + |
| 56 | +Use an existing workspace, add `managed_grafana_workspace_id=g-xxx` |
| 57 | +or use an environment variable `export TF_VAR_managed_grafana_workspace_id=g-xxx`. |
| 58 | + |
| 59 | +6. <a name="apikey"></a> **Grafana API Key** |
| 60 | + |
| 61 | +Amazon Managed Service for Grafana provides a control plane API for generating Grafana API keys. We will provide to Terraform |
| 62 | +a short lived API key to run the `apply` or `destroy` command. |
| 63 | +Ensure you have necessary IAM permissions (`CreateWorkspaceApiKey, DeleteWorkspaceApiKey`) |
| 64 | + |
| 65 | +```sh |
| 66 | +export TF_VAR_grafana_api_key=`aws grafana create-workspace-api-key --key-name "observability-accelerator-$(date +%s)" --key-role ADMIN --seconds-to-live 1200 --workspace-id $TF_VAR_managed_grafana_workspace_id --query key --output text` |
| 67 | +``` |
| 68 | + |
| 69 | +## Deploy |
| 70 | + |
| 71 | +```sh |
| 72 | +terraform apply -var-file=terraform.tfvars |
| 73 | +``` |
| 74 | + |
| 75 | +or if you had only setup environment variables, run |
| 76 | + |
| 77 | +```sh |
| 78 | +terraform apply |
| 79 | +``` |
| 80 | + |
| 81 | +## Visualization |
| 82 | + |
| 83 | +1. **Cloudwatch datasource on Grafana** |
| 84 | + |
| 85 | +Open your Grafana workspace and under Configuration -> Data sources, you should see `aws-observability-accelerator-cloudwatch`. Open and click `Save & test`. You should see a notification confirming that the CloudWatch datasource is ready to be used on Grafana. |
| 86 | + |
| 87 | +2. **Grafana dashboards** |
| 88 | + |
| 89 | +Go to the Dashboards panel of your Grafana workspace. You should see a list of dashboards under the `AMP Monitoring Dashboards` folder. |
| 90 | + |
| 91 | +Open the `AMP Accelerator Dashboard` to see a visualization of the AMP workspace. |
| 92 | + |
| 93 | +<img width="1786" alt="Screen Shot 2022-10-11 at 2 16 17 PM" src="https://user-images.githubusercontent.com/97046295/196742772-fba1a5fb-dd38-445c-88a9-607f38994713.png"> |
| 94 | + |
| 95 | +3. **Amazon Managed Service for Prometheus CloudWatch Alarms.** |
| 96 | + |
| 97 | +Open the CloudWatch console and click `Alarms` > `All Alarms` to review the service limit alarms. |
| 98 | + |
| 99 | +<img width="1525" alt="image" src="https://user-images.githubusercontent.com/97046295/196742923-876e3b1c-6f2a-419d-ad39-9c057a0f7650.png"> |
| 100 | + |
| 101 | +In us-east-1 region an alarm is created for billing. This alarm utilizes anomaly detection to detect anomalies in the Estimated Charges billing metric. |
| 102 | + |
| 103 | +<img width="1346" alt="image" src="https://user-images.githubusercontent.com/97046295/197042518-a98d69df-8f53-4a4a-afb8-f424d91da56f.png"> |
| 104 | + |
| 105 | + |
| 106 | + |
| 107 | +<!-- BEGIN_TF_DOCS --> |
| 108 | +## Requirements |
| 109 | + |
| 110 | +| Name | Version | |
| 111 | +|------|---------| |
| 112 | +| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.1.0, < 1.3.0 | |
| 113 | +| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.0.0 | |
| 114 | +| <a name="requirement_grafana"></a> [grafana](#requirement\_grafana) | >= 1.25.0 | |
| 115 | + |
| 116 | +## Providers |
| 117 | + |
| 118 | +| Name | Version | |
| 119 | +|------|---------| |
| 120 | +| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.36.1 | |
| 121 | +| <a name="provider_grafana"></a> [grafana](#provider\_grafana) | 1.30.0 | |
| 122 | + |
| 123 | +## Modules |
| 124 | + |
| 125 | +| Name | Source | Version | |
| 126 | +|------|--------|---------| |
| 127 | +| <a name="module_amp_monitor"></a> [amp\_monitor](#module\_amp\_monitor) | ../../modules/workloads/amp-monitoring | n/a | |
| 128 | +| <a name="module_billing"></a> [billing](#module\_billing) | ../../modules/Billing | n/a | |
| 129 | + |
| 130 | +## Resources |
| 131 | + |
| 132 | +| Name | Type | |
| 133 | +|------|------| |
| 134 | +| [grafana_folder.this](https://registry.terraform.io/providers/grafana/grafana/latest/docs/resources/folder) | resource | |
| 135 | +| [aws_grafana_workspace.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/grafana_workspace) | data source | |
| 136 | + |
| 137 | +## Inputs |
| 138 | + |
| 139 | +| Name | Description | Type | Default | Required | |
| 140 | +|------|-------------|------|---------|:--------:| |
| 141 | +| <a name="input_aws_region"></a> [aws\_region](#input\_aws\_region) | AWS Region | `string` | n/a | yes | |
| 142 | +| <a name="input_grafana_api_key"></a> [grafana\_api\_key](#input\_grafana\_api\_key) | API key for authorizing the Grafana provider to make changes to Amazon Managed Grafana | `string` | n/a | yes | |
| 143 | +| <a name="input_managed_grafana_workspace_id"></a> [managed\_grafana\_workspace\_id](#input\_managed\_grafana\_workspace\_id) | Amazon Managed Grafana (AMG) workspace ID | `string` | n/a | yes | |
| 144 | +| <a name="input_managed_prometheus_workspace_id"></a> [managed\_prometheus\_workspace\_id](#input\_managed\_prometheus\_workspace\_id) | Amazon Managed Service for Prometheus Workspace ID to create Alarms for | `string` | n/a | yes | |
| 145 | + |
| 146 | +## Outputs |
| 147 | + |
| 148 | +| Name | Description | |
| 149 | +|------|-------------| |
| 150 | +| <a name="output_grafana_dashboards_folder_id"></a> [grafana\_dashboards\_folder\_id](#output\_grafana\_dashboards\_folder\_id) | Grafana folder ID for automatic dashboards. Required by workload modules | |
| 151 | +<!-- END_TF_DOCS --> |
0 commit comments