You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Monitoring/auto-add-cw-alarms/README.md
+35-14Lines changed: 35 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,19 +10,32 @@ to monitor the CPU utilization of the file system. And if a volume or file syste
10
10
11
11
To implement this, you might think to just create EventTail filters to trigger on the creation or deletion of an FSx Volume.
12
12
This would kind of work, but since you have command line access to the FSx for ONTAP file system, you can create
13
-
and delete volumes without creating CloudTrail events. So, this method would not be reliable. Therefore, instead
13
+
and delete volumes without generating any CloudTrail events. So, this method would not be reliable. Therefore, instead
14
14
of relying on those events, this script will scan all the file systems and volumes in all the regions then create and delete alarms as needed.
15
15
16
16
## Invocation
17
-
There are two ways you can invoke this script (Python program). Either from a computer that has Python installed, or you could upload it
18
-
as a Lambda function.
17
+
There are two ways you can invoke this script (Python program). Either from a computer that has Python installed, or you could install it
18
+
as a Lambda function. If you want to run it as a Lambda function, a CloudFormation template is included in the repo that will:
19
+
- Create a role that will allow the Lambda function to:
20
+
- List AWS regions. So it can scan all regions for FSx for ONTAP file systems and volumes.
21
+
- List the FSx for ONTAP file systems.
22
+
- List the FSx volume.
23
+
- List the CloudWatch alarms.
24
+
- List tags for the resources. This is so you can customize the thresholds for the alarms.
25
+
- Create CloudWatch alarms.
26
+
- Delete CloudWatch alarms that it has created (based on alarm names).
27
+
- Create a Lambda function with the Python program.
28
+
- Create a EventBridge schedule that will run the Lambda function on a user defined basis.
29
+
- Create a role that will allow the EventBridge schedule to trigger the Lambda function.
19
30
20
31
### Configuring the program
21
32
Before you can run the program you will need to configure it. You can configure it a few ways:
22
33
* By editing the top part of the program itself where there are the following variable definitions.
23
-
* By setting environment variables.
34
+
* By setting environment variables with the same names as the variables in the program.
24
35
* If running it as a standalone program, via some command line options.
25
36
37
+
:bulb:**NOTE:** The CloudFormation template will prompt for these values when you create the stack and will set the appropriate environment variables for you.
38
+
26
39
Here is the list of variables, and what they define:
27
40
28
41
| Variable | Description |Command Line Option|
@@ -78,19 +91,20 @@ You can run the program in "Dry Run" mode by specifying the `-d` (or `--dryRun`)
78
91
messages showing what it would have done, and not really create or delete any CloudWatch alarms.
79
92
80
93
### Running as a Lambda function
81
-
If you run the program as a Lambda function, you will want to set the timeout to at least two minutes since some of the API calls
94
+
A CloudFormation template is included in the repo that will do the steps below. Otherwise, here are the steps required to install the program as a Lambda function.
95
+
Create a Lambda function and upload the program as the function code. Set the set the timeout to at least five minutes since some of the API calls
82
96
can take a significant amount of "clock time" to run, especially in distant regions.
83
97
84
98
Once you have installed the Lambda function it is recommended to set up a scheduled type EventBridge rule so the function will run on a regular basis.
85
99
86
100
The appropriate permissions will need to be assigned to the Lambda function in order for it to run correctly.
87
101
It doesn't need many permissions. It just needs to be able to:
88
-
* List the FSx for ONTAP file systems
89
-
* List the FSx volume names
90
-
* List the CloudWatch alarms
91
-
* Create CloudWatch alarms
92
-
* Delete CloudWatch alarms
93
-
* Create CloudWatch Log Groups and Log Streams in case you need to diagnose an issue
102
+
* List the FSx for ONTAP file systems.
103
+
* List the FSx volume names.
104
+
* List the CloudWatch alarms.
105
+
* Create CloudWatch alarms.
106
+
* Delete CloudWatch alarms. You can set resource to "arn:aws:cloudwatch:*:${AWS::AccountId}:alarm:FSx-ONTAP-Auto*" to limit the deletion to only the alarms that it created.
107
+
* Create CloudWatch Log Groups and Log Streams in case you need to diagnose an issue.
94
108
95
109
The following permissions are required to run the script (although you could narrow the "Resource" specification to suit your needs.)
96
110
```JSON
@@ -105,7 +119,6 @@ The following permissions are required to run the script (although you could nar
105
119
"fsx:ListTagsForResource",
106
120
"fsx:DescribeVolumes",
107
121
"fsx:DescribeFilesystems",
108
-
"cloudwatch:DeleteAlarms",
109
122
"cloudwatch:DescribeAlarmsForMetric",
110
123
"ec2:DescribeRegions",
111
124
"cloudwatch:DescribeAlarms"
@@ -115,14 +128,22 @@ The following permissions are required to run the script (although you could nar
0 commit comments