metric

command module
v0.40.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

README

Google Cloud Monitoring exporter example

This example shows how to use go.opentelemetry.io/otel to instrument a simple Go application with metrics and export the metrics to Google Cloud Monitoring

Build and run the application

Before sending metrics to Google Cloud Monitoring, confirm the Cloud Monitoring API is enabled for the project you will use to access the API as described in this document.

You can find your current project ID using the command:

$ gcloud config get-value project
Your active configuration is: [example]
foo-project-214354

In this case, the project ID is foo-project-214354.

Next, set this project ID to the environment variable GOOGLE_PROJECT_ID using the following command:

export GOOGLE_PROJECT_ID=$(gcloud config get-value project)

Once you ensure the API is enabled, then build the example application and run the executable.

$ go build -o metrics
$ ./metrics
2020/06/11 21:11:15 Most recent data: counter 110, observer 13.45
2020/06/11 21:11:15 Most recent data: counter 160, observer 16.02
2020/06/11 21:11:15 Most recent data: counter 134, observer 14.33
2020/06/11 21:11:15 Most recent data: counter 125, observer 15.12
...

To ensure you have enough data to create interesting charts for the Counter and Observer metrics generated by the example, keep the application running for at least five minutes.

Create dashboard

https://console.cloud.google.com/monitoring/dashboards?project=

Once you think you have sent sufficient data, then create a dashboard. If you are learning how to use Google Cloud Monitoring, you can follow how to use charts step by step on this document.

When filling in the Find resource type and metric box, use the metric names "custom.googleapis.com/opentelemetry/counter-a" and "custom.googleapis.com/opentelemetry/observer-a".

If you already know how to use Cloud Monitoring and would just like to confirm the data is properly received, you can run the dashboard creation script bundled in this directory.

$ ./create_dashboard.sh

This script creates a dashboard titled "OpenTelemetry exporter example/metric".

You should be able to view line charts like below once you create the dashboard.

2 charts in dashboard

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL