Bird
Raised Fist0
GCPcloud~5 mins

Metrics and dashboards in GCP - Commands & Configuration

Choose your learning style10 modes available
Introduction
When you run applications or services, you want to know how well they are working. Metrics and dashboards help you see important numbers and trends in one place so you can fix problems quickly.
When you want to watch how much CPU or memory your app uses over time
When you need to check if your website is responding fast or slow
When you want to get alerts if something goes wrong with your cloud resources
When you want to share performance data with your team in an easy-to-understand view
When you want to compare usage patterns between different time periods
Config File - dashboard.json
dashboard.json
{
  "displayName": "My App Metrics Dashboard",
  "gridLayout": {
    "columns": 2,
    "widgets": [
      {
        "title": "CPU Usage",
        "xyChart": {
          "dataSets": [
            {
              "timeSeriesQuery": {
                "timeSeriesFilter": {
                  "filter": "metric.type=\"compute.googleapis.com/instance/cpu/utilization\"",
                  "aggregation": {
                    "alignmentPeriod": "60s",
                    "perSeriesAligner": "ALIGN_MEAN"
                  }
                }
              }
            }
          ],
          "timeshiftDuration": "0s",
          "yAxis": {
            "label": "CPU Utilization",
            "scale": "LINEAR"
          }
        }
      },
      {
        "title": "Memory Usage",
        "xyChart": {
          "dataSets": [
            {
              "timeSeriesQuery": {
                "timeSeriesFilter": {
                  "filter": "metric.type=\"agent.googleapis.com/memory/usage\"",
                  "aggregation": {
                    "alignmentPeriod": "60s",
                    "perSeriesAligner": "ALIGN_MEAN"
                  }
                }
              }
            }
          ],
          "timeshiftDuration": "0s",
          "yAxis": {
            "label": "Memory Usage",
            "scale": "LINEAR"
          }
        }
      }
    ]
  }
}

This JSON file defines a Google Cloud Monitoring dashboard named "My App Metrics Dashboard".

It has a grid layout with 2 columns and 2 widgets.

The first widget shows CPU usage over time using the metric compute.googleapis.com/instance/cpu/utilization.

The second widget shows memory usage over time using the metric agent.googleapis.com/memory/usage.

Both charts show average values aligned every 60 seconds.

Commands
This command creates a new dashboard in Google Cloud Monitoring using the JSON configuration file. It sets up the widgets to show CPU and memory usage metrics.
Terminal
gcloud monitoring dashboards create --config-from-file=dashboard.json
Expected OutputExpected
Created dashboard: projects/my-project/dashboards/abc12345-6789-0123-4567-89abcdef0123
→
--config-from-file - Specifies the JSON file that contains the dashboard configuration
This command lists all dashboards in your Google Cloud project so you can verify that your new dashboard was created.
Terminal
gcloud monitoring dashboards list
Expected OutputExpected
NAME DISPLAY NAME projects/my-project/dashboards/abc12345-6789-0123-4567-89abcdef0123 My App Metrics Dashboard
This command shows detailed information about the dashboard you created, including its widgets and metrics.
Terminal
gcloud monitoring dashboards describe abc12345-6789-0123-4567-89abcdef0123
Expected OutputExpected
name: projects/my-project/dashboards/abc12345-6789-0123-4567-89abcdef0123 displayName: My App Metrics Dashboard gridLayout: columns: 2 widgets: - title: CPU Usage xyChart: dataSets: - timeSeriesQuery: timeSeriesFilter: filter: 'metric.type="compute.googleapis.com/instance/cpu/utilization"' aggregation: alignmentPeriod: 60s perSeriesAligner: ALIGN_MEAN yAxis: label: CPU Utilization scale: LINEAR - title: Memory Usage xyChart: dataSets: - timeSeriesQuery: timeSeriesFilter: filter: 'metric.type="agent.googleapis.com/memory/usage"' aggregation: alignmentPeriod: 60s perSeriesAligner: ALIGN_MEAN yAxis: label: Memory Usage scale: LINEAR
Key Concept

If you remember nothing else from this pattern, remember: dashboards collect and show important metrics visually so you can quickly understand your system's health.

Common Mistakes
Using incorrect metric type names in the dashboard JSON
The dashboard will not show any data because it cannot find the metrics.
Always use exact metric type names from Google Cloud Monitoring documentation or metric explorer.
Not specifying the alignment period in aggregation
Metrics may appear noisy or inconsistent because data points are not aligned properly.
Set a reasonable alignment period like 60 seconds to smooth data for better visualization.
Forgetting to verify dashboard creation with 'gcloud monitoring dashboards list'
You might think the dashboard was created but it was not, leading to confusion.
Always list dashboards after creation to confirm success.
Summary
Create a dashboard JSON file defining widgets and metrics to monitor.
Use 'gcloud monitoring dashboards create' to deploy the dashboard to Google Cloud.
Verify the dashboard exists and inspect its details with 'gcloud monitoring dashboards list' and 'describe'.

