/** * * * <pre> * The new [custom metric](/monitoring/custom-metrics) * descriptor. * </pre> * * <code>.google.api.MetricDescriptor metric_descriptor = 2;</code> */ private com.google.protobuf.SingleFieldBuilderV3< com.google.api.MetricDescriptor, com.google.api.MetricDescriptor.Builder, com.google.api.MetricDescriptorOrBuilder> getMetricDescriptorFieldBuilder() { if (metricDescriptorBuilder_ == null) { metricDescriptorBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< com.google.api.MetricDescriptor, com.google.api.MetricDescriptor.Builder, com.google.api.MetricDescriptorOrBuilder>( getMetricDescriptor(), getParentForChildren(), isClean()); metricDescriptor_ = null; } return metricDescriptorBuilder_; }
/** * * * <pre> * The new [custom metric](/monitoring/custom-metrics) * descriptor. * </pre> * * <code>.google.api.MetricDescriptor metric_descriptor = 2;</code> */ public com.google.api.MetricDescriptor.Builder getMetricDescriptorBuilder() { onChanged(); return getMetricDescriptorFieldBuilder().getBuilder(); } /**
.setName(projectName.toString()) .setMetricDescriptor(stackDriverMetricDescriptor) .build(); try { metricServiceClient.createMetricDescriptor(request);
/** * Creates a new metric descriptor. User-created metric descriptors define [custom * metrics](/monitoring/custom-metrics). * * <p>Sample code: * * <pre><code> * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) { * ProjectName name = ProjectName.of("[PROJECT]"); * MetricDescriptor metricDescriptor = MetricDescriptor.newBuilder().build(); * MetricDescriptor response = metricServiceClient.createMetricDescriptor(name.toString(), metricDescriptor); * } * </code></pre> * * @param name The project on which to execute the request. The format is * `"projects/{project_id_or_number}"`. * @param metricDescriptor The new [custom metric](/monitoring/custom-metrics) descriptor. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final MetricDescriptor createMetricDescriptor( String name, MetricDescriptor metricDescriptor) { CreateMetricDescriptorRequest request = CreateMetricDescriptorRequest.newBuilder() .setName(name) .setMetricDescriptor(metricDescriptor) .build(); return createMetricDescriptor(request); }
@Test public void export() { FakeMetricExporter fakeMetricExporter = new FakeMetricExporter(); CreateMetricDescriptorExporter exporter = new CreateMetricDescriptorExporter( PROJECT_ID, new FakeMetricServiceClient(mockStub), null, fakeMetricExporter); exporter.export(Arrays.asList(METRIC, METRIC_2)); verify(mockStub, times(2)).createMetricDescriptorCallable(); MetricDescriptor descriptor = StackdriverExportUtils.createMetricDescriptor( METRIC_DESCRIPTOR, PROJECT_ID, CUSTOM_OPENCENSUS_DOMAIN, DEFAULT_DISPLAY_NAME_PREFIX); verify(mockCreateMetricDescriptorCallable, times(1)) .call( eq( CreateMetricDescriptorRequest.newBuilder() .setName("projects/" + PROJECT_ID) .setMetricDescriptor(descriptor) .build())); MetricDescriptor descriptor2 = StackdriverExportUtils.createMetricDescriptor( METRIC_DESCRIPTOR_2, PROJECT_ID, CUSTOM_OPENCENSUS_DOMAIN, DEFAULT_DISPLAY_NAME_PREFIX); verify(mockCreateMetricDescriptorCallable, times(1)) .call( eq( CreateMetricDescriptorRequest.newBuilder() .setName("projects/" + PROJECT_ID) .setMetricDescriptor(descriptor2) .build())); assertThat(fakeMetricExporter.getLastExported()).containsExactly(METRIC, METRIC_2); }
/** * Creates a new metric descriptor. User-created metric descriptors define [custom * metrics](/monitoring/custom-metrics). * * <p>Sample code: * * <pre><code> * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) { * ProjectName name = ProjectName.of("[PROJECT]"); * MetricDescriptor metricDescriptor = MetricDescriptor.newBuilder().build(); * MetricDescriptor response = metricServiceClient.createMetricDescriptor(name, metricDescriptor); * } * </code></pre> * * @param name The project on which to execute the request. The format is * `"projects/{project_id_or_number}"`. * @param metricDescriptor The new [custom metric](/monitoring/custom-metrics) descriptor. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final MetricDescriptor createMetricDescriptor( ProjectName name, MetricDescriptor metricDescriptor) { CreateMetricDescriptorRequest request = CreateMetricDescriptorRequest.newBuilder() .setName(name == null ? null : name.toString()) .setMetricDescriptor(metricDescriptor) .build(); return createMetricDescriptor(request); }
private void createMetricDescriptorIfNecessary(MetricServiceClient client, Meter.Id id, MetricDescriptor.ValueType valueType, @Nullable String statistic) { if (!verifiedDescriptors.contains(id.getName())) { MetricDescriptor descriptor = MetricDescriptor.newBuilder() .setType(metricType(id, statistic)) .setDescription(id.getDescription() == null ? "" : id.getDescription()) .setMetricKind(MetricDescriptor.MetricKind.GAUGE) .setValueType(valueType) .build(); ProjectName name = ProjectName.of(config.projectId()); CreateMetricDescriptorRequest request = CreateMetricDescriptorRequest.newBuilder() .setName(name.toString()) .setMetricDescriptor(descriptor) .build(); if (logger.isTraceEnabled()) { logger.trace("creating metric descriptor:\n{}", request); } try { client.createMetricDescriptor(request); verifiedDescriptors.add(id.getName()); } catch (ApiException e) { logger.warn("failed to create metric descriptor in stackdriver for meter " + id + " {}", e.getCause().getMessage()); } } }
/** * <pre> * The new [custom metric](/monitoring/custom-metrics) * descriptor. * </pre> * * <code>optional .google.api.MetricDescriptor metric_descriptor = 2;</code> */ private com.google.protobuf.SingleFieldBuilderV3< com.google.api.MetricDescriptor, com.google.api.MetricDescriptor.Builder, com.google.api.MetricDescriptorOrBuilder> getMetricDescriptorFieldBuilder() { if (metricDescriptorBuilder_ == null) { metricDescriptorBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< com.google.api.MetricDescriptor, com.google.api.MetricDescriptor.Builder, com.google.api.MetricDescriptorOrBuilder>( getMetricDescriptor(), getParentForChildren(), isClean()); metricDescriptor_ = null; } return metricDescriptorBuilder_; } public final Builder setUnknownFields(
private Builder() { maybeForceBuilderInitialization(); }
/** * <pre> * The new [custom metric](/monitoring/custom-metrics) * descriptor. * </pre> * * <code>optional .google.api.MetricDescriptor metric_descriptor = 2;</code> */ public com.google.api.MetricDescriptor.Builder getMetricDescriptorBuilder() { onChanged(); return getMetricDescriptorFieldBuilder().getBuilder(); } /**
@java.lang.Override protected Builder newBuilderForType( com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } /**
public com.google.monitoring.v3.CreateMetricDescriptorRequest build() { com.google.monitoring.v3.CreateMetricDescriptorRequest result = buildPartial(); if (!result.isInitialized()) { throw newUninitializedMessageException(result); } return result; }
private Builder( com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); } private void maybeForceBuilderInitialization() {
/** * Creates a metric descriptor. * <p> * See: https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.metricDescriptors/create * * @param type The metric type */ void createMetricDescriptor(String type) throws IOException { // [START monitoring_create_metric] // Your Google Cloud Platform project ID String projectId = System.getProperty("projectId"); String metricType = CUSTOM_METRIC_DOMAIN + "/" + type; final MetricServiceClient client = MetricServiceClient.create(); ProjectName name = ProjectName.of(projectId); MetricDescriptor descriptor = MetricDescriptor.newBuilder() .setType(metricType) .setDescription("This is a simple example of a custom metric.") .setMetricKind(MetricDescriptor.MetricKind.GAUGE) .setValueType(MetricDescriptor.ValueType.DOUBLE) .build(); CreateMetricDescriptorRequest request = CreateMetricDescriptorRequest.newBuilder() .setName(name.toString()) .setMetricDescriptor(descriptor) .build(); client.createMetricDescriptor(request); // [END monitoring_create_metric] }
/** * Creates a new metric descriptor. User-created metric descriptors define [custom * metrics](/monitoring/custom-metrics). * * <p>Sample code: * * <pre><code> * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) { * ProjectName name = ProjectName.of("[PROJECT]"); * MetricDescriptor metricDescriptor = MetricDescriptor.newBuilder().build(); * MetricDescriptor response = metricServiceClient.createMetricDescriptor(name, metricDescriptor); * } * </code></pre> * * @param name The project on which to execute the request. The format is * `"projects/{project_id_or_number}"`. * @param metricDescriptor The new [custom metric](/monitoring/custom-metrics) descriptor. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final MetricDescriptor createMetricDescriptor( ProjectName name, MetricDescriptor metricDescriptor) { CreateMetricDescriptorRequest request = CreateMetricDescriptorRequest.newBuilder() .setName(name == null ? null : name.toString()) .setMetricDescriptor(metricDescriptor) .build(); return createMetricDescriptor(request); }
/** * Creates a new metric descriptor. User-created metric descriptors define [custom * metrics](/monitoring/custom-metrics). * * <p>Sample code: * * <pre><code> * try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) { * ProjectName name = ProjectName.of("[PROJECT]"); * MetricDescriptor metricDescriptor = MetricDescriptor.newBuilder().build(); * MetricDescriptor response = metricServiceClient.createMetricDescriptor(name.toString(), metricDescriptor); * } * </code></pre> * * @param name The project on which to execute the request. The format is * `"projects/{project_id_or_number}"`. * @param metricDescriptor The new [custom metric](/monitoring/custom-metrics) descriptor. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final MetricDescriptor createMetricDescriptor( String name, MetricDescriptor metricDescriptor) { CreateMetricDescriptorRequest request = CreateMetricDescriptorRequest.newBuilder() .setName(name) .setMetricDescriptor(metricDescriptor) .build(); return createMetricDescriptor(request); }
private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { super(parent); maybeForceBuilderInitialization(); }
private Builder() { maybeForceBuilderInitialization(); }