0
0
GCPcloud~5 mins

Cloud Monitoring overview in GCP - Commands & Configuration

Choose your learning style9 modes available
Introduction
Cloud Monitoring helps you watch your applications and services in the cloud. It collects data about how your systems are working and shows it in easy-to-understand charts and alerts. This helps you find and fix problems quickly.
When you want to see how much CPU or memory your cloud servers are using.
When you need to get alerts if your website goes down or slows down.
When you want to track the number of users visiting your app over time.
When you want to check if your cloud database is responding fast enough.
When you want to create dashboards to share system health with your team.
Commands
This command creates a new monitoring dashboard in Google Cloud using the settings defined in the dashboard.json file. Dashboards help you visualize metrics in one place.
Terminal
gcloud monitoring dashboards create --config-from-file=dashboard.json
Expected OutputExpected
Created dashboard: projects/my-project/dashboards/1234567890abcdef
--config-from-file - Specifies the JSON file that contains the dashboard configuration.
This command lists all available metrics you can monitor in your Google Cloud project. It helps you find what data you can track.
Terminal
gcloud monitoring metrics list
Expected OutputExpected
NAME compute.googleapis.com/instance/cpu/utilization compute.googleapis.com/instance/disk/read_bytes_count compute.googleapis.com/instance/network/received_bytes_count ...
This command creates an alerting policy that sends notifications when CPU usage on a virtual machine goes above 80% for more than 60 seconds.
Terminal
gcloud monitoring policies create --notification-channels=projects/my-project/notificationChannels/1234567890abcdef --condition-display-name="High CPU Usage" --condition-filter="metric.type=\"compute.googleapis.com/instance/cpu/utilization\" AND resource.type=\"gce_instance\"" --condition-threshold-value=0.8 --condition-comparison=COMPARISON_GT --condition-duration=60s
Expected OutputExpected
Created alerting policy: projects/my-project/alertPolicies/abcdef1234567890
--notification-channels - Specifies where to send alerts, like email or SMS.
--condition-filter - Defines which metric and resource to watch.
--condition-threshold-value - Sets the value that triggers the alert.
This command shows all the monitoring dashboards you have created in your project. It helps you check your visual monitoring setups.
Terminal
gcloud monitoring dashboards list
Expected OutputExpected
NAME DISPLAY_NAME projects/my-project/dashboards/1234567890abcdef My CPU Dashboard projects/my-project/dashboards/abcdef1234567890 Network Stats
Key Concept

If you remember nothing else from this pattern, remember: Cloud Monitoring collects and shows data about your cloud resources so you can keep them healthy and fix problems fast.

Common Mistakes
Not specifying the correct project or resource in commands.
The commands will apply to the wrong project or resource, so you won't see or affect the data you want.
Always check and set the correct project with 'gcloud config set project my-project' before running monitoring commands.
Creating alert policies without notification channels.
Alerts will trigger but no one will be notified, so problems can go unnoticed.
Create and specify notification channels like email or SMS before creating alert policies.
Summary
Use 'gcloud monitoring dashboards create' with a JSON file to set up visual dashboards.
List available metrics with 'gcloud monitoring metrics list' to know what you can track.
Create alert policies with 'gcloud monitoring policies create' to get notified about issues.
Check your dashboards anytime with 'gcloud monitoring dashboards list' to monitor system health.