|
| 1 | +# Deploy NetApp Harvest on EC2 |
| 2 | + |
| 3 | +Harvest installation for monitoring Amazon FSxN using Prometheus and Grafana stack, integrating AWS Secret Manager for FSxN credentials. |
| 4 | + |
| 5 | +## Introduction |
| 6 | + |
| 7 | +### What to Expect |
| 8 | + |
| 9 | +Harvest installation will result in the following: |
| 10 | +* Install NetApp Harvest with the latest version on your EC2 instance. |
| 11 | +* Collecting metrics about your FSxNs and adding existing Grafana dashboards for better visualization. |
| 12 | + |
| 13 | +### Prerequisites |
| 14 | +* A FSx for ONTAP file system running in the same VPC as the EC2 instance. |
| 15 | +* If not running an AWS based Linux, ensure that the `aws` command has been installed and configured. |
| 16 | + |
| 17 | +## Installation Steps |
| 18 | + |
| 19 | +### 1. Create AWS Secret Manager with Username and Password for each FSxN |
| 20 | +Since this solution uses an AWS Secrets Manager secret to authenticate with the FSx for ONTAP file system |
| 21 | +you will need to create a secret for each FSxN you want to monitor. You can use the following command to create a secret: |
| 22 | + |
| 23 | +```sh |
| 24 | +aws secretsmanager create-secret --name <YOUR-SECRET-NAME> --secret-string '{"username":"fsxadmin","password":"<YOUR-PASSWORD>"}' |
| 25 | +``` |
| 26 | + |
| 27 | +### 2. Create Instance Profile with Permission to AWS Secret Manager and CloudWatch metrics |
| 28 | + |
| 29 | +#### 2.1. Create Policy |
| 30 | + |
| 31 | +Edit the harvest-policy.json file found in this repo with the ARN of the AWS Secret Manager secrets created above. |
| 32 | +If you only have one FSxN and therefore only one secret, remove the comma after the one secret ARN (i.e. the last |
| 33 | +entry should not have a comma after it). |
| 34 | + |
| 35 | +``` |
| 36 | +{ |
| 37 | + "Statement": [ |
| 38 | + { |
| 39 | + "Effect": "Allow", |
| 40 | + "Action": [ |
| 41 | + "secretsmanager:GetSecretValue", |
| 42 | + "secretsmanager:DescribeSecret", |
| 43 | + "secretsmanager:ListSecrets" |
| 44 | + ], |
| 45 | + "Resource": [ |
| 46 | + "<your_secret_1_arn>", |
| 47 | + "<your_secret_2_arn>" |
| 48 | + ] |
| 49 | + }, |
| 50 | + { |
| 51 | + "Effect": "Allow", |
| 52 | + "Action": [ |
| 53 | + "tag:GetResources", |
| 54 | + "cloudwatch:GetMetricData", |
| 55 | + "cloudwatch:GetMetricStatistics", |
| 56 | + "cloudwatch:ListMetrics", |
| 57 | + "apigateway:GET", |
| 58 | + "aps:ListWorkspaces", |
| 59 | + "autoscaling:DescribeAutoScalingGroups", |
| 60 | + "dms:DescribeReplicationInstances", |
| 61 | + "dms:DescribeReplicationTasks", |
| 62 | + "ec2:DescribeTransitGatewayAttachments", |
| 63 | + "ec2:DescribeSpotFleetRequests", |
| 64 | + "shield:ListProtections", |
| 65 | + "storagegateway:ListGateways", |
| 66 | + "storagegateway:ListTagsForResource", |
| 67 | + "iam:ListAccountAliases" |
| 68 | + ], |
| 69 | + "Resource": [ |
| 70 | + "*" |
| 71 | + ] |
| 72 | + } |
| 73 | + ], |
| 74 | + "Version": "2012-10-17" |
| 75 | +} |
| 76 | +``` |
| 77 | + |
| 78 | +Run the following command to create the policy and obtain the policy ARN: |
| 79 | +```sh |
| 80 | +POLICY_ARN=$(aws iam create-policy --policy-name harvest-policy --policy-document file://harvest-policy.json --query Policy.Arn --output text) |
| 81 | +``` |
| 82 | + |
| 83 | +#### 2.2. Create Instance Profile Role |
| 84 | + |
| 85 | +Run the following commands to create the instance profile role and attach the policy to it: |
| 86 | +```sh |
| 87 | +aws iam create-role --role-name HarvestRole --assume-role-policy-document file://trust-policy.json |
| 88 | +aws iam attach-role-policy --role-name HarvestRole --policy-arn $POLICY_ARN |
| 89 | +aws iam create-instance-profile --instance-profile-name HarvestProfile |
| 90 | +aws iam add-role-to-instance-profile --instance-profile-name HarvestProfile --role-name HarvestRole |
| 91 | +``` |
| 92 | + |
| 93 | +Note that the `trust-policy.json` file can be found in this repo. |
| 94 | + |
| 95 | +### 3. Create EC2 Instance |
| 96 | + |
| 97 | +We recommend using a `t2.xlarge` or larger instance type with at least 20GB disk. |
| 98 | + |
| 99 | +Once you have created your ec2 instance, you can use the following command to attach the instance profile: |
| 100 | + |
| 101 | +```sh |
| 102 | +aws ec2 associate-iam-instance-profile --instance-id <INSTANCE-ID> --iam-instance-profile Arn=<Instance-Profile-ARN>,Name=HarvestProfile |
| 103 | +``` |
| 104 | +You should get the instance profile ARN from step 2.2 above. |
| 105 | + |
| 106 | +If your exiting ec2 instance already had an instance profile, then simply add the policy create in step 2.2 above to its instance profile role. |
| 107 | + |
| 108 | +### 4. Install Docker and Docker Compose |
| 109 | + |
| 110 | +To install Docker use the following commands if you are running an Red Hat based Linux: |
| 111 | +```sh |
| 112 | +sudo yum install docker |
| 113 | +sudo curl -L https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-compose-plugin-2.6.0-3.el7.x86_64.rpm -o ./compose-plugin.rpm |
| 114 | +sudo yum install ./compose-plugin.rpm -y |
| 115 | +sudo systemctl start docker |
| 116 | +``` |
| 117 | +If you aren't running a Red Hat based Linux, you can follow the instructions [here](https://docs.docker.com/engine/install/). |
| 118 | + |
| 119 | +To confirm that docker has been installed correctly, run the following command: |
| 120 | + |
| 121 | +```sh |
| 122 | +sudo docker run hello-world |
| 123 | +``` |
| 124 | + |
| 125 | +You should get output similar to the following: |
| 126 | +``` |
| 127 | +Hello from Docker! |
| 128 | +This message shows that your installation appears to be working correctly. |
| 129 | +
|
| 130 | +To generate this message, Docker took the following steps: |
| 131 | + 1. The Docker client contacted the Docker daemon. |
| 132 | + 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. |
| 133 | + (amd64) |
| 134 | + 3. The Docker daemon created a new container from that image which runs the |
| 135 | + executable that produces the output you are currently reading. |
| 136 | + 4. The Docker daemon streamed that output to the Docker client, which sent it |
| 137 | + to your terminal. |
| 138 | +
|
| 139 | +To try something more ambitious, you can run an Ubuntu container with: |
| 140 | + $ docker run -it ubuntu bash |
| 141 | +
|
| 142 | +Share images, automate workflows, and more with a free Docker ID: |
| 143 | + https://hub.docker.com/ |
| 144 | +
|
| 145 | +For more examples and ideas, visit: |
| 146 | + https://docs.docker.com/get-started/ |
| 147 | +``` |
| 148 | +### 5. Install Harvest on EC2 |
| 149 | + |
| 150 | +Preform the following steps to install Harvest on your EC2 instance: |
| 151 | + |
| 152 | +#### 5.1. Generate Harvest Configuration File |
| 153 | + |
| 154 | +Modify the `harvest.yml` found in this repo with your clusters details. You should just have to change the `<FSxN_ip_X>` with the IP addresses of your FSxNs. |
| 155 | +Add as many pollers as you need to monitor all your FSxNs. There should be an AWS Secrets Manager secret for each FSxN. |
| 156 | + |
| 157 | +```yaml |
| 158 | +Exporters: |
| 159 | + prometheus1: |
| 160 | + exporter: Prometheus |
| 161 | + port_range: 12990-14000 |
| 162 | + add_meta_tags: false |
| 163 | +Defaults: |
| 164 | + use_insecure_tls: true |
| 165 | +Pollers: |
| 166 | + fsx01: |
| 167 | + datacenter: fsx |
| 168 | + addr: <FSxN_ip_1> |
| 169 | + collectors: |
| 170 | + - Rest |
| 171 | + - RestPerf |
| 172 | + - Ems |
| 173 | + exporters: |
| 174 | + - prometheus1 |
| 175 | + credentials_script: |
| 176 | + path: /opt/fetch-credentails |
| 177 | + schedule: 3h |
| 178 | + timeout: 10s |
| 179 | + fsx02: |
| 180 | + datacenter: fsx |
| 181 | + addr: <FSxN_ip_2> |
| 182 | + collectors: |
| 183 | + - Rest |
| 184 | + - RestPerf |
| 185 | + - Ems |
| 186 | + exporters: |
| 187 | + - prometheus1 |
| 188 | + credentials_script: |
| 189 | + path: /opt/fetch-credentails |
| 190 | + schedule: 3h |
| 191 | + timeout: 10s |
| 192 | +``` |
| 193 | +
|
| 194 | +#### 5.2. Generate a Docker Compose from Harvest Configuration |
| 195 | +
|
| 196 | +Run the following command to generate a Docker Compose file from the Harvest configuration: |
| 197 | +
|
| 198 | +```sh |
| 199 | +docker run --rm \ |
| 200 | + --env UID=$(id -u) --env GID=$(id -g) \ |
| 201 | + --entrypoint "bin/harvest" \ |
| 202 | + --volume "$(pwd):/opt/temp" \ |
| 203 | + --volume "$(pwd)/harvest.yml:/opt/harvest/harvest.yml" \ |
| 204 | + ghcr.io/netapp/harvest \ |
| 205 | + generate docker full \ |
| 206 | + --output harvest-compose.yml |
| 207 | +``` |
| 208 | + |
| 209 | +:warning: Ignore the command that it outputs that it says will start the cluster. |
| 210 | + |
| 211 | +#### 5.3. Replace Harvest images in the harvest-compose.yml: |
| 212 | + |
| 213 | +Replace the Harvest image with one that supports using AWS Secret Manager for FSxN credentials: |
| 214 | + |
| 215 | +```yaml |
| 216 | +sed -i 's|ghcr.io/netapp/harvest:latest|ghcr.io/tlvdevops/harvest-fsx:latest|g' harvest-compose.yml |
| 217 | +``` |
| 218 | + |
| 219 | +#### 5.4. Add AWS Secret Manager Names to Docker Compose Environment Variables |
| 220 | + |
| 221 | +Edit the `harvest-compose.yml` file by adding the "environment" section for each FSxN with the two variables: `SECRET_NAME` and `AWS_REGION`. |
| 222 | +These environment variables are required for the credentials script. |
| 223 | + |
| 224 | +For example: |
| 225 | +```yaml |
| 226 | +services: |
| 227 | + fsx01: |
| 228 | + image: ghcr.io/tlvdevops/harvest-fsx:latest |
| 229 | + container_name: poller-fsx01 |
| 230 | + restart: unless-stopped |
| 231 | + ports: |
| 232 | + - "12990:12990" |
| 233 | + command: '--poller fsx01 --promPort 12990 --config /opt/harvest.yml' |
| 234 | + volumes: |
| 235 | + - ./cert:/opt/harvest/cert |
| 236 | + - ./harvest.yml:/opt/harvest.yml |
| 237 | + - ./conf:/opt/harvest/conf |
| 238 | + environment: |
| 239 | + - SECRET_NAME=<your_secret_name> |
| 240 | + - AWS_REGION=<region_where_secret_resides> |
| 241 | + networks: |
| 242 | + - backend |
| 243 | +``` |
| 244 | +#### 5.5. Download FSxN dashboards and import into Grafana container: |
| 245 | +The following commands will download the FSxN designed dashboards from this repo and replace the default Grafana dashboards with them: |
| 246 | +```yaml |
| 247 | +wget https://raw.githubusercontent.com/NetApp/FSx-ONTAP-samples-scripts/main/Monitoring/monitor_fsxn_with_grafana/fsx_dashboards.zip |
| 248 | +unzip fsx_dashboards.zip |
| 249 | +rm -rf grafana/dashboards |
| 250 | +mv dashboards grafana/dashboards |
| 251 | +``` |
| 252 | + |
| 253 | +#### 5.6. Configure Prometheus to use yet-another-exporter (yace) to gather AWS FSxN metrics |
| 254 | +AWS has useful metrics regarding the FSxN file system that ONTAP doesn't provide. Therefore, it is recommended to install |
| 255 | +an exporter that will expose these metrics. The following steps show how to install a recommended exporter. |
| 256 | + |
| 257 | +##### 5.6.1 Create the yace configuration file. |
| 258 | +Edit the `yace-config.yaml` file found in this repo and replace `<aws_region>`, in both places, with the region where your FSxN resides: |
| 259 | +```yaml |
| 260 | +apiVersion: v1alpha1 |
| 261 | +sts-region: <aws_region> |
| 262 | +discovery: |
| 263 | + jobs: |
| 264 | + - type: AWS/FSx |
| 265 | + regions: [<aws_region>] |
| 266 | + period: 300 |
| 267 | + length: 300 |
| 268 | + metrics: |
| 269 | + - name: DiskReadOperations |
| 270 | + statistics: [Average] |
| 271 | + - name: DiskWriteOperations |
| 272 | + statistics: [Average] |
| 273 | + - name: DiskReadBytes |
| 274 | + statistics: [Average] |
| 275 | + - name: DiskWriteBytes |
| 276 | + statistics: [Average] |
| 277 | + - name: DiskIopsUtilization |
| 278 | + statistics: [Average] |
| 279 | + - name: NetworkThroughputUtilization |
| 280 | + statistics: [Average] |
| 281 | + - name: FileServerDiskThroughputUtilization |
| 282 | + statistics: [Average] |
| 283 | + - name: CPUUtilization |
| 284 | + statistics: [Average] |
| 285 | +``` |
| 286 | +
|
| 287 | +##### 5.6.2 Add Yet-Another-Exporter to harvest-compose.yaml |
| 288 | +
|
| 289 | +Copy the following to the end of the `harvest-compose.yml` file: |
| 290 | +```yaml |
| 291 | + yace: |
| 292 | + image: quay.io/prometheuscommunity/yet-another-cloudwatch-exporter:latest |
| 293 | + container_name: yace |
| 294 | + restart: always |
| 295 | + expose: |
| 296 | + - 8080 |
| 297 | + volumes: |
| 298 | + - ./yace-config.yaml:/tmp/config.yml |
| 299 | + - $HOME/.aws:/exporter/.aws:ro |
| 300 | + command: |
| 301 | + - -listen-address=:8080 |
| 302 | + - -config.file=/tmp/config.yml |
| 303 | + networks: |
| 304 | + - backend |
| 305 | +``` |
| 306 | + |
| 307 | +##### 5.6.3. Add Yet-Another-Exporter target to prometheus.yml: |
| 308 | +```yaml |
| 309 | +sudo sed -i -e "\$a\- job_name: 'yace'" -e "\$a\ static_configs:" -e "\$a\ - targets: ['yace:8080']" container/prometheus/prometheus.yml |
| 310 | +``` |
| 311 | + |
| 312 | +##### 6. Bring Everything Up |
| 313 | + |
| 314 | +```sh |
| 315 | +sudo docker compose -f prom-stack.yml -f harvest-compose.yml up -d --remove-orphans |
| 316 | +``` |
| 317 | + |
| 318 | +After bringing up the prom-stack.yml compose file, you can access Grafana at |
| 319 | +http://IP_OF_GRAFANA:3000. |
| 320 | + |
| 321 | +You will be prompted to create a new password the first time you log in. Grafana's default credentials are: |
| 322 | +``` |
| 323 | +username: admin |
| 324 | +password: admin |
| 325 | +``` |
0 commit comments