Practice

(1/5)
1. What is the main purpose of a dashboard in Google Cloud Monitoring?
easy
A. To visually display metrics and help monitor cloud resources
B. To store data permanently for backup
C. To write code for cloud functions
D. To manage user permissions

Solution

  1. Step 1: Understand what dashboards do

    Dashboards show visual summaries of metrics to help users watch cloud resources easily.
  2. Step 2: Identify the correct purpose

    Among the options, only displaying metrics visually matches the dashboard's role.
  3. Final Answer:

    To visually display metrics and help monitor cloud resources -> Option A
  4. Quick Check:

    Dashboard = Visual metric display [OK]
Hint: Dashboards show data visually, not store or code [OK]
Common Mistakes:
  • Confusing dashboards with storage or coding tools
  • Thinking dashboards manage permissions
2. Which of the following is the correct way to filter CPU usage metric in a Google Cloud Monitoring dashboard widget?
easy
A. filter: cpu_usage_metric
B. metric = "cpu_usage"
C. metric.type = "compute.googleapis.com/instance/cpu/utilization"
D. metric.cpu = "usage"

Solution

  1. Step 1: Recall correct metric filter syntax

    Google Cloud Monitoring uses metric.type with full metric names like "compute.googleapis.com/instance/cpu/utilization".
  2. Step 2: Match options to syntax

    Only metric.type = "compute.googleapis.com/instance/cpu/utilization" uses the correct full metric.type format.
  3. Final Answer:

    metric.type = "compute.googleapis.com/instance/cpu/utilization" -> Option C
  4. Quick Check:

    Correct metric filter uses metric.type with full name [OK]
Hint: Use full metric.type path for filters [OK]
Common Mistakes:
  • Using incomplete or shorthand metric names
  • Wrong filter keywords like 'filter:' or 'metric.cpu'
3. Given this snippet for a dashboard widget filter:
metric.type = "compute.googleapis.com/instance/disk/read_bytes_count" AND resource.label.instance_id = "12345"
What does this filter show?
medium
A. Disk read bytes count for instance with ID 12345
B. CPU usage for instance 12345
C. Network bytes sent by instance 12345
D. Disk write bytes count for instance 12345

Solution

  1. Step 1: Analyze metric.type value

    The metric is "disk/read_bytes_count", which means bytes read from disk.
  2. Step 2: Check resource label filter

    The filter limits data to instance with ID "12345".
  3. Final Answer:

    Disk read bytes count for instance with ID 12345 -> Option A
  4. Quick Check:

    Disk read bytes + instance filter = Disk read bytes count for instance with ID 12345 [OK]
Hint: Match metric.type and resource label to understand filter [OK]
Common Mistakes:
  • Confusing read bytes with write bytes
  • Mixing disk metrics with CPU or network
4. You created a dashboard widget but it shows no data. Which of these is the most likely cause?
medium
A. The user has read access to the project
B. The dashboard widget is set to refresh every 5 seconds
C. The dashboard has more than 5 widgets
D. The metric filter uses an incorrect metric type name

Solution

  1. Step 1: Identify common reasons for no data

    Incorrect metric type names cause filters to match no data, so widget shows empty.
  2. Step 2: Evaluate other options

    Refresh rate or widget count do not prevent data display; read access is needed but assumed correct here.
  3. Final Answer:

    The metric filter uses an incorrect metric type name -> Option D
  4. Quick Check:

    No data usually means wrong metric filter [OK]
Hint: Check metric type spelling if no data shows [OK]
Common Mistakes:
  • Blaming refresh rate or widget count
  • Ignoring permission issues but assuming access is correct
5. You want to create a dashboard showing both CPU utilization and network bytes sent for multiple instances, but only for instances tagged with "env:production". Which approach is best?
hard
A. Create a widget with a filter for "env:production" but only for disk metrics
B. Create two widgets with filters for CPU and network metrics, each filtering resource labels for "env:production"
C. Create a widget filtering only CPU metrics for all instances, ignoring network metrics
D. Create one widget showing CPU and network metrics without filters, then manually check instance tags

Solution

  1. Step 1: Understand the requirement

    You need to show two different metrics (CPU and network) filtered by instance tag "env:production".
  2. Step 2: Choose filtering and widget setup

    Best practice is separate widgets for each metric with proper filters on resource labels for the tag.
  3. Step 3: Evaluate other options

    Options A, B, and C either miss filtering, use wrong metrics, or ignore one of the required metrics.
  4. Final Answer:

    Create two widgets with filters for CPU and network metrics, each filtering resource labels for "env:production" -> Option B
  5. Quick Check:

    Separate widgets + correct filters = best dashboard [OK]
Hint: Use separate widgets with filters for each metric [OK]
Common Mistakes:
  • Trying to combine unrelated metrics in one widget without filters
  • Ignoring resource label filters for tags
  • Showing irrelevant metrics
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard