feat(postgresql): add monitoring
This commit is contained in:
parent
b3a05ca3d8
commit
5fbb2886b3
9 changed files with 1590 additions and 4 deletions
|
@ -4,7 +4,7 @@ name: "postgresql"
|
|||
description: "A Helm chart for running PostgreSQL (Postgres) database"
|
||||
icon: https://wiki.postgresql.org/images/a/a4/PostgreSQL_logo.3colors.svg
|
||||
type: "application"
|
||||
version: "0.2.6"
|
||||
version: "0.3.0"
|
||||
# renovate: image=docker.io/library/postgres
|
||||
appVersion: "17.4-alpine"
|
||||
maintainers:
|
||||
|
|
|
@ -7,7 +7,7 @@ description: "A Helm chart for running PostgreSQL (Postgres) database"
|
|||
|
||||
# postgresql
|
||||
|
||||
  
|
||||
  
|
||||
|
||||
A Helm chart for running PostgreSQL (Postgres) database
|
||||
|
||||
|
@ -41,6 +41,25 @@ helm uninstall postgresql-release
|
|||
|
||||
## Values
|
||||
|
||||
### Monitoring
|
||||
|
||||
| Key | Type | Default | Description |
|
||||
|-----|------|---------|-------------|
|
||||
| grafana.dashboards.annotations | object | `{}` | label of configmap |
|
||||
| grafana.dashboards.enabled | bool | `false` | deploy grafana dashboard in configmap |
|
||||
| grafana.dashboards.labels | object | `{"grafana_dashboard":"1"}` | label of configmap |
|
||||
| prometheus.enabled | bool | `false` | add prometheus exporter sidecar |
|
||||
| prometheus.image.registry | string | `"docker.io"` | image registry (could be overwritten by global.image.registry) |
|
||||
| prometheus.image.repositry | string | `"prometheuscommunity/postgres-exporter"` | image repository |
|
||||
| prometheus.image.tag | string | `"v0.17.1"` | image tag |
|
||||
| prometheus.rules.additionalRules | list | `[]` | add own rules to prometheusrules (current no default alertrules are provided) |
|
||||
| prometheus.rules.enabled | bool | `false` | deploy prometheusrules |
|
||||
| prometheus.rules.labels | object | `{}` | labels of prometheusrule |
|
||||
| prometheus.servicemonitor.enabled | bool | `false` | deploy servicemonitor |
|
||||
| prometheus.servicemonitor.labels | object | `{}` | label of servicemonitor |
|
||||
|
||||
### Other Values
|
||||
|
||||
| Key | Type | Default | Description |
|
||||
|-----|------|---------|-------------|
|
||||
| affinity | object | `{}` | |
|
||||
|
|
1412
postgresql/grafana_dashboards/postgres-overview.json
Normal file
1412
postgresql/grafana_dashboards/postgres-overview.json
Normal file
File diff suppressed because it is too large
Load diff
14
postgresql/templates/configmap_grafana_dashboards.yaml
Normal file
14
postgresql/templates/configmap_grafana_dashboards.yaml
Normal file
|
@ -0,0 +1,14 @@
|
|||
{{- if .Values.grafana.dashboards.enabled }}
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: {{ include "postgresql.fullname" . }}-grafana-dashboards
|
||||
labels:
|
||||
{{- include "postgresql.labels" . | nindent 4 }}
|
||||
{{- toYaml .Values.grafana.dashboards.labels | nindent 4 }}
|
||||
annotations:
|
||||
{{- toYaml .Values.grafana.dashboards.annotations | nindent 4 }}
|
||||
data:
|
||||
{{- (.Files.Glob "grafana_dashboards/*.json" ).AsConfig | nindent 2 }}
|
||||
{{- end }}
|
33
postgresql/templates/prometheus-rules.yaml
Normal file
33
postgresql/templates/prometheus-rules.yaml
Normal file
|
@ -0,0 +1,33 @@
|
|||
{{- if and .Values.prometheus.rules.enabled }}
|
||||
{{- $fullname := include "postgresql.fullname" . }}
|
||||
{{- $filter := printf `namespace="%s",service=~"%s.*"` .Release.Namespace $fullname }}
|
||||
---
|
||||
apiVersion: monitoring.coreos.com/v1
|
||||
kind: PrometheusRule
|
||||
metadata:
|
||||
name: {{ $fullname }}
|
||||
labels:
|
||||
{{- include "postgresql.labels" . | nindent 4 }}
|
||||
{{- with .Values.prometheus.rules.labels }}
|
||||
{{- toYaml . | nindent 4 }}
|
||||
{{- end }}
|
||||
spec:
|
||||
groups:
|
||||
- name: {{ $fullname }}-Default
|
||||
rules:
|
||||
- alert: "PostgreSQLSlowQueries"
|
||||
expr: 'avg(rate(pg_stat_activity_max_tx_duration{ {{ $filter }},datname!~"template.*" }[2m])) by (datname) > 2 * 60'
|
||||
for: 2m
|
||||
labels:
|
||||
severity: warning
|
||||
annotations:
|
||||
{{`
|
||||
summary: "PostgreSQL high number of slow on {{ $labels.cluster }} for database {{ $labels.datname }}"
|
||||
description: "PostgreSQL high number of slow queries {{ $labels.cluster }} for database {{ $labels.datname }} with a value of {{ $value }}"
|
||||
`}}
|
||||
{{- with .Values.prometheus.rules.additionalRules }}
|
||||
- name: {{ $fullname }}-Additional
|
||||
rules:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
{{- end }}
|
|
@ -11,5 +11,11 @@ spec:
|
|||
targetPort: postgresql
|
||||
protocol: TCP
|
||||
name: postgresql
|
||||
{{- if .Values.prometheus.enabled }}
|
||||
- port: 9187
|
||||
targetPort: metrics
|
||||
protocol: TCP
|
||||
name: metrics
|
||||
{{- end }}
|
||||
selector:
|
||||
{{- include "postgresql.selectorLabels" . | nindent 4 }}
|
||||
|
|
36
postgresql/templates/servicemonitor.yaml
Normal file
36
postgresql/templates/servicemonitor.yaml
Normal file
|
@ -0,0 +1,36 @@
|
|||
{{- if and .Values.prometheus.servicemonitor.enabled }}
|
||||
apiVersion: monitoring.coreos.com/v1
|
||||
kind: ServiceMonitor
|
||||
metadata:
|
||||
name: {{ include "postgresql.fullname" . }}
|
||||
labels:
|
||||
{{- include "postgresql.labels" . | nindent 4 }}
|
||||
{{- with .Values.prometheus.servicemonitor.labels }}
|
||||
{{- toYaml . | nindent 4 }}
|
||||
{{- end }}
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
{{- include "postgresql.selectorLabels" . | nindent 6 }}
|
||||
app.kubernetes.io/component: web
|
||||
endpoints:
|
||||
- port: http
|
||||
path: "/metrics"
|
||||
enableHttp2: false
|
||||
basicAuth:
|
||||
username:
|
||||
name: {{ include "postgresql.fullname" . }}
|
||||
key: postgresql_METRICS_USER
|
||||
password:
|
||||
name: {{ include "postgresql.fullname" . }}
|
||||
key: postgresql_METRICS_PASSPHRASE
|
||||
{{- with .Values.prometheus.servicemonitor }}
|
||||
{{- with .interval }}
|
||||
interval: {{ . }}
|
||||
{{- end }}
|
||||
{{- with .scrapeTimeout }}
|
||||
scrapeTimeout: {{ . }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
|
@ -56,10 +56,10 @@ spec:
|
|||
imagePullPolicy: {{ coalesce $.Values.global.image.pullPolicy .pullPolicy }}
|
||||
{{- end }}
|
||||
env:
|
||||
- name: "POSTGRES_PASSWORD"
|
||||
value: {{ .Values.postgres.password | quote }}
|
||||
- name: "POSTGRES_USER"
|
||||
value: {{ .Values.postgres.user | quote }}
|
||||
- name: "POSTGRES_PASSWORD"
|
||||
value: {{ .Values.postgres.password | quote }}
|
||||
- name: "PGPORT"
|
||||
value: {{ .Values.service.port | quote }}
|
||||
- name: "PGDATA"
|
||||
|
@ -85,6 +85,24 @@ spec:
|
|||
volumeMounts:
|
||||
- name: "data"
|
||||
mountPath: "/var/lib/postgresql/data"
|
||||
{{- if .Values.prometheus.enabled }}
|
||||
- name: "exporter"
|
||||
{{- with .Values.prometheus.image }}
|
||||
image: "{{ coalesce $.Values.global.image.registry .registry }}/{{ .repository }}:{{ .tag }}"
|
||||
imagePullPolicy: {{ coalesce $.Values.global.image.pullPolicy .pullPolicy }}
|
||||
{{- end }}
|
||||
env:
|
||||
- name: "DATA_SOURCE_USER"
|
||||
value: {{ .Values.postgres.user | quote }}
|
||||
- name: "DATA_SOURCE_PASS"
|
||||
value: {{ .Values.postgres.password | quote }}
|
||||
- name: "DATA_SOURCE_URI"
|
||||
value: {{ printf "127.0.0.1:%d/postgres?sslmode=disable" .Values.service.port }}
|
||||
ports:
|
||||
- name: metrics
|
||||
containerPort: 9187
|
||||
protocol: TCP
|
||||
{{- end }}
|
||||
{{- with .Values.nodeSelector }}
|
||||
nodeSelector:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
|
|
|
@ -137,3 +137,51 @@ autoupgrade:
|
|||
# readOnlyRootFilesystem: true
|
||||
# runAsNonRoot: true
|
||||
# runAsUser: 1000
|
||||
|
||||
prometheus:
|
||||
# -- add prometheus exporter sidecar
|
||||
# @section -- Monitoring
|
||||
enabled: false
|
||||
servicemonitor:
|
||||
# -- deploy servicemonitor
|
||||
# @section -- Monitoring
|
||||
enabled: false
|
||||
# -- label of servicemonitor
|
||||
# @section -- Monitoring
|
||||
labels: {}
|
||||
rules:
|
||||
# -- deploy prometheusrules
|
||||
# @section -- Monitoring
|
||||
enabled: false
|
||||
# -- labels of prometheusrule
|
||||
# @section -- Monitoring
|
||||
labels: {}
|
||||
# -- add own rules to prometheusrules (current no default alertrules are provided)
|
||||
# @section -- Monitoring
|
||||
additionalRules: []
|
||||
image:
|
||||
# -- image registry (could be overwritten by global.image.registry)
|
||||
# @section -- Monitoring
|
||||
registry: docker.io
|
||||
# -- image repository
|
||||
# @section -- Monitoring
|
||||
repository: prometheuscommunity/postgres-exporter
|
||||
# -- This sets the pull policy for images. (could be overwritten by global.image.pullPolicy)
|
||||
# @section -- Monitoring
|
||||
pullPolicy: IfNotPresent
|
||||
# -- image tag
|
||||
# @section -- Monitoring
|
||||
tag: v0.17.1
|
||||
|
||||
grafana:
|
||||
dashboards:
|
||||
# -- deploy grafana dashboard in configmap
|
||||
# @section -- Monitoring
|
||||
enabled: false
|
||||
# -- label of configmap
|
||||
# @section -- Monitoring
|
||||
labels:
|
||||
grafana_dashboard: "1"
|
||||
# -- label of configmap
|
||||
# @section -- Monitoring
|
||||
annotations: {}
|
||||
|
|
Loading…
Add table
Reference in a new issue