|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright 2022 Crunchy Data Solutions, Inc. |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +# This script updates the Kustomize installer for monitoring with the latest Grafana, |
| 17 | +# Prometheus and Alert Manager configuration per the pgMonitor tag specified |
| 18 | + |
| 19 | +directory=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) |
| 20 | + |
| 21 | +# The pgMonitor tag to use to refresh the current monitoring installer |
| 22 | +pgmonitor_tag=v4.6-RC1 |
| 23 | + |
| 24 | +# Set the directory for the monitoring Kustomize installer |
| 25 | +pgo_examples_monitoring_dir="${directory}/../../postgres-operator-examples/kustomize/monitoring" |
| 26 | + |
| 27 | +# Create a tmp directory for checking out the pgMonitor tag |
| 28 | +tmp_dir="${directory}/pgmonitor_tmp/" |
| 29 | +mkdir -p "${tmp_dir}" |
| 30 | + |
| 31 | +# Clone the pgMonitor repo and checkout the tag provided |
| 32 | +git -C "${tmp_dir}" clone https://github.com/CrunchyData/pgmonitor.git |
| 33 | +cd "${tmp_dir}/pgmonitor" |
| 34 | +git checkout "${pgmonitor_tag}" |
| 35 | + |
| 36 | +# Deviation from pgMonitor default! |
| 37 | +# Update "${DS_PROMETHEUS}" to "PROMETHEUS" in all containers dashboards |
| 38 | +find "grafana/containers" -type f -exec \ |
| 39 | + sed -i 's/${DS_PROMETHEUS}/PROMETHEUS/' {} \; |
| 40 | +# Copy Grafana dashboards for containers |
| 41 | +cp -r "grafana/containers/." "${pgo_examples_monitoring_dir}/config/grafana/dashboards" |
| 42 | + |
| 43 | +# Deviation from pgMonitor default! |
| 44 | +# Update the dashboard location to the default for the Grafana container. |
| 45 | +sed -i 's#/etc/grafana/crunchy_dashboards#/etc/grafana/provisioning/dashboards#' \ |
| 46 | + "grafana/linux/crunchy_grafana_dashboards.yml" |
| 47 | +cp "grafana/linux/crunchy_grafana_dashboards.yml" "${pgo_examples_monitoring_dir}/config/grafana" |
| 48 | + |
| 49 | +# Deviation from pgMonitor default! |
| 50 | +# Update the URL for the Grafana data source configuration to use env vars for the Prometheus host |
| 51 | +# and port. |
| 52 | +sed -i 's#localhost:9090#$PROM_HOST:$PROM_PORT#' \ |
| 53 | + "grafana/common/crunchy_grafana_datasource.yml" |
| 54 | +cp "grafana/common/crunchy_grafana_datasource.yml" "${pgo_examples_monitoring_dir}/config/grafana" |
| 55 | + |
| 56 | +# Deviation from pgMonitor default! |
| 57 | +# Update the URL for the Grafana data source configuration to use env vars for the Prometheus host |
| 58 | +# and port. |
| 59 | +cp "prometheus/containers/crunchy-prometheus.yml.containers" "prometheus/containers/crunchy-prometheus.yml" |
| 60 | +cat << EOF >> prometheus/containers/crunchy-prometheus.yml |
| 61 | +alerting: |
| 62 | + alertmanagers: |
| 63 | + - scheme: http |
| 64 | + static_configs: |
| 65 | + - targets: |
| 66 | + - "crunchy-alertmanager:9093" |
| 67 | +EOF |
| 68 | +cp "prometheus/containers/crunchy-prometheus.yml" "${pgo_examples_monitoring_dir}/config/prometheus" |
| 69 | + |
| 70 | +# Copy the default Alert Manager configuration |
| 71 | +cp "alertmanager/common/crunchy-alertmanager.yml" "${pgo_examples_monitoring_dir}/config/alertmanager" |
| 72 | +cp "prometheus/containers/alert-rules.d/crunchy-alert-rules-pg.yml.containers.example" \ |
| 73 | + "${pgo_examples_monitoring_dir}/config/alertmanager/crunchy-alert-rules-pg.yml" |
| 74 | + |
| 75 | +# Cleanup any temporary resources |
| 76 | +rm -rf "${tmp_dir}" |
0 commit comments