Search in sources :

Example 1 with MetricServiceClient

use of com.google.bigtable.repackaged.com.google.cloud.monitoring.v3.MetricServiceClient in project instrumentation-java by census-instrumentation.

the class StackdriverStatsExporter method createInternal.

// Use createInternal() (instead of constructor) to enforce singleton.
private static void createInternal(@Nullable Credentials credentials, String projectId, Duration exportInterval, MonitoredResource monitoredResource, @Nullable String metricNamePrefix, @Nullable String displayNamePrefix, Map<LabelKey, LabelValue> constantLabels, Duration deadline, @Nullable MetricServiceStub stub) throws IOException {
    synchronized (monitor) {
        checkState(instance == null, "Stackdriver stats exporter is already created.");
        final MetricServiceClient client;
        if (stub == null) {
            metricServiceClient = createMetricServiceClient(credentials, deadline);
            client = metricServiceClient;
        } else {
            client = MetricServiceClient.create(stub);
        }
        instance = new StackdriverStatsExporter(projectId, client, exportInterval, monitoredResource, metricNamePrefix, displayNamePrefix, constantLabels);
    }
}
Also used : MetricServiceClient(com.google.cloud.monitoring.v3.MetricServiceClient)

Example 2 with MetricServiceClient

use of com.google.bigtable.repackaged.com.google.cloud.monitoring.v3.MetricServiceClient in project instrumentation-java by census-instrumentation.

the class StackdriverStatsExporterTest method createMetricServiceClient_WithoutCredentials.

@Test
public void createMetricServiceClient_WithoutCredentials() {
    try {
        MetricServiceClient client;
        synchronized (StackdriverStatsExporter.monitor) {
            client = StackdriverStatsExporter.createMetricServiceClient(null, DEFAULT_DEADLINE);
        }
        assertThat(client.getSettings().getCredentialsProvider()).isInstanceOf(GoogleCredentialsProvider.class);
        assertThat(client.getSettings().getTransportChannelProvider()).isInstanceOf(InstantiatingGrpcChannelProvider.class);
        // There's no way to get HeaderProvider from TransportChannelProvider.
        assertThat(client.getSettings().getTransportChannelProvider().needsHeaders()).isFalse();
    } catch (IOException e) {
    // This test depends on the Application Default Credentials settings (environment variable
    // GOOGLE_APPLICATION_CREDENTIALS). Some hosts may not have the expected environment settings
    // and this test should be skipped in that case.
    }
}
Also used : MetricServiceClient(com.google.cloud.monitoring.v3.MetricServiceClient) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with MetricServiceClient

use of com.google.bigtable.repackaged.com.google.cloud.monitoring.v3.MetricServiceClient in project java-docs-samples by GoogleCloudPlatform.

the class WorkloadGeneratorTest method testPipeline.

@Test
public void testPipeline() throws IOException, InterruptedException {
    String workloadJobName = "bigtable-workload-generator-test-" + new Date().getTime();
    final int WORKLOAD_DURATION = 10;
    final int WAIT_DURATION = WORKLOAD_DURATION * 60 * 1000;
    int rate = 1000;
    BigtableWorkloadOptions options = PipelineOptionsFactory.create().as(BigtableWorkloadOptions.class);
    options.setBigtableInstanceId(instanceId);
    options.setBigtableTableId(TABLE_ID);
    options.setWorkloadRate(rate);
    options.setRegion(REGION_ID);
    options.setWorkloadDurationMinutes(WORKLOAD_DURATION);
    options.setRunner(DataflowRunner.class);
    options.setJobName(workloadJobName);
    final PipelineResult pipelineResult = WorkloadGenerator.generateWorkload(options);
    MetricServiceClient metricServiceClient = MetricServiceClient.create();
    ProjectName name = ProjectName.of(projectId);
    // Wait X minutes and then get metrics for the X minute period.
    Thread.sleep(WAIT_DURATION);
    long startMillis = System.currentTimeMillis() - WAIT_DURATION;
    TimeInterval interval = TimeInterval.newBuilder().setStartTime(Timestamps.fromMillis(startMillis)).setEndTime(Timestamps.fromMillis(System.currentTimeMillis())).build();
    ListTimeSeriesRequest request = ListTimeSeriesRequest.newBuilder().setName(name.toString()).setFilter("metric.type=\"bigtable.googleapis.com/server/request_count\"").setInterval(interval).build();
    ListTimeSeriesPagedResponse response = metricServiceClient.listTimeSeries(request);
    long startRequestCount = 0;
    long endRequestCount = 0;
    for (TimeSeries ts : response.iterateAll()) {
        startRequestCount = ts.getPoints(0).getValue().getInt64Value();
        endRequestCount = ts.getPoints(ts.getPointsCount() - 1).getValue().getInt64Value();
    }
    assertThat(endRequestCount - startRequestCount > rate);
    // Stop the running job.
    String jobId = ((DataflowPipelineJob) pipelineResult).getJobId();
    DataflowClient client = DataflowClient.create(options);
    Job job = client.getJob(jobId);
    assertThat(job.getCurrentState().equals("JOB_STATE_CANCELLED"));
}
Also used : TimeSeries(com.google.bigtable.repackaged.com.google.monitoring.v3.TimeSeries) MetricServiceClient(com.google.bigtable.repackaged.com.google.cloud.monitoring.v3.MetricServiceClient) TimeInterval(com.google.bigtable.repackaged.com.google.monitoring.v3.TimeInterval) ProjectName(com.google.bigtable.repackaged.com.google.monitoring.v3.ProjectName) PipelineResult(org.apache.beam.sdk.PipelineResult) ListTimeSeriesPagedResponse(com.google.bigtable.repackaged.com.google.cloud.monitoring.v3.MetricServiceClient.ListTimeSeriesPagedResponse) Date(java.util.Date) ListTimeSeriesRequest(com.google.bigtable.repackaged.com.google.monitoring.v3.ListTimeSeriesRequest) BigtableWorkloadOptions(bigtable.WorkloadGenerator.BigtableWorkloadOptions) DataflowPipelineJob(org.apache.beam.runners.dataflow.DataflowPipelineJob) DataflowClient(org.apache.beam.runners.dataflow.DataflowClient) Job(com.google.api.services.dataflow.model.Job) DataflowPipelineJob(org.apache.beam.runners.dataflow.DataflowPipelineJob) Test(org.junit.Test)

