Skip to content

Commit

Permalink
Create templates for grafana and prometheus (hashicorp#802)
Browse files Browse the repository at this point in the history
* Create templates for grafana and prometheus
  • Loading branch information
Ashwin Venkatesh authored and thisisnotashwin committed Mar 10, 2021
1 parent 0532464 commit c39b731
Show file tree
Hide file tree
Showing 9 changed files with 2,868 additions and 0 deletions.
1,981 changes: 1,981 additions & 0 deletions addons/dashboards/consul-server-monitoring.json

Large diffs are not rendered by default.

67 changes: 67 additions & 0 deletions addons/gen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env bash

WD=$(dirname "$0")
WD=$(cd "$WD"; pwd)

set -eux

TEMPLATES="${WD}/../templates"
DASHBOARDS="${WD}/dashboards"
TMP=$(mktemp -d)

# create Prometheus template
helm template prometheus prometheus \
--repo https://prometheus-community.github.io/helm-charts \
--namespace "replace-me-namespace" \
--version 13.2.1 \
-f "${WD}/values/prometheus.yaml" \
> "${TEMPLATES}/prometheus.yaml"

# Find and replace `replace-me-namespace` with `{{ .Release.Namespace }}` in Prometheus template.
sed -i'.orig' 's/replace-me-namespace/{{ .Release.Namespace }}/g' "${TEMPLATES}/prometheus.yaml"
# Add a comment to the top of the template file mentioning that the file is auto-generated.
sed -i'.orig' '1i\
# This file is auto-generated, see addons/gen.sh
' "${TEMPLATES}/prometheus.yaml"
# Add `{{- if .Values.prometheus.enabled }} to the top of the Prometheus template to ensure it is only templated when enabled.
sed -i'.orig' '1i\
{{- if .Values.prometheus.enabled }}
' "${TEMPLATES}/prometheus.yaml"
# Add `{{- end }} to the bottom of the Prometheus template to ensure it is only templated when enabled (closes the `if` statement).
sed -i'.orig' -e '$a\
{{- end }}' "${TEMPLATES}/prometheus.yaml"
# Remove the `prometheus.yaml.orig` file that is created as a side-effect of the `sed` command on OS X.
rm "${TEMPLATES}/prometheus.yaml.orig"

# create Grafana template
{
helm template grafana grafana \
--repo https://grafana.github.io/helm-charts \
--namespace "replace-me-namespace" \
--version 6.2.1 \
-f "${WD}/values/grafana.yaml"

# Set up grafana dashboards and reduce to a single line json to avoid Kubernetes size limits of 1MiB.
< "${DASHBOARDS}/consul-server-monitoring.json" jq -c > "${TMP}/consul-server-monitoring.json"
echo -e "\n---\n"
kubectl create configmap -n "replace-me-namespace" consul-grafana-dashboards \
--dry-run=client -oyaml \
--from-file=consul-server-monitoring.json="${TMP}/consul-server-monitoring.json"

} > "${TEMPLATES}/grafana.yaml"

# Find and replace `replace-me-namespace` with `{{ .Release.Namespace }}` in Grafana template.
sed -i'.orig' 's/replace-me-namespace/{{ .Release.Namespace }}/g' "${TEMPLATES}/grafana.yaml"
# Add a comment to the top of the template file mentioning that the file is auto-generated.
sed -i'.orig' '1i\
# This file is auto-generated, see addons/gen.sh
' "${TEMPLATES}/grafana.yaml"
# Add `{{- if .Values.grafana.enabled }} to the top of the Grafana template to ensure it is only templated when enabled.
sed -i'.orig' '1i\
{{- if .Values.grafana.enabled }}
' "${TEMPLATES}/grafana.yaml"
# Add `{{- end }} to the bottom of the Grafana template to ensure it is only templated when enabled (closes the `if` statement).
sed -i'.orig' -e '$a\
{{- end }}' "${TEMPLATES}/grafana.yaml"
# Remove the `grafana.yaml.orig` file that is created as a side-effect of the `sed` command on OS X.
rm "${TEMPLATES}/grafana.yaml.orig"
59 changes: 59 additions & 0 deletions addons/values/grafana.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
rbac:
create: false
pspEnabled: false

# Disable test pods
testFramework:
enabled: false

podLabels:
app: grafana

podAnnotations:
"consul.hashicorp.com/connect-inject": "false"

# Disable authentication
admin:
existingSecret: true
ldap:
existingSecret: true
env:
GF_SECURITY_ADMIN_USER: "-"
GF_SECURITY_ADMIN_PASSWORD: "-"
GF_AUTH_BASIC_ENABLED: "false"
GF_AUTH_ANONYMOUS_ENABLED: "true"
GF_AUTH_ANONYMOUS_ORG_ROLE: Admin

service:
port: 3000

# Setup dashboards
dashboardProviders:
dashboardproviders.yaml:
apiVersion: 1
providers:
- name: 'consul'
orgId: 1
folder: 'consul'
type: file
disableDeletion: false
options:
path: /var/lib/grafana/dashboards/consul

dashboardsConfigMaps:
consul: "consul-grafana-dashboards"

# Configure the prometheus data source. We expect prometheus:9090 in the same namespace.
datasources:
datasources.yaml:
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
orgId: 1
url: http://prometheus:9090
access: proxy
isDefault: true
jsonData:
timeInterval: 5s
editable: true
21 changes: 21 additions & 0 deletions addons/values/prometheus.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Disable non-essential components
alertmanager:
enabled: false
pushgateway:
enabled: false
kubeStateMetrics:
enabled: false
nodeExporter:
enabled: false
server:
podAnnotations:
"consul.hashicorp.com/connect-inject": "false"
persistentVolume:
enabled: false
service:
servicePort: 9090
readinessProbeInitialDelay: 0
# Speed up scraping a bit from the default
global:
scrape_interval: 15s
fullnameOverride: prometheus
201 changes: 201 additions & 0 deletions templates/grafana.yaml

Large diffs are not rendered by default.

Loading

0 comments on commit c39b731

Please sign in to comment.