- Use at your own risk, no warranties are provided. Refer to the License Summary section.
- This solution will not be supported by Google Cloud.
- Proper testing should be done before running this tool in production.
This sample code is made available under Apache 2 license. See the LICENSE file.
-
Google Cloud Observability Pricing
(Free for the first 150 MiB per billing account https://cloud.google.com/stackdriver/pricing#google-cloud-observability-pricing, https://cloud.google.com/stackdriver/pricing#monitoring-costs) -
Backend e2-micro instance(s) cost. *1 e2-micro is eligible under free usage limit.
(https://cloud.google.com/compute/vm-instance-pricing#e2_sharedcore_machine_type)
- Either Debian or Mac env required.
-
Setup GCP SDK - https://cloud.google.com/sdk
-
Initialize the SDK for the target account
gcloud init
gcloud auth application-default login
https://cloud.google.com/docs/authentication/gcloud#gcloud-credentials -
Replace ISP and Project ID in prereq.sh and run.
bash prereq.shThis will set env variables.
-
*Optional: Disable Restrict external IP addresses to specific VMs constraint if it is defined in the Organization Policy if you want to test the script on GCE.
gcloud resource-manager org-policies set-policy disable_vmExternalIpAccess.json --project=$PROJECT_ID -
Modify backendRegion.csv to list the regions/zones you wish to measure latency.
-
Requires preconfigured VPC Network and Subnet for each of the Regions defined in the backendRegion.csv.
-
Requires the Cloud Monitoring API to be enabled.
-
Requires the following IAM roles/permissions.
At the project level:
- Compute Admin
- Compute Network Admin
- Logging Admin
- Monitoring Admin
- Monitoring Editor
- Monitoring Viewer
At the organization level:
-
Install jq
Example
sudo apt-get install jq
or
brew install jq -
Install dig
Example
sudo apt-get install dnsutils -
Mac Only
- Add full disk access for cron program
https://phoenixnap.com/kb/bash-redirect-stderr-to-stdout - Turn off power nap
https://support.apple.com/en-ca/guide/mac-help/mh40774/mac - *Might be requried on older MacOS versions: Remove quarantine flag from postNetworkLatencyMetrics.sh
sudo xattr -d com.apple.quarantine ./postNetworkLatencyMetrics.sh
-
Replace Backend Region and Zone in backendRegion.csv.
-
Run setup.sh to create backend instances and setup crontab schedules.
bash setup.shThis will setup 2 e2-micro instances per region defined in backendRegion.csv, one for premium and standard network each. It'll then setup crontab schedule to execute every minute that'll collect latency custom metrics to the backend instances. It'll also find out the current machine's public ip address and create a firewall rule that allows icmp to ingress into backend instances. Note that it'll only create backend instances when it can't find any.
-
Run deleteBackend.sh to delete backend instances and ingresss firewall rules.
bash deleteBackend.shThis will delete premium and standard network backend e2-micro instances in the regions defined in backendRegion.csv and also delete ingress firewall rules.
-
Run deleteMetrics.sh to delete the custom metrics.
bash deleteMetrics.sh backendRegion.csvNote that all the accumulated latency custom metrics will be deleted, proceed with caution.