Bon ghjornu, abitanti di Habr !
Oghje vogliu dicu cumu vulemu veramente monitorà i postgres è un coppiu di altre entità in u cluster OpenShift è cumu avemu fattu.
À l'entrata avianu:
- Openshift
- Helm
- Prometheus
Per travaglià cù una applicazione Java, tuttu era abbastanza simplice è trasparente, o per esse più precisu:
1) Aghjunghjendu à build.gradle
implementation "io.micrometer:micrometer-registry-prometheus"
2) Eseguite prometheus cù cunfigurazione
- job_name: 'job-name'
metrics_path: '/actuator/prometheus'
scrape_interval: 5s
kubernetes_sd_configs:
- role: pod
namespaces:
names:
- 'name'
3) Aghjunghjendu un display à Grafana
Tuttu era abbastanza simplice è prosaicu finu à u mumentu hè ghjuntu à monitorà e basi chì si trovanu vicinu in u nostru spaziu di nomi (iè, questu hè male, nimu face questu, ma cose diverse succede).
Cumu funziona?
In più di u pod cù postgres è prometheus stessu, avemu bisognu di una entità più - exporter.
Un esportatore in un cuncettu astrattu hè un agentu chì raccoglie metriche da una applicazione o ancu un servitore. Per l'esportatore di postgres, hè scrittu in Go, funziona nantu à u principiu di eseguisce script SQL in a basa di dati è poi prometheus piglia i risultati ottenuti. Questu permette ancu di espansione e metriche raccolte aghjunghjendu i vostri.
Implementemu cusì (esempiu deployment.yaml, non vincolante):
---
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
Hè ancu necessariu un serviziu è imagestream
Dopu a implementazione, vulemu veramente chì tutti si vedanu.
Aghjunghjite u seguente pezzu à a cunfigurazione di Prometheus:
- job_name: 'postgres_exporter'
metrics_path: '/metrics'
scrape_interval: 5s
dns_sd_configs:
- names:
- 'postgres-exporter'
type: 'A'
port: 9187
È dopu tuttu hà travagliatu, tuttu ciò chì resta hè di aghjunghje tutte queste cose à a grafana è gode di u risultatu.
In più di l'abilità di aghjunghje e vostre dumande, pudete cambià i paràmetri in prometheus, cullighjendu più metrici mirati.
Questu hè statu fattu in modu simili per:
- Kafka
- Elasticsearch
- Mongo
PS Tutti i dati nantu à i nomi, i porti è u restu hè pigliatu da l'aria è ùn cuntene micca infurmazione.
Ligami utili:
Source: www.habr.com