use of com.google.storage.v2.ProjectName 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]
}
use of com.google.storage.v2.ProjectName 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]
}
use of com.google.storage.v2.ProjectName 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]
}
use of com.google.storage.v2.ProjectName in project spring-cloud-config by spring-cloud.
the class GoogleSecretManagerV1AccessStrategy method getSecrets.
@Override
public List<Secret> getSecrets() {
// Build the parent name.
ProjectName project = ProjectName.of(getProjectId());
// Create the request.
ListSecretsRequest listSecretRequest = ListSecretsRequest.newBuilder().setParent(project.toString()).build();
// Get all secrets.
SecretManagerServiceClient.ListSecretsPagedResponse pagedListSecretResponse = client.listSecrets(listSecretRequest);
List<Secret> result = new ArrayList<Secret>();
pagedListSecretResponse.iterateAll().forEach(result::add);
// List all secrets.
return result;
}
use of com.google.storage.v2.ProjectName in project java-docs-samples by GoogleCloudPlatform.
the class ListSecrets method listSecrets.
// List all secrets for a project
public static void listSecrets(String projectId) throws IOException {
// the "close" method on the client to safely clean up any remaining background resources.
try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
// Build the parent name.
ProjectName projectName = ProjectName.of(projectId);
// Get all secrets.
ListSecretsPagedResponse pagedResponse = client.listSecrets(projectName);
// List all secrets.
pagedResponse.iterateAll().forEach(secret -> {
System.out.printf("Secret %s\n", secret.getName());
});
}
}
Aggregations