Skip to content

Commit 70fb0d1

Browse files
andrewlecuyerjmckulk
authored andcommitted
Adds Monitoring for the Prometheus & Grafana Operators
Adds a Kustomize installer for those using CPK metrics & monitoring with the Prometheus and/or Grafana operators.
1 parent 6b9bb00 commit 70fb0d1

File tree

9 files changed

+317
-0
lines changed

9 files changed

+317
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
apiVersion: grafana.integreatly.org/v1beta1
2+
kind: GrafanaDashboard
3+
metadata:
4+
name: pgbackrest
5+
spec:
6+
instanceSelector:
7+
matchLabels:
8+
dashboards: crunchy-grafana
9+
configMapRef:
10+
name: grafana-dashboards
11+
key: pgbackrest.json
12+
---
13+
apiVersion: grafana.integreatly.org/v1beta1
14+
kind: GrafanaDashboard
15+
metadata:
16+
name: pgbouncer-direct
17+
spec:
18+
instanceSelector:
19+
matchLabels:
20+
dashboards: crunchy-grafana
21+
configMapRef:
22+
name: grafana-dashboards
23+
key: pgbouncer_direct.json
24+
---
25+
apiVersion: grafana.integreatly.org/v1beta1
26+
kind: GrafanaDashboard
27+
metadata:
28+
name: pod-details
29+
spec:
30+
instanceSelector:
31+
matchLabels:
32+
dashboards: crunchy-grafana
33+
configMapRef:
34+
name: grafana-dashboards
35+
key: pod_details.json
36+
---
37+
apiVersion: grafana.integreatly.org/v1beta1
38+
kind: GrafanaDashboard
39+
metadata:
40+
name: postgresql-details
41+
spec:
42+
instanceSelector:
43+
matchLabels:
44+
dashboards: crunchy-grafana
45+
configMapRef:
46+
name: grafana-dashboards
47+
key: postgresql_details.json
48+
---
49+
apiVersion: grafana.integreatly.org/v1beta1
50+
kind: GrafanaDashboard
51+
metadata:
52+
name: postgresql-overview
53+
spec:
54+
instanceSelector:
55+
matchLabels:
56+
dashboards: crunchy-grafana
57+
configMapRef:
58+
name: grafana-dashboards
59+
key: postgresql_overview.json
60+
---
61+
apiVersion: grafana.integreatly.org/v1beta1
62+
kind: GrafanaDashboard
63+
metadata:
64+
name: postgresql-service-health
65+
spec:
66+
instanceSelector:
67+
matchLabels:
68+
dashboards: crunchy-grafana
69+
configMapRef:
70+
name: grafana-dashboards
71+
key: postgresql_service_health.json
72+
---
73+
apiVersion: grafana.integreatly.org/v1beta1
74+
kind: GrafanaDashboard
75+
metadata:
76+
name: prometheus-alerts
77+
spec:
78+
instanceSelector:
79+
matchLabels:
80+
dashboards: crunchy-grafana
81+
configMapRef:
82+
name: grafana-dashboards
83+
key: prometheus_alerts.json
84+
---
85+
apiVersion: grafana.integreatly.org/v1beta1
86+
kind: GrafanaDashboard
87+
metadata:
88+
name: query-statistics
89+
spec:
90+
instanceSelector:
91+
matchLabels:
92+
dashboards: crunchy-grafana
93+
configMapRef:
94+
name: grafana-dashboards
95+
key: query_statistics.json
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: grafana.integreatly.org/v1beta1
2+
kind: GrafanaDatasource
3+
metadata:
4+
name: grafana-datasources
5+
spec:
6+
instanceSelector:
7+
matchLabels:
8+
dashboards: crunchy-grafana
9+
valuesFrom:
10+
- targetPath: "secureJsonData.httpHeaderValue1"
11+
valueFrom:
12+
secretKeyRef:
13+
name: grafana-pgo
14+
key: token
15+
datasource:
16+
access: proxy
17+
editable: true
18+
isDefault: true
19+
jsonData:
20+
httpHeaderName1: 'Authorization'
21+
timeInterval: 5s
22+
tlsSkipVerify: true
23+
name: PROMETHEUS
24+
secureJsonData:
25+
httpHeaderValue1: 'Bearer ${token}'
26+
type: prometheus
27+
url: https://thanos-querier.openshift-monitoring.svc.cluster.local:9091/
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: grafana.integreatly.org/v1beta1
2+
kind: Grafana
3+
metadata:
4+
name: crunchy-grafana
5+
labels:
6+
dashboards: crunchy-grafana
7+
spec:
8+
deployment:
9+
spec:
10+
template:
11+
spec:
12+
containers:
13+
- name: grafana
14+
env:
15+
- name: GF_SECURITY_ADMIN_USER
16+
valueFrom:
17+
secretKeyRef:
18+
name: grafana-admin
19+
key: username
20+
- name: GF_SECURITY_ADMIN_PASSWORD
21+
valueFrom:
22+
secretKeyRef:
23+
name: grafana-admin
24+
key: password
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
generatorOptions:
2+
disableNameSuffixHash: true
3+
4+
secretGenerator:
5+
- name: grafana-admin
6+
literals:
7+
- password=admin
8+
- username=admin
9+
type: Opaque
10+
11+
resources:
12+
- rbac.yaml
13+
- grafana.yaml
14+
- datasources.yaml
15+
- ../../grafana/dashboards
16+
- dashboards.yaml
17+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: grafana-pgo
5+
---
6+
apiVersion: v1
7+
kind: Secret
8+
type: kubernetes.io/service-account-token
9+
metadata:
10+
name: grafana-pgo
11+
annotations:
12+
kubernetes.io/service-account.name: grafana-pgo
13+
---
14+
apiVersion: rbac.authorization.k8s.io/v1
15+
kind: ClusterRoleBinding
16+
metadata:
17+
name: grafana-pgo
18+
roleRef:
19+
apiGroup: rbac.authorization.k8s.io
20+
kind: ClusterRole
21+
name: cluster-monitoring-view
22+
subjects:
23+
- kind: ServiceAccount
24+
name: grafana-pgo
25+
namespace: postgres-operator
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace: postgres-operator
2+
3+
resources:
4+
- grafana
5+
- prometheus
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
resources:
2+
- rbac.yaml
3+
- podmonitor.yaml
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
apiVersion: monitoring.coreos.com/v1
2+
kind: PodMonitor
3+
metadata:
4+
name: crunchy-otel-collector
5+
spec:
6+
selector:
7+
matchLabels:
8+
postgres-operator.crunchydata.com/crunchy-otel-collector: "true"
9+
10+
# Uncomment to monitor a single namespace only
11+
# namespaceSelector:
12+
# matchNames:
13+
# - postgres-operator
14+
15+
podMetricsEndpoints:
16+
- port: otel-metrics
17+
interval: 15s
18+
scrapeTimeout: 15s
19+
relabelings:
20+
# Keep exporter port and drop all others
21+
- sourceLabels: [__meta_kubernetes_pod_container_port_number]
22+
action: keep
23+
regex: "9187"
24+
# Set label for namespace
25+
- sourceLabels: [__meta_kubernetes_namespace]
26+
targetLabel: kubernetes_namespace
27+
# Set label for pod name
28+
- sourceLabels: [__meta_kubernetes_pod_name]
29+
targetLabel: pod
30+
# Convert namespace and cluster name to pg_cluster=namespace:cluster
31+
- sourceLabels: [__meta_kubernetes_namespace,__meta_kubernetes_pod_label_postgres_operator_crunchydata_com_cluster]
32+
targetLabel: pg_cluster
33+
separator: ":"
34+
replacement: '$1$2'
35+
# Convert kubernetes pod ip to ip
36+
- sourceLabels: [__meta_kubernetes_pod_ip]
37+
targetLabel: ip
38+
# Convert postgres-operator.crunchydata.com/instance to deployment
39+
- sourceLabels: [__meta_kubernetes_pod_label_postgres_operator_crunchydata_com_instance]
40+
targetLabel: deployment
41+
# Convert postgres-operator.crunchydata.com/role to role
42+
- sourceLabels: [__meta_kubernetes_pod_label_postgres_operator_crunchydata_com_role]
43+
targetLabel: role
44+
# The following relabels should make it easier to use pgMonitor dashboards.
45+
# Note: The following was added for the pgBouncer dashboard and what labels it requires.
46+
# For pgBouncer, `exp_type` should be equal to role.
47+
- sourceLabels: [__meta_kubernetes_pod_label_postgres_operator_crunchydata_com_role]
48+
targetLabel: exp_type
49+
# `cluster_name` is equivalent to `pg_cluster`
50+
- sourceLabels: [__meta_kubernetes_namespace,__meta_kubernetes_pod_label_postgres_operator_crunchydata_com_cluster]
51+
targetLabel: cluster_name
52+
separator: ":"
53+
replacement: '$1$2'
54+
---
55+
apiVersion: monitoring.coreos.com/v1
56+
kind: PodMonitor
57+
metadata:
58+
name: pgo-metrics
59+
spec:
60+
selector:
61+
matchExpressions:
62+
- key: postgres-operator.crunchydata.com/control-plane
63+
operator: Exists
64+
65+
# Uncomment to monitor a single namespace only
66+
# namespaceSelector:
67+
# matchNames:
68+
# - postgres-operator
69+
70+
podMetricsEndpoints:
71+
- port: metrics
72+
interval: 15s
73+
scrapeTimeout: 15s
74+
# If you are running CPK v5.7 or earlier, you will need to change the scheme to 'http'
75+
# and add a metrics port to the postgres-operator deployment that exposes port 8080.
76+
scheme: https
77+
authorization:
78+
type: Bearer
79+
credentials:
80+
name: prometheus-pgo
81+
key: token
82+
tlsConfig:
83+
# By default, the operator's metrics server automatically creates self-signed certs
84+
# which cannot be verified, so `insecure_skip_verify` is set to `true`. See the
85+
# documentation for providing your own signed certificates.
86+
insecureSkipVerify: true
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: prometheus-pgo
5+
---
6+
apiVersion: v1
7+
kind: Secret
8+
type: kubernetes.io/service-account-token
9+
metadata:
10+
name: prometheus-pgo
11+
annotations:
12+
kubernetes.io/service-account.name: prometheus-pgo
13+
---
14+
apiVersion: rbac.authorization.k8s.io/v1
15+
kind: ClusterRole
16+
metadata:
17+
name: prometheus-pgo
18+
rules:
19+
- nonResourceURLs:
20+
- /metrics
21+
verbs:
22+
- get
23+
---
24+
apiVersion: rbac.authorization.k8s.io/v1
25+
kind: ClusterRoleBinding
26+
metadata:
27+
name: prometheus-pgo
28+
roleRef:
29+
apiGroup: rbac.authorization.k8s.io
30+
kind: ClusterRole
31+
name: prometheus-pgo
32+
subjects:
33+
- kind: ServiceAccount
34+
name: prometheus-pgo
35+
namespace: postgres-operator

0 commit comments

Comments
 (0)