Example 4 with MetricServiceClient

use of com.google.bigtable.repackaged.com.google.cloud.monitoring.v3.MetricServiceClient in project java-docs-samples by GoogleCloudPlatform.

the class Snippets method listTimeSeriesAggregrate.

/**
 * Demonstrates listing time series and aggregating them.
 */
void listTimeSeriesAggregrate() throws IOException {
    // [START monitoring_read_timeseries_align]
    MetricServiceClient metricServiceClient = MetricServiceClient.create();
    String projectId = System.getProperty("projectId");
    ProjectName name = ProjectName.of(projectId);
    // Restrict time to last 20 minutes
    long startMillis = System.currentTimeMillis() - ((60 * 20) * 1000);
    TimeInterval interval = TimeInterval.newBuilder().setStartTime(Timestamps.fromMillis(startMillis)).setEndTime(Timestamps.fromMillis(System.currentTimeMillis())).build();
    Aggregation aggregation = Aggregation.newBuilder().setAlignmentPeriod(Duration.newBuilder().setSeconds(600).build()).setPerSeriesAligner(Aggregation.Aligner.ALIGN_MEAN).build();
    ListTimeSeriesRequest.Builder requestBuilder = ListTimeSeriesRequest.newBuilder().setName(name.toString()).setFilter("metric.type=\"compute.googleapis.com/instance/cpu/utilization\"").setInterval(interval).setAggregation(aggregation);
    ListTimeSeriesRequest request = requestBuilder.build();
    ListTimeSeriesPagedResponse response = metricServiceClient.listTimeSeries(request);
    System.out.println("Got timeseries: ");
    for (TimeSeries ts : response.iterateAll()) {
        System.out.println(ts);
    }
// [END monitoring_read_timeseries_align]
}
Also used : Aggregation(com.google.monitoring.v3.Aggregation) TimeSeries(com.google.monitoring.v3.TimeSeries) MetricServiceClient(com.google.cloud.monitoring.v3.MetricServiceClient) TimeInterval(com.google.monitoring.v3.TimeInterval) ProjectName(com.google.monitoring.v3.ProjectName) ListTimeSeriesPagedResponse(com.google.cloud.monitoring.v3.MetricServiceClient.ListTimeSeriesPagedResponse) ListTimeSeriesRequest(com.google.monitoring.v3.ListTimeSeriesRequest)

Example 5 with MetricServiceClient

use of com.google.bigtable.repackaged.com.google.cloud.monitoring.v3.MetricServiceClient in project java-docs-samples by GoogleCloudPlatform.

the class Snippets method deleteMetricDescriptor.

/**
 * Delete a metric descriptor.
 *
 * @param name Name of metric descriptor to delete
 */
void deleteMetricDescriptor(String name) throws IOException {
    // [START monitoring_delete_metric]
    String projectId = System.getProperty("projectId");
    final MetricServiceClient client = MetricServiceClient.create();
    MetricDescriptorName metricName = MetricDescriptorName.of(projectId, name);
    client.deleteMetricDescriptor(metricName);
    System.out.println("Deleted descriptor " + name);
// [END monitoring_delete_metric]
}
Also used : MetricServiceClient(com.google.cloud.monitoring.v3.MetricServiceClient) MetricDescriptorName(com.google.monitoring.v3.MetricDescriptorName)

Aggregations

MetricServiceClient (com.google.cloud.monitoring.v3.MetricServiceClient)26 ProjectName (com.google.monitoring.v3.ProjectName)15 TimeInterval (com.google.monitoring.v3.TimeInterval)10 TimeSeries (com.google.monitoring.v3.TimeSeries)8 ListTimeSeriesRequest (com.google.monitoring.v3.ListTimeSeriesRequest)6 CreateTimeSeriesRequest (com.google.monitoring.v3.CreateTimeSeriesRequest)5 Metric (com.google.api.Metric)4 MetricDescriptor (com.google.api.MetricDescriptor)4 MonitoredResource (com.google.api.MonitoredResource)4 MonitoredResourceDescriptor (com.google.api.MonitoredResourceDescriptor)4 ListTimeSeriesPagedResponse (com.google.cloud.monitoring.v3.MetricServiceClient.ListTimeSeriesPagedResponse)4 Point (com.google.monitoring.v3.Point)4 TypedValue (com.google.monitoring.v3.TypedValue)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 CreateMetricDescriptorRequest (com.google.monitoring.v3.CreateMetricDescriptorRequest)3 ListMetricDescriptorsRequest (com.google.monitoring.v3.ListMetricDescriptorsRequest)3 MonitoredResourceDescriptorName (com.google.monitoring.v3.MonitoredResourceDescriptorName)3 Test (org.junit.Test)3 Aggregation (com.google.monitoring.v3.Aggregation)2