Search in sources :

Example 11 with MetricServiceClient

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

the class TimeSeriesHeadersList method listTimeSeriesHeaders.

public static void listTimeSeriesHeaders(String projectId, String filter) throws ApiException, IOException {
    // once, and can be reused for multiple requests.
    try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
        ProjectName projectName = 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();
        // Prepares the list time series request with headers
        ListTimeSeriesRequest request = ListTimeSeriesRequest.newBuilder().setName(projectName.toString()).setFilter(filter).setInterval(interval).setView(ListTimeSeriesRequest.TimeSeriesView.HEADERS).build();
        // Send the request to list the time series
        MetricServiceClient.ListTimeSeriesPagedResponse response = metricServiceClient.listTimeSeries(request);
        // Process the response
        System.out.println("Got timeseries headers: ");
        response.iterateAll().forEach(timeSeries -> System.out.println(timeSeries));
    }
}
Also used : MetricServiceClient(com.google.cloud.monitoring.v3.MetricServiceClient) TimeInterval(com.google.monitoring.v3.TimeInterval) ProjectName(com.google.monitoring.v3.ProjectName) ListTimeSeriesRequest(com.google.monitoring.v3.ListTimeSeriesRequest)

Example 12 with MetricServiceClient

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

the class DeleteMetricDescriptor method deleteMetricDescriptor.

public static void deleteMetricDescriptor(String projectId, String name) throws ApiException, IOException {
    // once, and can be reused for multiple requests.
    try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
        MetricDescriptorName metricDescriptorName = MetricDescriptorName.of(projectId, name);
        // Deletes a metric descriptor
        metricServiceClient.deleteMetricDescriptor(metricDescriptorName);
        System.out.println("metric descriptor deleted successfully" + name);
    }
}
Also used : MetricServiceClient(com.google.cloud.monitoring.v3.MetricServiceClient) MetricDescriptorName(com.google.monitoring.v3.MetricDescriptorName)

Example 13 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.

@Test
public void createMetricServiceClient() throws IOException {
    MetricServiceClient client;
    synchronized (StackdriverStatsExporter.monitor) {
        client = StackdriverStatsExporter.createMetricServiceClient(FAKE_CREDENTIALS, DEFAULT_DEADLINE);
    }
    assertThat(client.getSettings().getCredentialsProvider().getCredentials()).isEqualTo(FAKE_CREDENTIALS);
    assertThat(client.getSettings().getTransportChannelProvider()).isInstanceOf(InstantiatingGrpcChannelProvider.class);
    // There's no way to get HeaderProvider from TransportChannelProvider.
    assertThat(client.getSettings().getTransportChannelProvider().needsHeaders()).isFalse();
}
Also used : MetricServiceClient(com.google.cloud.monitoring.v3.MetricServiceClient) Test(org.junit.Test)

Example 14 with MetricServiceClient

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

the class BigQueryRunnerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    bout = new ByteArrayOutputStream();
    PrintStream out = new PrintStream(bout);
    MetricServiceClient metricsClient = MetricServiceClient.create(metricsServiceStub);
    app = new BigQueryRunner(metricsClient, BigQueryOptions.getDefaultInstance().getService(), out);
    when(metricsServiceStub.listMetricDescriptorsPagedCallable()).thenReturn(listCallable);
    when(listCallable.call(any(ListMetricDescriptorsRequest.class))).thenReturn(listResponse);
    when(listResponse.iterateAll()).thenReturn(Collections.EMPTY_LIST);
    when(metricsServiceStub.createMetricDescriptorCallable()).thenReturn(createMetricCallable);
    when(createMetricCallable.call(any(CreateMetricDescriptorRequest.class))).thenReturn(null);
    when(metricsServiceStub.createTimeSeriesCallable()).thenReturn(createTimeSeriesCallable);
    when(createTimeSeriesCallable.call(any(CreateTimeSeriesRequest.class))).thenReturn(Empty.getDefaultInstance());
}
Also used : PrintStream(java.io.PrintStream) MetricServiceClient(com.google.cloud.monitoring.v3.MetricServiceClient) CreateTimeSeriesRequest(com.google.monitoring.v3.CreateTimeSeriesRequest) CreateMetricDescriptorRequest(com.google.monitoring.v3.CreateMetricDescriptorRequest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ListMetricDescriptorsRequest(com.google.monitoring.v3.ListMetricDescriptorsRequest) Before(org.junit.Before)

Example 15 with MetricServiceClient

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

the class QuickstartSample method main.

public static void main(String... args) throws Exception {
    // Your Google Cloud Platform project ID
    String projectId = System.getProperty("projectId");
    if (projectId == null) {
        System.err.println("Usage: QuickstartSample -DprojectId=YOUR_PROJECT_ID");
        return;
    }
    // Instantiates a client
    MetricServiceClient metricServiceClient = MetricServiceClient.create();
    // Prepares an individual data point
    TimeInterval interval = TimeInterval.newBuilder().setEndTime(Timestamps.fromMillis(System.currentTimeMillis())).build();
    TypedValue value = TypedValue.newBuilder().setDoubleValue(3.14).build();
    Point point = Point.newBuilder().setInterval(interval).setValue(value).build();
    List<Point> pointList = new ArrayList<>();
    pointList.add(point);
    ProjectName name = ProjectName.of(projectId);
    // Prepares the metric descriptor
    Map<String, String> metricLabels = new HashMap<String, String>();
    metricLabels.put("store_id", "Pittsburg");
    Metric metric = Metric.newBuilder().setType("custom.googleapis.com/my_metric").putAllLabels(metricLabels).build();
    // Prepares the monitored resource descriptor
    Map<String, String> resourceLabels = new HashMap<String, String>();
    resourceLabels.put("instance_id", "1234567890123456789");
    resourceLabels.put("zone", "us-central1-f");
    MonitoredResource resource = MonitoredResource.newBuilder().setType("gce_instance").putAllLabels(resourceLabels).build();
    // Prepares the time series request
    TimeSeries timeSeries = TimeSeries.newBuilder().setMetric(metric).setResource(resource).addAllPoints(pointList).build();
    List<TimeSeries> timeSeriesList = new ArrayList<>();
    timeSeriesList.add(timeSeries);
    CreateTimeSeriesRequest request = CreateTimeSeriesRequest.newBuilder().setName(name.toString()).addAllTimeSeries(timeSeriesList).build();
    // Writes time series data
    metricServiceClient.createTimeSeries(request);
    System.out.printf("Done writing time series data.%n");
    metricServiceClient.close();
}
Also used : 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) HashMap(java.util.HashMap) CreateTimeSeriesRequest(com.google.monitoring.v3.CreateTimeSeriesRequest) ArrayList(java.util.ArrayList) MonitoredResource(com.google.api.MonitoredResource) Point(com.google.monitoring.v3.Point) Metric(com.google.api.Metric) TypedValue(com.google.monitoring.v3.TypedValue)

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