简体   繁体   English

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

[英]My Pod is not appering in the prometheus targets

My Pod is not appearing in the prometheus targets我的 Pod 没有出现在 prometheus 目标中

the application is exposing metrics '/metrics'应用程序正在公开指标“/metrics”

I added a service monitor to expose the service我添加了一个服务监视器来公开服务

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

but still prometheus can't read the metrics但普罗米修斯仍然无法读取指标

make sure that your pod has a label called "app"确保您的 pod 有一个名为“app”的 label

Labels:       app=<appname>

if you are using helpm chart add the label in the helper in {{chart-name}}\templates_helpers.tpl如果您使用 helpm 图表,请在 {{chart-name}}\templates_helpers.tpl 的帮助程序中添加 label

{{/*
Selector labels
*/}}
{{- define "<appname>.selectorLabels" -}}
app.kubernetes.io/name: {{ include "<appname>.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app: {{ .Release.Name }} # <======================================= add this 
{{- end }}

replace "< appname >" with your app name将“< appname >”替换为您的应用名称

check if your pod appeared in http://localhost:9090/config检查您的 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: $1
    action: keep
  - source_labels: [__meta_kubernetes_endpoint_port_name]
    separator: ;
    regex: http
    replacement: $1
    action: keep

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM