Unable to fetch CloudSql metrics for Specific Database Instance

206 προβολές
Παράβλεψη και μετάβαση στο πρώτο μη αναγνωσμένο μήνυμα

Rahul

μη αναγνωσμένη,
10 Νοε 2019, 11:48:03 μ.μ.10/11/19
ως Google Cloud SQL discuss
Hello,


I am trying to fetch CPU Utilization percentage for a specific database instance. But, That gives me an exception to unable to use multiple metrics at a time. Your documentation suggests you can use multiple metrics in single request.


metric.type = "compute.googleapis.com/instance/cpu/usage_time"
AND
(metric.label.instance_name = "your-instance-id" OR
  metric
.label.instance_name = "your-other-instance-id")

The below is java code : 

public Double readCloudSqlCpuLevel() throws IOException {

final MetricServiceClient metricServiceClient = MetricServiceClient.create();

// Trying to read last 3 minutes data only.
long startMillis = System.currentTimeMillis() - ((60 * 3) * 1000);

final TimeInterval interval = TimeInterval.newBuilder()
.setStartTime(Timestamps.fromMillis(startMillis))
.setEndTime(Timestamps.fromMillis(System.currentTimeMillis()))
.build();

final String filter = "metric.type=\"cloudsql.googleapis.com/database/cpu/utilization\" AND metric.labels.instance_name = \"my-instance-id\" ";
final ListTimeSeriesRequest.Builder requestBuilder = ListTimeSeriesRequest.newBuilder()
.setName(projectName.toString())
.setFilter(filter)
.setInterval(interval)
.setView(ListTimeSeriesRequest.TimeSeriesView.FULL);

final ListTimeSeriesRequest request = requestBuilder.build();
final MetricServiceClient.ListTimeSeriesPagedResponse response = metricServiceClient.listTimeSeries(request);

Double cpuLevel = 0.0D;
for (TimeSeries ts : response.iterateAll()) {

for (Point pt : ts.getPointsList()) {
cpuLevel = pt.getValue().getDoubleValue() * 100;
}

}
log.info("cpuLevel : {} ", cpuLevel);
metricServiceClient.shutdownNow();
return cpuLevel;
}

This code gives me :

c.i.b.t.g.s.c.CloudSqlCpuCacheService    : Unable to fetch Cloud SQL CPU level from GCloud StackDriver Monitoring API : error : io.grpc.StatusRuntimeException: NOT_FOUND: The metric referenced by the provided filter is unknown. Check the metric name and labels.
g
.s.c.CloudSqlCpuCacheMaintenanceService : Unable to get Cloud SQL CPU level from GCloud API : Error : com.google.api.gax.rpc.NotFoundException: io.grpc.StatusRuntimeException: NOT_FOUND: The metric referenced by the provided filter is unknown. Check the metric name and labels.





Please suggest any solution, please.






George (Cloud Platform Support)

μη αναγνωσμένη,
11 Νοε 2019, 2:01:42 μ.μ.11/11/19
ως Google Cloud SQL discuss
Expected string is "metric.label.instance_name". You use "metric.labels.instance_name = \"my-instance-id\" with an extra "s" in "labels". 

All this is above the scope of this discussion group, in fact off-topic. You should post such questions to StackOverflow, or other similar forums. This forum is meant for general discussion on Cloud Platform and its services. By contrast, in StackOverflow, you get in contact with experienced programmers, who are happy to help. 
Απάντηση σε όλους
Απάντηση στον συντάκτη
Προώθηση
0 νέα μηνύματα