普罗米修斯发现服务不在目标中



我有prometheus配置,它能够发现我的服务,但没有添加目标。

普罗米修斯样本(0/1个活动目标(

下面是我的普罗米修斯配置。

- job_name: prometheus-sample
honor_timestamps: true
scrape_interval: 10s
scrape_timeout: 10s
metrics_path: /metrics
scheme: http
follow_redirects: true
relabel_configs:
- source_labels: [__meta_kubernetes_service_label_app]
separator: ;
regex: prometheus-sample
replacement: $1
action: keep
- source_labels: [__meta_kubernetes_endpoint_port_name]
separator: ;
regex: "8080"
replacement: $1
action: keep
kubernetes_sd_configs:
- role: endpoints
follow_redirects: true
namespaces:
names:
- prometheus-sample

这是我的服务定义:

apiVersion: v1
kind: Service
metadata:
name: prometheus-sample
namespace: prometheus-sample
spec:
selector:
app: prometheus-sample
ports:
- name: http
port: 8080
targetPort: 8080

我的吊舱已经启动并运行,正在接受请求。我已经能够使用静态配置来测试它,它运行良好,并且能够刮除pod。

是什么使得发现的服务没有添加到目标中?

这似乎是本节中正则表达式的问题。您正在匹配端口名http,但您的正则表达式正在查找8080

- source_labels: [__meta_kubernetes_endpoint_port_name]
separator: ;
regex: "8080"
replacement: $1
action: keep

将我的prometheus配置更改为:

- job_name: prometheus-sample
honor_timestamps: true
scrape_interval: 10s
scrape_timeout: 10s
metrics_path: /metrics
scheme: http
follow_redirects: true
kubernetes_sd_configs:
- role: endpoints
follow_redirects: true
namespaces:
names:
- prometheus-sample

这似乎工作

最新更新