在 kubernetes 命名空间中监视普罗米修斯上的自定义服务的问题
Issue with monitoring custom service on prometheus in kubernetes namespace
我的目标是使用 Prometheus 监控服务,因此我遵循了位于以下位置的指南:
我对这一切都比较陌生,所以请原谅我的幼稚。我试着调查错误,但所有的答案都令人费解。我不知道从哪里开始调试过程(也许查看 YAML?)
我想监控自定义服务。因此,我将以下 service.yaml 部署到自定义命名空间 (t) 中:
kind: Service
apiVersion: v1
metadata:
namespace: t
name: example-service-test
labels:
app: example-service-test
spec:
selector:
app: example-service-test
type: NodePort
ports:
- name: http
nodePort: 30901
port: 8080
protocol: TCP
targetPort: http
---
apiVersion: v1
kind: Pod
metadata:
name: example-service-test
namespace: t
labels:
app: example-service-test
spec:
containers:
- name: example-service-test
image: python:2.7
imagePullPolicy: IfNotPresent
command: ["/bin/bash"]
args: ["-c", "echo \"<p>This is POD1 $(hostname)</p>\" > index.html; python -m SimpleHTTPServer 8080"]
ports:
- name: http
containerPort: 8080
并将服务监视器部署到命名空间中:
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: example-service-test
labels:
team: frontendtest1
namespace: t
spec:
selector:
matchLabels:
app: example-service-test
endpoints:
- port: http
至此,服务监控正在检测服务,如图:
Prometheus Service Discovery。
但是,从服务获取指标时出错:Prometheus Targets。
据我所知,prometheus 无法访问示例服务上的 /metrics - 在这种情况下,我是否需要公开指标?如果是这样,我可以获得有关如何公开指标的分步指南解决方案吗?如果不是,我应该走什么路线?
恐怕您可能会错过您在 CoreOS 网站上关注的教程中的关键内容,关于应用程序的指标如何到达 Prometheus:
First, deploy three instances of a simple example application, which
listens and exposes metrics on port 8080
是的,您的应用程序(网站)侦听端口 8080,但不会以 Prometheus 已知的格式在“/metrics”端点上公开任何指标。
您可以通过从托管它的 Pod/Conatiner 内部点击端点来验证我所说的指标类型。
kubectl exec -it $(kubectl get po -l app=example-app -o jsonpath='{.items[0].metadata.name}') -c example-app -- curl localhost:8080/metrics
您应该会看到与此类似的输出:
# HELP codelab_api_http_requests_in_progress The current number of API HTTP requests in progress.
# TYPE codelab_api_http_requests_in_progress gauge
codelab_api_http_requests_in_progress 1
# HELP codelab_api_request_duration_seconds A histogram of the API HTTP request durations in seconds.
# TYPE codelab_api_request_duration_seconds histogram
codelab_api_request_duration_seconds_bucket{method="GET",path="/api/bar",status="200",le="0.0001"} 0
codelab_api_request_duration_seconds_bucket{method="GET",path="/api/bar",status="200",le="0.00015000000000000001"} 0
codelab_api_request_duration_seconds_bucket{method="GET",path="/api/bar",status="200",le="0.00022500000000000002"} 0
codelab_api_request_duration_seconds_bucket{method="GET",path="/api/bar",status="200",le="0.0003375"} 0
codelab_api_request_duration_seconds_bucket{method="GET",path="/api/bar",status="200",le="0.00050625"} 0
codelab_api_request_duration_seconds_bucket{method="GET",path="/api/bar",status="200",le="0.000759375"} 0
请详细阅读 here 公开指标的方法。
我的目标是使用 Prometheus 监控服务,因此我遵循了位于以下位置的指南:
我对这一切都比较陌生,所以请原谅我的幼稚。我试着调查错误,但所有的答案都令人费解。我不知道从哪里开始调试过程(也许查看 YAML?)
我想监控自定义服务。因此,我将以下 service.yaml 部署到自定义命名空间 (t) 中:
kind: Service
apiVersion: v1
metadata:
namespace: t
name: example-service-test
labels:
app: example-service-test
spec:
selector:
app: example-service-test
type: NodePort
ports:
- name: http
nodePort: 30901
port: 8080
protocol: TCP
targetPort: http
---
apiVersion: v1
kind: Pod
metadata:
name: example-service-test
namespace: t
labels:
app: example-service-test
spec:
containers:
- name: example-service-test
image: python:2.7
imagePullPolicy: IfNotPresent
command: ["/bin/bash"]
args: ["-c", "echo \"<p>This is POD1 $(hostname)</p>\" > index.html; python -m SimpleHTTPServer 8080"]
ports:
- name: http
containerPort: 8080
并将服务监视器部署到命名空间中:
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: example-service-test
labels:
team: frontendtest1
namespace: t
spec:
selector:
matchLabels:
app: example-service-test
endpoints:
- port: http
至此,服务监控正在检测服务,如图: Prometheus Service Discovery。 但是,从服务获取指标时出错:Prometheus Targets。
据我所知,prometheus 无法访问示例服务上的 /metrics - 在这种情况下,我是否需要公开指标?如果是这样,我可以获得有关如何公开指标的分步指南解决方案吗?如果不是,我应该走什么路线?
恐怕您可能会错过您在 CoreOS 网站上关注的教程中的关键内容,关于应用程序的指标如何到达 Prometheus:
First, deploy three instances of a simple example application, which listens and exposes metrics on port 8080
是的,您的应用程序(网站)侦听端口 8080,但不会以 Prometheus 已知的格式在“/metrics”端点上公开任何指标。
您可以通过从托管它的 Pod/Conatiner 内部点击端点来验证我所说的指标类型。
kubectl exec -it $(kubectl get po -l app=example-app -o jsonpath='{.items[0].metadata.name}') -c example-app -- curl localhost:8080/metrics
您应该会看到与此类似的输出:
# HELP codelab_api_http_requests_in_progress The current number of API HTTP requests in progress.
# TYPE codelab_api_http_requests_in_progress gauge
codelab_api_http_requests_in_progress 1
# HELP codelab_api_request_duration_seconds A histogram of the API HTTP request durations in seconds.
# TYPE codelab_api_request_duration_seconds histogram
codelab_api_request_duration_seconds_bucket{method="GET",path="/api/bar",status="200",le="0.0001"} 0
codelab_api_request_duration_seconds_bucket{method="GET",path="/api/bar",status="200",le="0.00015000000000000001"} 0
codelab_api_request_duration_seconds_bucket{method="GET",path="/api/bar",status="200",le="0.00022500000000000002"} 0
codelab_api_request_duration_seconds_bucket{method="GET",path="/api/bar",status="200",le="0.0003375"} 0
codelab_api_request_duration_seconds_bucket{method="GET",path="/api/bar",status="200",le="0.00050625"} 0
codelab_api_request_duration_seconds_bucket{method="GET",path="/api/bar",status="200",le="0.000759375"} 0
请详细阅读 here 公开指标的方法。