gpt4 book ai didi

java - TimeSeries Rest API https ://monitoring. googleapis.com/v3/projects/../timeseries 返回空

转载 作者:行者123 更新时间:2023-12-01 18:48:07 26 4
gpt4 key购买 nike

我正在尝试使用 Google 监控 REST API(代码示例)获取性能数据。但它返回空数据“{}”。还观察到它正在重新调整响应的 ContentEncoding 为“gzip”类型。

private static void executeMetricUrl(Credential credential) throws Exception {
// Set up and execute a Google Cloud Storage request.
long startMillis = System.currentTimeMillis() - ((60 * 20) * 1000);
Date currentDate = new Date(startMillis);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");

//formatted value of current Date
System.out.println("Milliseconds to Date: " + df.format(currentDate));

//System.out.println(currentDate);
String URI = "https://monitoring.googleapis.com/v3/projects/" + projectId+"/timeSeries/?";
String interval =
"interval.end_time=" + df.format(System.currentTimeMillis()) + "&interval.start_time="
+ df.format(currentDate);
String filter =
"filter=metric.type=\"compute.googleapis.com/instance/cpu/utilization\""; //AND metric.labels.instance_name=sampleinstance-1";
String aggregation =
"aggregation.perSeriesAligner=ALIGN_RATE&aggregation.alignmentPeriod=60s&aggregation.crossSeriesReducer=ALIGN_MEAN";

String finalUrl = URI+filter+"&"+interval;
System.out.println("Final URL ::: "+finalUrl);
TimeInterval interval1 = TimeInterval
.newBuilder()
.setStartTime(Timestamps.fromMillis(startMillis))
.setEndTime(
Timestamps.fromMillis(System
.currentTimeMillis())).build();

HttpRequestFactory requestFactory = httpTransport.createRequestFactory(credential);
GenericUrl url = new GenericUrl(finalUrl);
HttpRequest request = requestFactory.buildGetRequest(url);
//HttpHeaders headers = new HttpHeaders();
//request.setHeaders(headers.setAcceptEncoding("gzip"));
HttpResponse response = request.execute();
String html = "";
BufferedReader in = new BufferedReader(new InputStreamReader(response.getContent()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
html += inputLine + "\n";
}
System.out.println("content ::: "+html);

}

我使用 MetricServiceClient 获取具有相同过滤器和间隔的正确时间序列数据。我是否遗漏了 REST API 方法中的某些内容?

最佳答案

我尝试使用 Method: projects.timeSeries.list 重现您的案例

我使用了以下参数

name : project/your-project

filter : metric.type = "compute.googleapis.com/instance/cpu/utilization" AND metric.labels.instance_name = "instance-name"

interval.startTime : 2020-01-10T15:01:23.045123456Z

interval.endTime : 2020-01-11T15:01:23.045123456Z

我收到以下回复:

  "timeSeries": [
{
"metric": {
"labels": {
"instance_name": "instance-name"
},
"type": "compute.googleapis.com/instance/cpu/utilization"
},
"resource": {
"type": "gce_instance",
"labels": {
"instance_id": "XXXXXXXXXXX",
"zone": "XXXXXXXXX",
"project_id": "your-project"
}
},
"metricKind": "GAUGE",
"valueType": "DOUBLE",
"points": [
{
"interval": {
"startTime": "2020-01-11T15:01:00Z",
"endTime": "2020-01-11T15:01:00Z"
},
"value": {
"doubleValue": 0.00097723160608135617
}
},
{
"interval": {
"startTime": "2020-01-11T15:00:00Z",
"endTime": "2020-01-11T15:00:00Z"
},
"value": {
"doubleValue": 0.00092651031620789577
}
....................................................

我建议注意一下如何设置startTime和EndTime。

它应该是 RFC3339 UTC“Zulu”格式 TimeInterval 的时间戳

还尝试在过滤器中包含实例名称。

关于java - TimeSeries Rest API https ://monitoring. googleapis.com/v3/projects/../timeseries 返回空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59782492/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com