Complete the code to create a basic alert policy in Cloud Monitoring using gcloud CLI.
gcloud monitoring policies create --notification-channels=[1] --condition-display-name="High CPU Usage" --condition-filter="metric.type=\"compute.googleapis.com/instance/cpu/utilization\"" --condition-threshold-value=0.8
The --notification-channels flag requires the ID of a notification channel, such as an email channel, to send alerts.
Complete the code to list all monitored resource descriptors in Cloud Monitoring.
gcloud monitoring resource-descriptors [1]describe which shows details for one resource only.create or delete which modify resources.The list command shows all monitored resource descriptors available in Cloud Monitoring.
Fix the error in the command to create a metric descriptor for custom metrics.
gcloud monitoring metric-descriptors create [1] --metric-kind=GAUGE --value-type=DOUBLE --unit="1" --description="Custom metric"
Custom metric types must start with custom.googleapis.com/ to be valid in Cloud Monitoring.
Fill both blanks to create a filter for CPU utilization metric with resource type 'gce_instance'.
filter="metric.type=[1] AND resource.type=[2]"
The metric type for CPU utilization on Google Compute Engine instances is compute.googleapis.com/instance/cpu/utilization and the resource type is gce_instance.
Fill all three blanks to create a JSON snippet for a Cloud Monitoring alert policy condition.
{
"displayName": "High Memory Usage",
"condition": {
"displayName": [1],
"conditionThreshold": {
"filter": [2],
"comparison": [3]
}
}
}The displayName is a string describing the condition. The filter specifies the metric type for memory utilization. The comparison uses COMPARISON_GT to trigger when usage is greater than the threshold.