Search in sources :

Example 6 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 describeMonitoredResources.

// [END monitoring_get_resource]
/**
 * Gets full information for a monitored resource.
 *
 * @param type The resource type
 */
void describeMonitoredResources(String type) throws IOException {
    // [START monitoring_get_descriptor]
    // Your Google Cloud Platform project ID
    String projectId = System.getProperty("projectId");
    final MetricServiceClient client = MetricServiceClient.create();
    MonitoredResourceDescriptorName name = MonitoredResourceDescriptorName.of(projectId, type);
    MonitoredResourceDescriptor response = client.getMonitoredResourceDescriptor(name);
    System.out.println("Printing monitored resource descriptor: ");
    System.out.println(response);
// [END monitoring_get_descriptor]
}
Also used : MonitoredResourceDescriptorName(com.google.monitoring.v3.MonitoredResourceDescriptorName) MetricServiceClient(com.google.cloud.monitoring.v3.MetricServiceClient) MonitoredResourceDescriptor(com.google.api.MonitoredResourceDescriptor)

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

/**
 * Gets all monitored resource descriptors.
 */
void listMonitoredResources() throws IOException {
    // [START monitoring_list_resources]
    // Your Google Cloud Platform project ID
    String projectId = System.getProperty("projectId");
    final MetricServiceClient client = MetricServiceClient.create();
    ProjectName name = ProjectName.of(projectId);
    ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder().setName(name.toString()).build();
    System.out.println("Listing monitored resource descriptors: ");
    ListMonitoredResourceDescriptorsPagedResponse response = client.listMonitoredResourceDescriptors(request);
    for (MonitoredResourceDescriptor d : response.iterateAll()) {
        System.out.println(d.getType());
    }
// [END monitoring_list_resources]
}
Also used : MetricServiceClient(com.google.cloud.monitoring.v3.MetricServiceClient) ProjectName(com.google.monitoring.v3.ProjectName) ListMonitoredResourceDescriptorsRequest(com.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest) MonitoredResourceDescriptor(com.google.api.MonitoredResourceDescriptor) ListMonitoredResourceDescriptorsPagedResponse(com.google.cloud.monitoring.v3.MetricServiceClient.ListMonitoredResourceDescriptorsPagedResponse)

Example 8 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 createMetricDescriptor.

/**
 * 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).addLabels(LabelDescriptor.newBuilder().setKey("store_id").setValueType(LabelDescriptor.ValueType.STRING)).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]
}
Also used : MetricDescriptor(com.google.api.MetricDescriptor) MetricServiceClient(com.google.cloud.monitoring.v3.MetricServiceClient) ProjectName(com.google.monitoring.v3.ProjectName) CreateMetricDescriptorRequest(com.google.monitoring.v3.CreateMetricDescriptorRequest)

Example 9 with MetricServiceClient

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

the class GetMonitoredResource method getMonitoredResource.

public static void getMonitoredResource(String projectId, String resourceId) throws ApiException, IOException {
    // once, and can be reused for multiple requests.
    try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
        MonitoredResourceDescriptorName name = MonitoredResourceDescriptorName.of(projectId, resourceId);
        // Prepare get monitor resource descriptor
        MonitoredResourceDescriptor response = metricServiceClient.getMonitoredResourceDescriptor(name);
        System.out.println(response);
    }
}
Also used : MonitoredResourceDescriptorName(com.google.monitoring.v3.MonitoredResourceDescriptorName) MetricServiceClient(com.google.cloud.monitoring.v3.MetricServiceClient) MonitoredResourceDescriptor(com.google.api.MonitoredResourceDescriptor)

Example 10 with MetricServiceClient

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

the class QuickstartSample method quickstart.

public static void quickstart(String projectId) throws IOException {
    // once, and can be reused for multiple requests.
    try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
        // Prepares an individual data point
        TimeInterval interval = TimeInterval.newBuilder().setEndTime(Timestamps.fromMillis(System.currentTimeMillis())).build();
        TypedValue value = TypedValue.newBuilder().setDoubleValue(123.45).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/stores/daily_sales").putAllLabels(metricLabels).build();
        // Prepares the monitored resource descriptor
        Map<String, String> resourceLabels = new HashMap<String, String>();
        resourceLabels.put("project_id", projectId);
        MonitoredResource resource = MonitoredResource.newBuilder().setType("global").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");
    }
}
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