Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Java中查询kubelet metrics API?_Java_Kubernetes_Prometheus - Fatal编程技术网

如何在Java中查询kubelet metrics API?

如何在Java中查询kubelet metrics API?,java,kubernetes,prometheus,Java,Kubernetes,Prometheus,使用Java查询prometheus kubelet metrics API的正确方法是什么,特别是PVC使用指标?我可以看到有一个API可以通过自动定标器获取一些指标,但我的集群没有自动定标器,因此返回一个空列表: AutoscalingV2beta2Api autoscalingV2beta2Api = new AutoscalingV2beta2Api(apiClient); var autoscalers = autoscalingV2beta2Api .listHorizont

使用Java查询prometheus kubelet metrics API的正确方法是什么,特别是PVC使用指标?我可以看到有一个API可以通过自动定标器获取一些指标,但我的集群没有自动定标器,因此返回一个空列表:

AutoscalingV2beta2Api autoscalingV2beta2Api = new AutoscalingV2beta2Api(apiClient);
var autoscalers = autoscalingV2beta2Api
    .listHorizontalPodAutoscalerForAllNamespaces(null, null, null, null, null, null, null, null, null)
    .getItems();
作为参考,我认为这是我需要获取的: 我不喜欢使用
kubectl-n exec df
方法,因为这样我需要将pod卷装载回我已经通过K8s API获取的卷声明列表


谢谢

最后,我只是使用Spring的
RestTemplate
直接查询普罗米修斯。我只针对一个开发集群工作,所以我利用了Len安装的prometheus,这意味着端点类似于:

下面是他们的查询,我在下面重复使用了这些查询:

String query = String
    .format(
        "sum(kubelet_volume_stats_used_bytes{persistentvolumeclaim=\"%s\",namespace=\"%s\"}) by (persistentvolumeclaim, namespace)",
        pvc.getMetadata().getName(),
        pvc.getMetadata().getNamespace());

var response = restTemplateBuilder.build().getForEntity(prometheusEndpoint + "/api/v1/query?query={query}", String.class, query);
String json = response.getBody();

// E.g. {"status":"success","data":{"resultType":"vector","result":[{"metric":{"namespace":"luke",
//       "persistentvolumeclaim":"elasticsearch-data-es-ap-southeast-2c-0"},"value":[1622781271.612,"76865536"]}]}}
long bytesUsed = JsonPath.parse(json).read("data.result[0].value[1]", Long.class);