Complete the code to create a metric descriptor for a custom metric in Google Cloud Monitoring.
metric_descriptor = monitoring_v3.MetricDescriptor() metric_descriptor.type = "custom.googleapis.com/[1]" metric_descriptor.metric_kind = monitoring_v3.MetricDescriptor.MetricKind.GAUGE metric_descriptor.value_type = monitoring_v3.MetricDescriptor.ValueType.DOUBLE
The metric type must be a valid custom metric name. Here, "memory_usage" is used as an example custom metric.
Complete the code to create a dashboard widget that shows a line chart of CPU utilization.
widget = {
"xyChart": {
"dataSets": [{
"timeSeriesQuery": {
"timeSeriesFilter": {
"filter": "metric.type = \"compute.googleapis.com/instance/cpu/utilization\"",
"aggregation": {
"perSeriesAligner": monitoring_v3.Aggregation.Aligner.[1]
}
}
}
}]
}
}ALIGN_MEAN calculates the average CPU utilization over the alignment period, which is common for line charts.
Fix the error in the alerting policy condition filter to monitor high memory usage.
condition = {
"conditionThreshold": {
"filter": "metric.type = \"compute.googleapis.com/instance/memory/usage_bytes\" AND resource.type = [1]",
"comparison": monitoring_v3.ComparisonType.COMPARISON_GT,
"thresholdValue": 8000000000,
"duration": "300s"
}
}The correct resource type for Google Compute Engine VM instances is "gce_instance".
Fill both blanks to create a dashboard widget that displays a stacked bar chart of network traffic by direction.
widget = {
"xyChart": {
"chartOptions": {
"mode": monitoring_v3.XyChart.ChartOptions.Mode.[1],
"chartType": monitoring_v3.XyChart.ChartType.[2]
},
"dataSets": [{
"timeSeriesQuery": {
"timeSeriesFilter": {
"filter": "metric.type = \"compute.googleapis.com/instance/network/received_bytes_count\" OR metric.type = \"compute.googleapis.com/instance/network/sent_bytes_count\"",
"aggregation": {
"perSeriesAligner": monitoring_v3.Aggregation.Aligner.ALIGN_SUM
}
}
}
}]
}
}To show a stacked bar chart, set mode to STACKED and chart type to BAR.
Fill all three blanks to define an alerting policy that triggers when average CPU utilization exceeds 70% for 5 minutes.
alert_policy = {
"conditions": [{
"conditionThreshold": {
"filter": "metric.type = \"compute.googleapis.com/instance/cpu/utilization\" AND resource.type = \"[1]\"",
"comparison": monitoring_v3.ComparisonType.[2],
"thresholdValue": [3],
"duration": "300s"
}
}]
}The resource type is "gce_instance". The comparison is greater than (COMPARISON_GT). The threshold value is 0.7 (70%).