Stackdriver is GCP's tool for monitoring, logging and diagnostics. Stackdriver gives you access to many different kinds of signals from your infrastructure platforms, virtual machines, containers, middleware and application tier, logs, metrics and traces. It gives you insight into your application's health, performance and availability. So if issues occur, you can fix them faster. Here are the core components of Stackdriver: Monitoring, Logging, Trace, Error Reporting and Debugging.
Example of using GCP Deployment Manager and Stackdriver
• Confirm the following API are enabled via API & Service module:
Cloud Deployment Manager v2 API
Cloud Runtime Configuration API
Cloud Monitoring API
• Task: Create a Deployment Manager deployment
In GCP console, on the top right toolbar, click the Open Cloud Shell button (Activate Cloud Shell). Click Continue. For your convenience, place the zone that Qwiklabs assigned you to into an environment variable called MY_ZONE. At the Cloud Shell prompt, type this partial command:
followed by the zone that Qwiklabs assigned you to. Your complete command will look like this:
At the Cloud Shell prompt, download an editable Deployment Manager template:
gsutil cp gs://cloud-training/gcpfcoreinfra/mydeploy.yaml mydeploy.yaml
Insert your Google Cloud Platform project ID into the file in place of the string PROJECT_ID using this command:
sed -i -e 's/PROJECT_ID/'$DEVSHELL_PROJECT_ID/ mydeploy.yaml
Insert your assigned Google Cloud Platform zone into the file in place of the string ZONE using this command:
sed -i -e 's/ZONE/'$MY_ZONE/ mydeploy.yaml
View the mydeploy.yaml file, with your modifications, with this command:
The file will look something like this:
resources: - name: my-vm type: compute.v1.instance properties: zone: us-west1-b machineType: zones/us-west1-b/machineTypes/n1-standard-1 metadata: items: - key: startup-script value: "apt-get update" disks: - deviceName: boot type: PERSISTENT boot: true autoDelete: true initializeParams: sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-9-stretch-v20180806 networkInterfaces: - network: https://www.googleapis.com/compute/v1/projects/qwiklabs-gcp-02-asdg/global/networks/default accessConfigs: - name: External NAT type: ONE_TO_ONE_NAT
Build a deployment from the template:
gcloud deployment-manager deployments create my-first-depl --config mydeploy.yaml
When the deployment operation is complete, the gcloud command displays a list of the resources named in the template and their current state.
Confirm that the deployment was successful. In the GCP Console, on the Navigation menu (Navigation menu), click Compute Engine > VM instances called my-vm has been created, as specified by the template.
Click on the VM instance's name to open its VM instance details screen.
Scroll down to the Custom metadata section. Confirm that the startup script you specified in your Deployment Manager template has been installed.
•Task : Update a Deployment Manager deployment
Return to your Cloud Shell prompt. Launch the nano text editor to edit the mydeploy.yaml file:
Find the line that sets the value of the startup script, value: "apt-get update", and edit it so that it looks like this:
value: "apt-get update; apt-get install nginx-light -y"
Do not disturb the spaces at the beginning of the line. The YAML templating language relies on indented lines as part of its syntax. As you edit the file, be sure that the v in the word value in this new line is immediately below the k in the word key on the line above it.
Press Ctrl+O and then press Enter to save your edited file.
Press Ctrl+X to exit the nano text editor.
Return to your Cloud Shell prompt. Enter this command to cause Deployment Manager to update your deployment to install the new startup script:
gcloud deployment-manager deployments update my-first-depl --config mydeploy.yaml
Wait for the gcloud command to display a message confirming that the update operation was completed successfully. In the GCP console, on the Navigation menu (Navigation menu), click Compute Engine > VM instances. Click on the my-vm VM instance's name to open its VM instance details pane. Scroll down to the Custom metadata section.
• Task: View the Load on a VM using Cloud Monitoring, In the GCP Console, on the Navigation menu (Navigation menu), click Compute Engine > VM instances.
To open a command prompt on the my-vm instance, click SSH in its row in the VM instances list.
In the ssh session on my-vm, execute this command to create a CPU load:
dd if=/dev/urandom | gzip -9 >> /dev/null &
This Linux pipeline forces the CPU to work on compressing a continuous stream of random data.
• Create a Monitoring workspace
You will now setup a Monitoring workspace that's tied to your Qwiklabs GCP Project. The following steps create a new account that has a free trial of Monitoring.
In the Google Cloud Platform Console, click on Navigation menu > Monitoring.
Wait for your workspace to be provisioned. When the Monitoring dashboard opens, your workspace is ready.
Click on Settings option from the left panel and confirm that the GCP project which Qwiklabs created for you is shown under the GCP Projects section.
Under the Settings tab menu, click Agent. Using your VM's open SSH window and the code shown on the Agents page, install both the Monitoring and Logging agents on your project's VM.
The Monitoring agent is a collectd-based daemon that gathers system and application metrics from virtual machine instances and sends them to Monitoring. By default, the Monitoring agent collects disk, CPU, network, and process metrics. Configuring the Monitoring agent allows third-party applications to get the full list of agent metrics. Learn more
Monitoring agent install script
curl -sSO https://dl.google.com/cloudagents/install-monitoring-agent.sh
sudo bash install-monitoring-agent.sh
The Logging agent streams logs from your VM instances and from selected third-party software packages to Logging. It is a best practice to run the Logging agent on all your VM instances. Learn more
Logging agent install script
curl -sSO https://dl.google.com/cloudagents/install-logging-agent.sh
sudo bash install-logging-agent.sh