From 7badbfad0b37af5688ef0b1481fd71eae65c575a Mon Sep 17 00:00:00 2001 From: Mohammed Naser Date: Tue, 21 Jul 2020 16:58:28 -0400 Subject: [PATCH] Added HAproxy exporter Change-Id: I99124d11639505c76bafcfe9be622135382e3f09 --- charts/haproxy-exporter/Chart.yaml | 11 +++++ .../haproxy-exporter/templates/_helpers.tpl | 45 ++++++++++++++++++ .../haproxy-exporter/templates/daemonset.yaml | 47 +++++++++++++++++++ .../templates/prometheusrule.yaml | 32 +++++++++++++ .../haproxy-exporter/templates/service.yaml | 16 +++++++ .../templates/servicemonitor.yaml | 23 +++++++++ charts/haproxy-exporter/values.yaml | 1 + 7 files changed, 175 insertions(+) create mode 100644 charts/haproxy-exporter/Chart.yaml create mode 100644 charts/haproxy-exporter/templates/_helpers.tpl create mode 100644 charts/haproxy-exporter/templates/daemonset.yaml create mode 100644 charts/haproxy-exporter/templates/prometheusrule.yaml create mode 100644 charts/haproxy-exporter/templates/service.yaml create mode 100644 charts/haproxy-exporter/templates/servicemonitor.yaml create mode 100644 charts/haproxy-exporter/values.yaml diff --git a/charts/haproxy-exporter/Chart.yaml b/charts/haproxy-exporter/Chart.yaml new file mode 100644 index 0000000..8f5c154 --- /dev/null +++ b/charts/haproxy-exporter/Chart.yaml @@ -0,0 +1,11 @@ +--- +apiVersion: v1 +name: haproxy-exporter +version: 0.3.1 +description: HAProxy exporter for Prometheus +home: https://github.com/vexxhost/helm-charts +maintainers: +- name: Mohammed Naser + email: mnaser@vexxhost.com + url: https://github.com/mnaser +appVersion: v0.10.0 diff --git a/charts/haproxy-exporter/templates/_helpers.tpl b/charts/haproxy-exporter/templates/_helpers.tpl new file mode 100644 index 0000000..ee9ed32 --- /dev/null +++ b/charts/haproxy-exporter/templates/_helpers.tpl @@ -0,0 +1,45 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "haproxy-exporter.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- 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 "haproxy-exporter.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 -}} + +{{/* +Generate basic labels +*/}} +{{- define "haproxy-exporter.labels" }} +app.kubernetes.io/name: {{ include "haproxy-exporter.fullname" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +app.kubernetes.io/component: metrics +app.kubernetes.io/part-of: haproxy +{{- if .Values.commonLabels }} +{{ toYaml .Values.commonLabels }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "haproxy-exporter.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} \ No newline at end of file diff --git a/charts/haproxy-exporter/templates/daemonset.yaml b/charts/haproxy-exporter/templates/daemonset.yaml new file mode 100644 index 0000000..cddd6fc --- /dev/null +++ b/charts/haproxy-exporter/templates/daemonset.yaml @@ -0,0 +1,47 @@ +--- +apiVersion: apps/v1 +kind: DaemonSet +metadata: + namespace: {{ .Release.Namespace }} + name: {{ include "haproxy-exporter.fullname" . }} + labels: +{{ include "haproxy-exporter.labels" $ | indent 4 }} +spec: + selector: + matchLabels: +{{ include "haproxy-exporter.labels" $ | indent 6 }} + template: + metadata: + labels: +{{ include "haproxy-exporter.labels" $ | indent 8 }} + spec: + containers: + - name: haproxy-exporter + image: prom/haproxy-exporter:v0.10.0 + args: + - --haproxy.scrape-uri=unix:/var/run/haproxy.stat + resources: + limits: + cpu: 500m + memory: 180Mi + requests: + cpu: 250m + memory: 180Mi + volumeMounts: + - name: haproxy-socket + mountPath: /var/run/haproxy.stat + ports: + - name: metrics + containerPort: 9101 + {{- with $.Values.tolerations }} + tolerations: +{{ toYaml . | indent 8 }} + {{- end }} + {{- with $.Values.nodeSelector }} + nodeSelector: +{{ toYaml . | indent 8 }} + {{- end }} + volumes: + - name: haproxy-socket + hostPath: + path: /var/run/haproxy.stat \ No newline at end of file diff --git a/charts/haproxy-exporter/templates/prometheusrule.yaml b/charts/haproxy-exporter/templates/prometheusrule.yaml new file mode 100644 index 0000000..3502702 --- /dev/null +++ b/charts/haproxy-exporter/templates/prometheusrule.yaml @@ -0,0 +1,32 @@ +--- +apiVersion: monitoring.coreos.com/v1 +kind: PrometheusRule +metadata: + namespace: {{ .Release.Namespace }} + name: {{ include "haproxy-exporter.fullname" . }} + labels: +{{ include "haproxy-exporter.labels" $ | indent 4 }} +spec: + groups: + - name: haproxy + rules: + - alert: HaproxyDown + expr: | + absent(haproxy_up == 1) + for: 1m + labels: + severity: critical + + - alert: HaproxyBackendDown + for: 1m + expr: | + haproxy_backend_up != 1 + labels: + severity: P2 + + - alert: HaproxyBackendDegraded + expr: | + avg(haproxy_server_up) by (instance, backend, server) != 1 + for: 1m + labels: + severity: P3 \ No newline at end of file diff --git a/charts/haproxy-exporter/templates/service.yaml b/charts/haproxy-exporter/templates/service.yaml new file mode 100644 index 0000000..251f29f --- /dev/null +++ b/charts/haproxy-exporter/templates/service.yaml @@ -0,0 +1,16 @@ +--- +apiVersion: v1 +kind: Service +metadata: + namespace: {{ .Release.Namespace }} + name: {{ include "haproxy-exporter.fullname" . }} + labels: +{{ include "haproxy-exporter.labels" $ | indent 4 }} +spec: + clusterIP: None + ports: + - name: metrics + port: 9101 + targetPort: metrics + selector: +{{ include "haproxy-exporter.labels" $ | indent 4 }} \ No newline at end of file diff --git a/charts/haproxy-exporter/templates/servicemonitor.yaml b/charts/haproxy-exporter/templates/servicemonitor.yaml new file mode 100644 index 0000000..74d64cd --- /dev/null +++ b/charts/haproxy-exporter/templates/servicemonitor.yaml @@ -0,0 +1,23 @@ +--- +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + namespace: {{ .Release.Namespace }} + name: {{ include "haproxy-exporter.fullname" . }} + labels: +{{ include "haproxy-exporter.labels" $ | indent 4 }} +spec: + endpoints: + - interval: 30s + port: metrics + relabelings: + - action: replace + regex: (.*) + replacement: ${1}:9101 + sourceLabels: + - __meta_kubernetes_pod_node_name + targetLabel: instance + jobLabel: jobLabel + selector: + matchLabels: +{{ include "haproxy-exporter.labels" $ | indent 6 }} \ No newline at end of file diff --git a/charts/haproxy-exporter/values.yaml b/charts/haproxy-exporter/values.yaml new file mode 100644 index 0000000..ed97d53 --- /dev/null +++ b/charts/haproxy-exporter/values.yaml @@ -0,0 +1 @@ +---