Skip to content

Commit 3249716

Browse files
committed
chore(postgresql-cluster): add metrics
1 parent 4f1a350 commit 3249716

4 files changed

Lines changed: 87 additions & 7 deletions

File tree

addons/postgresql-cluster/15/chart/postgresql/templates/networkpolicy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ spec:
2121
- ports:
2222
- port: 5432
2323
{{- if and .Values.metrics.enabled }}
24-
- port: {{ .Values.metrics.service.port }}
24+
- port: {{ .Values.metrics.containerPort }}
2525
{{ end }}
2626
{{- if or .Values.networkPolicy.allowCurrentNamespace .Values.networkPolicy.allowNamespaces }}
2727
from:

addons/postgresql-cluster/15/chart/postgresql/templates/statefulset.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,55 @@ spec:
9797
{{- end }}
9898
resources:
9999
{{ toYaml .Values.resources | indent 10 }}
100+
{{- if .Values.metrics.enabled }}
101+
- name: metrics
102+
image: "{{ .Values.metrics.image.repository }}:{{ .Values.metrics.image.tag }}"
103+
imagePullPolicy: {{ .Values.metrics.image.pullPolicy | quote }}
104+
{{- if .Values.metrics.containerSecurityContext.enabled }}
105+
securityContext: {{- omit .Values.metrics.containerSecurityContext "enabled" | toYaml | nindent 12 }}
106+
{{- end }}
107+
{{- if .Values.diagnosticMode.enabled }}
108+
command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 12 }}
109+
args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 12 }}
110+
{{- else if .Values.metrics.customMetrics }}
111+
args: ["--extend.query-path", "/conf/custom-metrics.yaml"]
112+
{{- end }}
113+
env:
114+
- name: DATA_SOURCE_NAME
115+
value: {{ printf "postgresql://tea_mon:password@127.0.0.1:5432/%s?sslmode=disable" $.Values.dataname.dbname }}
116+
ports:
117+
- name: http-metrics
118+
containerPort: {{ .Values.metrics.containerPort }}
119+
startupProbe:
120+
initialDelaySeconds: 10
121+
tcpSocket:
122+
port: http-metrics
123+
periodSeconds: 10
124+
timeoutSeconds: 1
125+
failureThreshold: 15
126+
successThreshold: 1
127+
livenessProbe:
128+
initialDelaySeconds: 5
129+
httpGet:
130+
path: /
131+
port: http-metrics
132+
periodSeconds: 10
133+
timeoutSeconds: 5
134+
failureThreshold: 6
135+
successThreshold: 1
136+
readinessProbe:
137+
initialDelaySeconds: 5
138+
httpGet:
139+
path: /
140+
port: http-metrics
141+
periodSeconds: 10
142+
timeoutSeconds: 5
143+
failureThreshold: 6
144+
successThreshold: 1
145+
{{- if .Values.metrics.resources }}
146+
resources: {{- toYaml .Values.metrics.resources | nindent 12 }}
147+
{{- end }}
148+
{{- end }}
100149
{{- with .Values.nodeSelector }}
101150
nodeSelector:
102151
{{ toYaml . | indent 8 }}

addons/postgresql-cluster/15/chart/postgresql/templates/svc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ spec:
1515
- name: postgresql
1616
port: 5432
1717
targetPort: postgresql
18-
protocol: TCP
18+
protocol: TCP

addons/postgresql-cluster/15/chart/postgresql/values.yaml

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
replicaCount: 3
2+
diagnosticMode:
3+
enable: false
24

35
image:
46
# Image was built from registry.drycc.cc/drycc-addons/patroni:3.2
@@ -46,6 +48,7 @@ preInitScript: |
4648
use_slots: true
4749
pg_hba:
4850
- local all all peer
51+
- host all tea_mon 127.0.0.1/32 trust
4952
- host all all 0.0.0.0/0 scram-sha-256
5053
- host replication ${PATRONI_REPLICATION_USERNAME} 0.0.0.0/0 scram-sha-256
5154
parameters:
@@ -108,6 +111,39 @@ postInitScript: |
108111
echo "Skipping database creation"
109112
fi
110113
114+
## Postgresql Prometheus exporter parameters
115+
##
116+
metrics:
117+
enabled: true
118+
image:
119+
repository: registry.drycc.cc/drycc-addons/postgres-exporter
120+
tag: "0"
121+
# IfNotPresent , Always
122+
pullPolicy: 'IfNotPresent'
123+
## @param metrics.customMetrics Define additional custom metrics
124+
## ref: https://github.com/wrouesnel/postgres_exporter#adding-new-metrics-via-a-config-file
125+
## customMetrics:
126+
## pg_database:
127+
## query: "SELECT d.datname AS name, CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT') THEN pg_catalog.pg_database_size(d.datname) ELSE 0 END AS size_bytes FROM pg_catalog.pg_database d where datname not in ('template0', 'template1', 'postgres')"
128+
## metrics:
129+
## - name:
130+
## usage: "LABEL"
131+
## description: "Name of the database"
132+
## - size_bytes:
133+
## usage: "GAUGE"
134+
## description: "Size of the database in bytes"
135+
##
136+
customMetrics: {}
137+
containerPort: 9187
138+
containerSecurityContext:
139+
enabled: false
140+
runAsUser: 1001
141+
runAsNonRoot: true
142+
customLivenessProbe: {}
143+
customReadinessProbe:
144+
enabled: true
145+
service: port
146+
resources: {}
111147
walE:
112148
# Specifies whether Wal-E should be enabled
113149
enable: false
@@ -189,11 +225,6 @@ serviceAccount:
189225
# The name of the ServiceAccount to use.
190226
# If not set and create is true, a name is generated using the fullname template
191227
name:
192-
193-
## Postgresql Prometheus exporter parameters
194-
##
195-
metrics:
196-
enabled: false
197228
## Postgresql Nework Policy configuration
198229
##
199230
networkPolicy:

0 commit comments

Comments
 (0)