[英]prometheus operator is not scraping all pods
我已經在 digitalocean 集群上部署了 prometheus-operator。 使用 kube-prometheus-stack https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack 。 我為 kubernetes pod 角色添加了一些額外的抓取配置。
- job_name: kubernetes-pods
scrape_timeout: 5m
kubernetes_sd_configs:
- role: pod
relabel_configs:
- action: keep
regex: true
source_labels:
- __meta_kubernetes_pod_annotation_prometheus_io_scrape
- action: replace
regex: (.+)
source_labels:
- __meta_kubernetes_pod_annotation_prometheus_io_path
target_label: __metrics_path__
- action: replace
regex: ([^:]+)(?::\d+)?;(\d+)
replacement: $1:$2
source_labels:
- __address__
- __meta_kubernetes_pod_annotation_prometheus_io_port
target_label: __address__
- action: labelmap
regex: __meta_kubernetes_pod_label_(.+)
- action: replace
source_labels:
- __meta_kubernetes_namespace
target_label: kubernetes_namespace
- action: replace
source_labels:
- __meta_kubernetes_pod_name
target_label: kubernetes_pod_name
- action: drop
regex: Pending|Succeeded|Failed
source_labels:
- __meta_kubernetes_pod_phase
之后,我通過在 postgres deploy yaml 文件中提供 prometheus 注釋,在 postgres 命名空間上部署了 postgres db,這是我的文件
kind: Service
metadata:
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "postgres"
prometheus.io/path: "/metrics"
prometheus.io/probe: "true"
namespace: postgres
name: postgres
labels:
component: postgres
spec:
ports:
- port: 5432
name: postgres
selector:
component: postgres
---
# Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
namespace: postgres
labels:
component: postgres
spec:
selector:
matchLabels:
component: postgres
template:
metadata:
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "postgres"
prometheus.io/path: "/metrics"
labels:
component: postgres
spec:
containers:
- image: postgres:11.1-alpine
name: postgres
securityContext:
runAsUser: 70 # postgres user on Alpine
allowPrivilegeEscalation: false
resources:
limits:
memory: 2Gi
cpu: 2
requests:
memory: 2Gi
cpu: 2
env:
- name: PGDATA
value: "/var/lib/postgresql/data/pgdata"
- name: POSTGRES_DB
valueFrom:
secretKeyRef:
name: postgres-secret
key: PG_DATABASE
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: postgres-secret
key: PG_USERNAME
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-secret
key: PG_PASSWORD
ports:
- containerPort: 5432
name: postgres
volumeMounts:
- name: postgres-storage
mountPath: /var/lib/postgresql/data
readinessProbe:
tcpSocket:
port: 5432
initialDelaySeconds: 15
periodSeconds: 5
livenessProbe:
exec:
command:
- pg_isready
- -h
- localhost
- -U
- test_user
- -d
- test_db
initialDelaySeconds: 10
periodSeconds: 5
volumes:
- name: postgres-storage
emptyDir: {}
但是在 postgres pod 的 prometheus 目標中,我收到 EOF 錯誤,有人可以幫我解決這個問題嗎?
您需要使用導出器以 prometheus 格式導出指標。
您不能只向 postgres 端口發送 HTTP 請求,希望它能為您提供一些指標。
使用postgress 導出器。 它與 postgres 對話並在 http 端點下公開指標。 更重要的是:采用普羅米修斯能夠理解的格式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.