NOTE: While Opentelemetry Metrics API is stable, the SDK is still Alpha in OpenTelemetry, and this exporter is not guaranteed to work across versions.
Opentelemetry Google Monitoring Metrics Exporter allows users to send collected metrics to Google Cloud.
Google Cloud Monitoring provides visibility into the performance, uptime, and overall health of cloud-powered applications. It collects metrics, events, and metadata from Google Cloud, Amazon Web Services, hosted uptime probes, application instrumentation, and a variety of common application components including Cassandra, Nginx, Apache Web Server, Elasticsearch, and many others. Operations ingests that data and generates insights via dashboards, charts, and alerts. Cloud Monitoring alerting helps you collaborate by integrating with Slack, PagerDuty, and more.
Google Cloud Monitoring is a managed service provided by Google Cloud Platform. Google Cloud Monitoring requires to set up "Workspace" in advance. The guide to create a new Workspace is available on the official document.
TODO(jsuereth): Write this.
See the code example for details.
TODO(jsuereth): Write this section.
You can configure the Cloud Monitoring Metrics Exporter via the following setup:
import io.opentelemetry.api.metrics.MeterProvider;
import io.opentelemetry.sdk.metrics.export.MetricExporter;
import io.opentelemetry.sdk.metrics.export.PeriodicMetricReader;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import com.google.cloud.opentelemetry.metric.MetricConfiguration;
import com.google.cloud.opentelemetry.metric.MetricDescriptorStrategy;
import com.google.cloud.opentelemetry.metric.GoogleCloudMetricExporter;
import java.util.Collections;
// Configure the exporter in code.
MetricExporter cloudMonitoringExporter =
GoogleCloudMetricExporter.createWithConfiguration(
MetricConfiguration.builder()
// Configure the cloud project id. Note: this is autodiscovered by default.
.setProjectId(...)
// Set the credentials to use when writing to the Cloud Monitoring API
.setCredentials(...)
// Set the Deadline for exporting to Cloud Monitoring before giving up.
.setDeadline(...)
// Configure a strategy for how/when to configure metric descriptors.
.setMetricDescriptorStrategy(MetricDescriptorStrategy.SEND_ONCE)
.build()
);
// Now set up PeriodicMetricReader to use this Exporter
MeterProvider provider = SdkMeterProvider.builder()
.registerMetricReader(
// Set collection interval to 20 seconds.
// See https://cloud.google.com/monitoring/quotas#custom_metrics_quotas
// Rate at which data can be written to a single time series: one point each 10
// seconds.
PeriodicMetricReader.builder(metricExporter)
.setInterval(java.time.Duration.ofSeconds(20))
.build())
.build();
Configuration | Environment Variable | JVM Property | Description | Default |
---|---|---|---|---|
projectId | GOOGLE_CLOUD_PROJECT or GOOGLE_APPLICATION_CREDENTIALS | ??? | The cloud project id. This is autodiscovered. | The autodiscovered value. |
credentials | GOOGLE_APPLICATION_CREDENTIALS | N/A | Credentials to use when talking to Cloud Monitoring API. | App Engine, Cloud Shell, GCE built-in or provided by gcloud auth application-default login |
deadline | ??? | ??? | The deadline limit on export calls to Cloud Monitoring API | 12 seconds |
metricDescriptorStrategy | ??? | ??? | How to adapt OpenTelemetry metric definition into google cloud. ALWAYS_SEND will try to create metric descriptors on every export. SEND_ONCE will try to create metric descriptors once per Java instance/classloader. NEVER_SEND will rely on Cloud Monitoring's auto-generated MetricDescriptors from time series. |
SEND_ONCE |