我可以列出所有可用的custom.metrics
,但是我不知道如何查询单个值。例如,我尝试过:
curl http://localhost:8001/apis/custom.metrics.k8s.io/v1beta1/ | jq .
{
"kind": "APIResourceList",
"apiVersion": "v1",
"groupVersion": "custom.metrics.k8s.io/v1beta1",
"resources": [
{
"name": "deployments.apps/aws_sqs_approximate_number_of_messages_visible_average",
"singularName": "",
"namespaced": false,
"kind": "MetricValueList",
"verbs": [
"get"
]
}
]
}
但是,如果我尝试这样做:
curl http://localhost:8001/apis/custom.metrics.k8s.io/v1beta1/deployments.apps/aws_sqs_approximate_number_of_messages_visible_average | jq .
{
"kind": "Status",
"apiVersion": "v1",
"metadata": {
},
"status": "Failure",
"message": "the server could not find the requested resource",
"reason": "NotFound",
"details": {
},
"code": 404
}
我得到404。我见过this issue,它显示了如何获取命名空间的指标,但是我的没有命名空间?是否有关于如何使用此API的定义?
答案 0 :(得分:2)
就像资源指标一样,自定义指标也绑定到Kubernetes对象。 URL中缺少的是您希望指标与之相关的资源。 例如,自定义指标与之相关的Pod,但对于Deployments来说同样如此。
尝试根据您的需要调整此网址:
app:srcCompat="@drawable/..."
以下是我们在FOSDEM 2019上通过Prometheus Adapter进行的演讲的幻灯片:answer
一旦视频可用,我将更新此答案。
答案 1 :(得分:0)
自从我使用DirectXMan12/k8s-prometheus-adapter
以来,有几件事要知道:
k8s-prometheus-adapter
will report it as non-existent.
使用自定义指标API非常简单:
kubectl proxy
打开您的kubernetes API的代理curl http://localhost:8001/apis/custom.metrics.k8s.io/v1beta1/
列出所有可用的自定义指标。例如,您可能会看到:
{
"name": "deployments.extensions/kube_deployment_status_replicas_available",
"singularName": "",
"namespaced": true,
"kind": "MetricValueList",
"verbs": [
"get"
]
}
我们知道它是从namespaced: true
命名的,并且可以在name
字段中通过部署选择命名空间。
因此,我们将像这样构建查询:
curl http://localhost:8001/apis/custom.metrics.k8s.io/v1beta1/namespace/$NAMESPACE/deployments.extensions/$DEPLOYMENT/kube_deployment_status_replicas_available
至少我认为这是应该的工作方式,尽管如果您执行不带deployments.extensions
部分的相同查询,它将显示名称空间的值:
curl http://localhost:8001/apis/custom.metrics.k8s.io/v1beta1/namespace/$NAMESPACE/kube_deployment_status_replicas_available
这也许是由于查询是如何在Prometheus中执行的。