哈布尔的居民们,美好的一天!
今天,我想告诉您我们如何真正想要监控 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 所有有关名称、端口等的数据均来自空中,不包含任何信息。