Skip to content

Commit

Permalink
Finish snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill Prin committed Mar 17, 2017
1 parent c27959d commit 7b7c0ae
Show file tree
Hide file tree
Showing 3 changed files with 766 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@

// [START monitoring_quickstart]
import com.google.api.Metric;
import com.google.api.MetricDescriptor;
import com.google.api.MonitoredResource;

// Imports the Google Cloud client library
import com.google.cloud.monitoring.spi.v3.MetricServiceClient;

import com.google.monitoring.v3.CreateMetricDescriptorRequest;
import com.google.monitoring.v3.CreateTimeSeriesRequest;
import com.google.monitoring.v3.Point;
import com.google.monitoring.v3.ProjectName;
Expand All @@ -49,6 +51,17 @@ public static void main(String... args) throws Exception {
// Instantiates a client
MetricServiceClient metricServiceClient = MetricServiceClient.create();

final String metricType = "custom.googleapis.com/stores/daily_sales";

// Create the metric descriptor
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();


// Prepares an individual data point
TimeInterval interval = TimeInterval.newBuilder()
.setEndTime(Timestamps.fromMillis(System.currentTimeMillis()))
Expand All @@ -66,7 +79,14 @@ public static void main(String... args) throws Exception {

ProjectName name = ProjectName.create(projectId);

// Prepares the metric descriptor
CreateMetricDescriptorRequest request = CreateMetricDescriptorRequest.newBuilder()
.setNameWithProjectName(name)
.setMetricDescriptor(descriptor)
.build();

metricServiceClient.createMetricDescriptor(request);

// Prepares the metric
Map<String, String> metricLabels = new HashMap<String, String>();
metricLabels.put("store_id", "Pittsburg");
Metric metric = Metric.newBuilder()
Expand Down
Loading

0 comments on commit 7b7c0ae

Please sign in to comment.