Merge pull request #850 from maunope/updates-quota-monitoring-function
Made sample alert creation optional
This commit is contained in:
commit
4f6cf40c98
|
@ -197,4 +197,4 @@ def main(event, context):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main(None, None)
|
main(None, None)
|
|
@ -168,4 +168,4 @@ def count_effective_limit(config, project_id, network_dict, usage_metric_name,
|
||||||
limit_metric_name, network_dict['network_name'])
|
limit_metric_name, network_dict['network_name'])
|
||||||
metrics.write_data_to_metric(config, project_id, utilization,
|
metrics.write_data_to_metric(config, project_id, utilization,
|
||||||
utilization_metric_name,
|
utilization_metric_name,
|
||||||
network_dict['network_name'])
|
network_dict['network_name'])
|
|
@ -28,7 +28,7 @@ Labels are set with project id (which may differ from the monitoring workspace p
|
||||||
|
|
||||||
<img src="explorer.png" width="640px" alt="GCP Metrics Explorer, usage, limit and utilization view sample">
|
<img src="explorer.png" width="640px" alt="GCP Metrics Explorer, usage, limit and utilization view sample">
|
||||||
|
|
||||||
The solution also creates a basic monitoring alert policy, to demonstrate how to raise alerts when quotas utilization goes over a predefined threshold.
|
The solution can also create a basic monitoring alert policy, to demonstrate how to raise alerts when quotas utilization goes over a predefined threshold, to enable it, set variable `alert_create` to true and reapply main.tf after main.py has run at least one and quota monitoring metrics have been creaed.
|
||||||
|
|
||||||
## Running the blueprint
|
## Running the blueprint
|
||||||
|
|
||||||
|
@ -42,12 +42,13 @@ Clone this repository or [open it in cloud shell](https://ssh.cloud.google.com/c
|
||||||
|
|
||||||
| name | description | type | required | default |
|
| name | description | type | required | default |
|
||||||
|---|---|:---:|:---:|:---:|
|
|---|---|:---:|:---:|:---:|
|
||||||
| [project_id](variables.tf#L35) | Project id that references existing project. | <code>string</code> | ✓ | |
|
| [project_id](variables.tf#L41) | Project id that references existing project. | <code>string</code> | ✓ | |
|
||||||
| [bundle_path](variables.tf#L17) | Path used to write the intermediate Cloud Function code bundle. | <code>string</code> | | <code>"./bundle.zip"</code> |
|
| [alert_create](variables.tf#L17) | Enables the creation of a sample monitoring alert, false by default. | <code>bool</code> | | <code>false</code> |
|
||||||
| [name](variables.tf#L23) | Arbitrary string used to name created resources. | <code>string</code> | | <code>"quota-monitor"</code> |
|
| [bundle_path](variables.tf#L23) | Path used to write the intermediate Cloud Function code bundle. | <code>string</code> | | <code>"./bundle.zip"</code> |
|
||||||
| [project_create](variables.tf#L29) | Create project instead ofusing an existing one. | <code>bool</code> | | <code>false</code> |
|
| [name](variables.tf#L29) | Arbitrary string used to name created resources. | <code>string</code> | | <code>"quota-monitor"</code> |
|
||||||
| [quota_config](variables.tf#L40) | Cloud function configuration. | <code title="object({ filters = list(string) projects = list(string) regions = list(string) })">object({…})</code> | | <code title="{ filters = null projects = null regions = null }">{…}</code> |
|
| [project_create](variables.tf#L35) | Create project instead of using an existing one. | <code>bool</code> | | <code>false</code> |
|
||||||
| [region](variables.tf#L54) | Compute region used in the example. | <code>string</code> | | <code>"europe-west1"</code> |
|
| [quota_config](variables.tf#L46) | Cloud function configuration. | <code title="object({ filters = list(string) projects = list(string) regions = list(string) })">object({…})</code> | | <code title="{ filters = null projects = null regions = null }">{…}</code> |
|
||||||
| [schedule_config](variables.tf#L60) | Schedule timer configuration in crontab format. | <code>string</code> | | <code>"0 * * * *"</code> |
|
| [region](variables.tf#L60) | Compute region used in the example. | <code>string</code> | | <code>"europe-west1"</code> |
|
||||||
|
| [schedule_config](variables.tf#L66) | Schedule timer configuration in crontab format. | <code>string</code> | | <code>"0 * * * *"</code> |
|
||||||
|
|
||||||
<!-- END TFDOC -->
|
<!-- END TFDOC -->
|
||||||
|
|
|
@ -106,7 +106,9 @@ resource "google_project_iam_member" "quota_viewer" {
|
||||||
member = module.cf.service_account_iam_email
|
member = module.cf.service_account_iam_email
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
resource "google_monitoring_alert_policy" "alert_policy" {
|
resource "google_monitoring_alert_policy" "alert_policy" {
|
||||||
|
count = var.alert_create ? 1 : 0
|
||||||
project = module.project.project_id
|
project = module.project.project_id
|
||||||
display_name = "Quota monitor"
|
display_name = "Quota monitor"
|
||||||
combiner = "OR"
|
combiner = "OR"
|
||||||
|
@ -137,6 +139,7 @@ resource "google_monitoring_alert_policy" "alert_policy" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
resource "random_pet" "random" {
|
resource "random_pet" "random" {
|
||||||
length = 1
|
length = 1
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,12 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
variable "alert_create" {
|
||||||
|
description = "Enables the creation of a sample monitoring alert, false by default."
|
||||||
|
type = bool
|
||||||
|
default = false
|
||||||
|
}
|
||||||
|
|
||||||
variable "bundle_path" {
|
variable "bundle_path" {
|
||||||
description = "Path used to write the intermediate Cloud Function code bundle."
|
description = "Path used to write the intermediate Cloud Function code bundle."
|
||||||
type = string
|
type = string
|
||||||
|
@ -27,7 +33,7 @@ variable "name" {
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "project_create" {
|
variable "project_create" {
|
||||||
description = "Create project instead ofusing an existing one."
|
description = "Create project instead of using an existing one."
|
||||||
type = bool
|
type = bool
|
||||||
default = false
|
default = false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue