简体   繁体   中英

My Pod is not appering in the prometheus targets

My Pod is not appearing in the prometheus targets

the application is exposing 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"

Labels:       app=<appname>

if you are using helpm chart add the label in the helper in {{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 }}

replace "< appname >" with your app name

check if your pod appeared in 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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