use of 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(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");
metricServiceClient.close();
}
use of 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());
}
Aggregations