哈布爾的居民們,美好的一天!
今天,我想告訴您我們如何真正想要監控 postgres 和 OpenShift 叢集內的其他幾個實體以及我們是如何做到的。
在入口處他們有:
- 開班
- 舵
- 普羅米修斯
要使用 java 應用程序,一切都非常簡單和透明,或者更準確地說:
1)加入到build.gradle
implementation "io.micrometer:micrometer-registry-prometheus"
2)使用配置運行prometheus
- job_name: 'job-name'
metrics_path: '/actuator/prometheus'
scrape_interval: 5s
kubernetes_sd_configs:
- role: pod
namespaces:
names:
- 'name'
3)向Grafana添加顯示
一切都非常簡單和平淡,直到監控位於我們命名空間附近的基地的那一刻(是的,這很糟糕,沒有人這樣做,但發生了不同的事情)。
它是如何工作的?
除了有 postgres 和 prometheus 本身的 pod 之外,我們還需要一個實體-exporter。
抽象概念中的導出器是一個從應用程式甚至伺服器收集指標的代理程式。 對於postgres導出器,它是用Go編寫的,它的工作原理是在資料庫內執行SQL腳本,然後prometheus取得所獲得的結果。 這也允許您透過添加自己的指標來擴展收集的指標。
讓我們像這樣部署它(例如deployment.yaml,非綁定):
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: postgres-exporter
labels:
app: {{ .Values.name }}
monitoring: prometheus
spec:
serviceName: {{ .Values.name }}
replicas: 1
revisionHistoryLimit: 5
template:
metadata:
labels:
app: postgres-exporter
monitoring: prometheus
spec:
containers:
- env:
- name: DATA_SOURCE_URI
value: postgresdb:5432/pstgr?sslmode=disable
- name: DATA_SOURCE_USER
value: postgres
- name: DATA_SOURCE_PASS
value: postgres
resources:
limits:
cpu: 100m
memory: 50Mi
requests:
cpu: 100m
memory: 50Mi
livenessProbe:
tcpSocket:
port: metrics
initialDelaySeconds: 30
periodSeconds: 30
readinessProbe:
tcpSocket:
port: metrics
initialDelaySeconds: 10
periodSeconds: 30
image: exporter
name: postgres-exporter
ports:
- containerPort: 9187
name: metrics
它還需要服務和圖像流
部署後,我們真的希望每個人都能見到對方。
將以下內容新增至 Prometheus 配置中:
- job_name: 'postgres_exporter'
metrics_path: '/metrics'
scrape_interval: 5s
dns_sd_configs:
- names:
- 'postgres-exporter'
type: 'A'
port: 9187
然後一切就都成功了,剩下的就是將所有這些東西添加到 grafana 中並享受結果。
除了能夠新增自己的查詢之外,您還可以變更 prometheus 中的設置,收集更有針對性的指標。
這是以類似的方式完成的:
- 卡夫卡
- Elasticsearch
- 蒙戈
PS 所有有關名稱、連接埠等的數據均來自空中,不包含任何資訊。
相關鏈接:
來源: www.habr.com