我的 Pod 没有出现在普罗米修斯目标中

My Pod is not appering in the prometheus targets

我的 Pod 没有出现在 prometheus 目标中

应用程序正在公开指标“/metrics”

我添加了一个服务监视器来公开服务

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: abc 
  # Change this to the namespace the Prometheus instance is running in
  # namespace: default
  labels:
    app: abc
    release: prometheus
spec:
  selector:
    matchLabels:
      app: abc # target gitlab service
  endpoints:
    - port: http
      interval: 15s
      path: /metrics

但 prometheus 仍然无法读取指标

确保您的广告连播有一个名为“app”的标签

Labels:       app=<appname>

如果您使用的是 helpm 图表,请在 {{chart-name}}\templates_helpers.tpl

中的帮助器中添加标签
{{/*
Selector labels
*/}}
{{- define "<appname>.selectorLabels" -}}
app.kubernetes.io/name: {{ include "<appname>.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app: {{ .Release.Name }} # <======================================= add this 
{{- end }}

将“”替换为您的应用名称

检查你的 pod 是否出现在 http://localhost:9090/config

rule_files:
- /etc/prometheus/rules/prometheus-prometheus-kube-prometheus-prometheus-rulefiles-0/*.yaml
scrape_configs:
- job_name: default/<appname>y/0
  honor_timestamps: true
  scrape_interval: 15s
  scrape_timeout: 10s
  metrics_path: /metrics
  scheme: http
  relabel_configs:
  - source_labels: [__meta_kubernetes_service_label_app]
    separator: ;
    regex: 
    replacement: 
    action: keep
  - source_labels: [__meta_kubernetes_endpoint_port_name]
    separator: ;
    regex: http
    replacement: 
    action: keep