Skip to content

Commit

Permalink
Add Pi-Hole exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
WyriHaximus committed Nov 13, 2020
1 parent 75cdad7 commit f839831
Show file tree
Hide file tree
Showing 13 changed files with 265 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/helm-charts-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
run: |
cp charts/cron-jobs/library-ci/*.yaml charts/cron-jobs/templates/
cp charts/horizontal-pod-autoscalers/library-ci/*.yaml charts/horizontal-pod-autoscalers/templates/
cp charts/pi-hole-exporter/library-ci/*.yaml charts/pi-hole-exporter/templates/
sed -i 's/library/application/g' charts/cron-jobs/Chart.yaml
sed -i 's/library/application/g' charts/horizontal-pod-autoscalers/Chart.yaml
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Opinionated helm chats for my personal projects, and OSS Projects that either do

* [`default-backend`](https://artifacthub.io/packages/helm/wyrihaximusnet/default-backend)
* [`docker-hub-exporter`](https://artifacthub.io/packages/helm/wyrihaximusnet/docker-hub-exporter)
* [`pi-hole-exporter`](https://artifacthub.io/packages/helm/wyrihaximusnet/pi-hole-exporter)
* [`redirect`](https://artifacthub.io/packages/helm/wyrihaximusnet/redirect)
* [`redis-db-assignment-operator`](https://artifacthub.io/packages/helm/wyrihaximusnet/redis-db-assignment-operator)

Expand Down
22 changes: 22 additions & 0 deletions charts/pi-hole-exporter/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
11 changes: 11 additions & 0 deletions charts/pi-hole-exporter/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v2
name: pi-hole-exporter
description: Pi-Hole Exporter
home: https://github.com/eko/pihole-exporter
icon: https://helm.wyrihaximus.net/images/charts/pi-hole-exporter.png
type: application
version: 0.1.0
appVersion: d05df48
maintainers:
- name: WyriHaximus
email: [email protected]
22 changes: 22 additions & 0 deletions charts/pi-hole-exporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Pi-Hole Exporter

<p align="center">
<img src="https://helm.wyrihaximus.net/images/charts/pi-hole-exporter.png">
</p>

Opinionated helm chart for [`eko/pihole-exporter`](https://github.com/eko/pihole-exporter). There is an alternative
available at [`SiM22/pihole-exporter-helm-chart`](https://github.com/SiM22/pihole-exporter-helm-chart) but that didn't
meet my requirements.

## Configuration

By default, this chart will look for a secret name `pi-hole` in the same namespace for additional env vars to add to the
container. It is required that it contains the location of your [`PiHole`](https://pi-hole.net/) and a away to authenticate against it. Those
can be find [here](https://github.com/eko/pihole-exporter#using-docker). You can find an example secret file in
[`library-ci/secret.yaml`](https://github.com/WyriHaximusNet/helm-charts/blob/master/charts/pi-hole-exporter/library-ci/secret.yaml).

## Opinionated decisions

* Port is hardcoded to `9617` for the metrics.
* Metrics collection from Pi-Hole happens every 30 seconds.
* Requires you to configure a secret in the same namespace as you deploy this chart to container additional env vars.
8 changes: 8 additions & 0 deletions charts/pi-hole-exporter/library-ci/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Secret
metadata:
name: pi-hole
type: Opaque
data:
PIHOLE_HOSTNAME: UElIT0xFX0hPU1ROQU1F
PIHOLE_PASSWORD: UElIT0xFX1BBU1NXT1JE
7 changes: 7 additions & 0 deletions charts/pi-hole-exporter/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Congratulations, your prometheus compatible scraped Pi-Hole metrics are now available for scraping.

You can access them by using a port forward:
kubectl port-forward svc/{{ include ".helm.fullname" . }} 9617:9617 -n {{ .Release.Namespace }}

And then point your browser to:
http://localhost:9617/metrics
67 changes: 67 additions & 0 deletions charts/pi-hole-exporter/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define ".helm.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{- define ".helm.nameRevision" -}}
{{ template ".helm.name" . }}___{{ .Release.Revision }}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define ".helm.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define ".helm.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Common labels
*/}}
{{- define ".helm.labels" -}}
helm.sh/chart: {{ include ".helm.chart" . }}
{{ include ".helm.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}

{{/*
Selector labels
*/}}
{{- define ".helm.selectorLabels" -}}
app.kubernetes.io/name: {{ include ".helm.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}

{{/*
Create the name of the service account to use
*/}}
{{- define ".helm.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include ".helm.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}
67 changes: 67 additions & 0 deletions charts/pi-hole-exporter/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include ".helm.fullname" . }}
labels:
app: {{ include ".helm.fullname" . }}
appRevision: {{ template ".helm.nameRevision" . }}
release: {{ include ".helm.fullname" . }}
releaseRevision: {{ .Release.Revision | quote }}
{{- include ".helm.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicas }}
selector:
matchLabels:
{{- include ".helm.selectorLabels" . | nindent 6 }}
template:
metadata:
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "9617"
labels:
app: {{ include ".helm.fullname" . }}
release: {{ include ".helm.fullname" . }}
{{- include ".helm.selectorLabels" . | nindent 8 }}
spec:
containers:
- name: pi-hole-exporter
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: metrics
containerPort: 9617
protocol: TCP
livenessProbe:
httpGet:
path: /metrics
port: metrics
readinessProbe:
httpGet:
path: /metrics
port: metrics
startupProbe:
failureThreshold: 120
periodSeconds: 1
httpGet:
path: /metrics
port: metrics
resources:
{{- toYaml .Values.resources | nindent 12 }}
envFrom:
- secretRef:
name: {{ .Values.configurationSecret | quote }}
env:
- name: INTERVAL
value: "30s"
- name: PORT
value: "9617"
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- {{ template ".helm.nameRevision" . }}
topologyKey: "kubernetes.io/hostname"
12 changes: 12 additions & 0 deletions charts/pi-hole-exporter/templates/pod-disruption-budget.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if gt (.Values.replicas | int) 1 -}}
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
name: {{ include ".helm.fullname" . }}
spec:
minAvailable: 1
selector:
matchLabels:
app: {{ include ".helm.fullname" . }}
release: {{ include ".helm.fullname" . }}
{{ end }}
15 changes: 15 additions & 0 deletions charts/pi-hole-exporter/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include ".helm.fullname" . }}
labels:
{{- include ".helm.labels" . | nindent 4 }}
spec:
type: ClusterIP
ports:
- port: 9617
targetPort: metrics
protocol: TCP
name: metrics
selector:
{{- include ".helm.selectorLabels" . | nindent 4 }}
15 changes: 15 additions & 0 deletions charts/pi-hole-exporter/templates/tests/test-connection.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Pod
metadata:
name: "{{ include ".helm.fullname" . }}-test-connection"
labels:
{{ include ".helm.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": test-success
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include ".helm.fullname" . }}:9617/metrics']
restartPolicy: Never
17 changes: 17 additions & 0 deletions charts/pi-hole-exporter/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
image:
repository: ekofr/pihole-exporter
tag: 0.0.10
pullPolicy: IfNotPresent

configurationSecret: pi-hole

replicas: 1

resources:
# Setting this pretty low since this is a low resource intensive application, increase when needed
limits:
cpu: 30m
memory: 64Mi
requests:
cpu: 30m
memory: 64Mi

0 comments on commit f839831

Please sign in to comment.