Commit 94f9cc03 authored by Adnan Abdulhussein's avatar Adnan Abdulhussein Committed by GitHub

Merge pull request #269 from jackzampolin/telegraf

Add Telegraf Chart
parents 4affe5d0 0a1203c7
# 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
name: telegraf
version: 0.1.0
description: Chart for Telegraf Kubernetes deployments
keywords:
- telegraf
- collector
- timeseries
- influxdata
home: https://www.influxdata.com/time-series-platform/telegraf/
maintainers:
- name: Jack Zampolin
email: jack@influxdb.com
engine: gotpl
\ No newline at end of file
To open a shell session in the container running Telegraf run the following:
- kubectl exec -i -t --namespace {{ .Release.Namespace }} $(kubectl get pods --namespace {{ .Release.Namespace }} -l app={{ template "fullname" . }} -o jsonpath='{.items[0].metadata.name}') /bin/sh
To tail the logs for a Telegraf pod in the Daemonset run the following:
- kubectl logs -f --namespace {{ .Release.Namespace }} $(kubectl get pods --namespace {{ .Release.Namespace }} -l app={{ template "fullname" . }}-ds -o jsonpath='{ .items[0].metadata.name }')
{{- if eq .Values.single.service.type "LoadBalancer" }}
To watch for the LoadBalancer IP run the following
- kubectl get svc -w --namespace {{ .Release.Namespace }} -l app={{ template "fullname" . }}
{{- end }}
{{- if empty .Values.single.config.outputs.influxdb.urls }}
{{- if empty .Values.daemonset.config.outputs.influxdb.urls }}
Need to set an InfluxDB url for either single or daemonset to deploy this instance:
.Values.daemonset.config.outputs.influxdb.urls
.Values.single.config.outputs.influxdb.urls
{{- end }}
{{- end }}
\ No newline at end of file
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 24 -}}
{{- end -}}
{{/*
Create a default fully qualified app name.
We truncate at 24 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "fullname" -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 24 -}}
{{- end -}}
{{/*
CUSTOM TEMPLATES: This section contains templates that make up the different parts of the telegraf configuration file.
- global_tags section
- agent section
*/}}
{{- define "global_tags" -}}
{{- if . -}}
[global_tags]
{{- range $key, $val := . }}
{{ $key }} = {{ $val | quote }}
{{- end }}
{{- end }}
{{- end -}}
{{- define "agent" -}}
[agent]
{{- range $key, $value := . -}}
{{- $tp := typeOf $value }}
{{- if eq $tp "string"}}
{{ $key }} = {{ $value | quote }}
{{- end }}
{{- if eq $tp "float64"}}
{{ $key }} = {{ $value | int64 }}
{{- end }}
{{- if eq $tp "int"}}
{{ $key }} = {{ $value | int64 }}
{{- end }}
{{- if eq $tp "bool"}}
{{ $key }} = {{ $value }}
{{- end }}
{{- end }}
{{- end -}}
{{- define "outputs" -}}
{{- range $output, $config := . }}
[[outputs.{{ $output }}]]
{{- if $config }}
{{- range $key, $value := $config -}}
{{- $tp := typeOf $value }}
{{- if eq $tp "string"}}
{{ $key }} = {{ $value | quote }}
{{- end }}
{{- if eq $tp "float64"}}
{{ $key }} = {{ $value | int64 }}
{{- end }}
{{- if eq $tp "int"}}
{{ $key }} = {{ $value | int64 }}
{{- end }}
{{- if eq $tp "bool"}}
{{ $key }} = {{ $value }}
{{- end }}
{{- if eq $tp "[]interface {}" }}
{{ $key }} = [
{{- $numOut := len $value }}
{{- $numOut := sub $numOut 1 }}
{{- range $b, $val := $value }}
{{- $i := int64 $b }}
{{- if eq $i $numOut }}
{{ $val | quote }}
{{- else }}
{{ $val | quote }},
{{- end }}
{{- end }}
]
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end -}}
{{- define "inputs" -}}
{{- range $input, $config := . -}}
[[inputs.{{- $input }}]]
{{- if $config -}}
{{- range $key, $value := $config -}}
{{- $tp := typeOf $value -}}
{{- if eq $tp "string" }}
{{ $key }} = {{ $value | quote }}
{{- end }}
{{- if eq $tp "float64" }}
{{ $key }} = {{ $value | int64 }}
{{- end }}
{{- if eq $tp "int" }}
{{ $key }} = {{ $value | int64 }}
{{- end }}
{{- if eq $tp "bool" }}
{{ $key }} = {{ $value }}
{{- end }}
{{- if eq $tp "[]interface {}" }}
{{ $key }} = [
{{- $numOut := len $value }}
{{- $numOut := sub $numOut 1 }}
{{- range $b, $val := $value }}
{{- $i := int64 $b }}
{{- $tp := typeOf $val }}
{{- if eq $i $numOut }}
{{- if eq $tp "string" }}
{{ $val | quote }}
{{- end }}
{{- if eq $tp "float64" }}
{{ $val | int64 }}
{{- end }}
{{- else }}
{{- if eq $tp "string" }}
{{ $val | quote }},
{{- end}}
{{- if eq $tp "float64" }}
{{ $val | int64 }},
{{- end }}
{{- end }}
{{- end }}
]
{{- end }}
{{- if eq $tp "map[string]interface {}" }}
[[inputs.{{ $input }}.{{ $key }}]]
{{- range $k, $v := $value }}
{{- $tps := typeOf $v }}
{{- if eq $tps "string" }}
{{ $k }} = {{ $v }}
{{- end }}
{{- if eq $tps "[]interface {}"}}
{{ $k }} = [
{{- $numOut := len $value }}
{{- $numOut := sub $numOut 1 }}
{{- range $b, $val := $v }}
{{- $i := int64 $b }}
{{- if eq $i $numOut }}
{{ $val | quote }}
{{- else }}
{{ $val | quote }},
{{- end }}
{{- end }}
]
{{- end }}
{{- if eq $tps "map[string]interface {}"}}
[[inputs.{{ $input }}.{{ $key }}.{{ $k }}]]
{{- range $foo, $bar := $v }}
{{ $foo }} = {{ $bar | quote }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{ end }}
{{- end -}}
\ No newline at end of file
{{- if gt (len .Values.single.config.outputs.influxdb.urls) 0 }}
{{- if .Values.single.enabled -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "fullname" . }}-s
labels:
app: {{ template "fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
data:
telegraf.conf: |+
{{ template "global_tags" .Values.single.config.global_tags }}
{{ template "agent" .Values.single.config.agent }}
{{ template "outputs" .Values.single.config.outputs }}
{{ template "inputs" .Values.single.config.inputs -}}
{{- end -}}
{{- end -}}
\ No newline at end of file
{{- if gt (len .Values.daemonset.config.outputs.influxdb.urls) 0 }}
{{- if .Values.daemonset.enabled -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "fullname" . }}-ds
labels:
app: {{ template "fullname" . }}-ds
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
data:
telegraf.conf: |+
{{ template "global_tags" .Values.daemonset.config.global_tags }}
{{ template "agent" .Values.daemonset.config.agent }}
{{ template "outputs" .Values.daemonset.config.outputs }}
{{ template "inputs" .Values.daemonset.config.inputs -}}
{{- end -}}
{{- end -}}
\ No newline at end of file
{{- if gt (len .Values.daemonset.config.outputs.influxdb.urls) 0 }}
{{- if .Values.daemonset.enabled -}}
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: {{ template "fullname" . }}-ds
labels:
app: {{ template "fullname" . }}-ds
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
spec:
template:
metadata:
labels:
app: {{ template "fullname" . }}-ds
spec:
containers:
- name: {{ template "fullname" . }}
image: "{{ .Values.image.repo }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ default "" .Values.image.pullPolicy | quote }}
resources:
{{ toYaml .Values.daemonset.resources | indent 10 }}
env:
- name: HOSTNAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: "HOST_PROC"
value: "/rootfs/proc"
- name: "HOST_SYS"
value: "/rootfs/sys"
volumeMounts:
- name: sysro
mountPath: /rootfs/sys
readOnly: true
- name: procro
mountPath: /rootfs/proc
readOnly: true
- name: docker-socket
mountPath: /var/run/docker.sock
# readOnly: true
- name: varrunutmpro
mountPath: /var/run/utmp
readOnly: true
- name: config
mountPath: /etc/telegraf
volumes:
- name: sysro
hostPath:
path: /sys
- name: docker-socket
hostPath:
path: /var/run/docker.sock
- name: procro
hostPath:
path: /proc
- name: varrunutmpro
hostPath:
path: /var/run/utmp
- name: config
configMap:
name: {{ template "fullname" . }}-ds
{{- end -}}
{{- end -}}
\ No newline at end of file
{{- if gt (len .Values.single.config.outputs.influxdb.urls) 0 }}
{{- if .Values.single.enabled -}}
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ template "fullname" . }}-s
labels:
app: {{ template "fullname" . }}-s
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
spec:
replicas: 1
template:
metadata:
labels:
app: {{ template "fullname" . }}-s
spec:
containers:
- name: {{ template "fullname" . }}
image: "{{ .Values.image.repo }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ default "" .Values.image.pullPolicy | quote }}
resources:
{{ toYaml .Values.single.resources | indent 10 }}
volumeMounts:
- name: config
mountPath: /etc/telegraf
volumes:
- name: config
configMap:
name: {{ template "fullname" . }}-s
{{- end -}}
{{- end -}}
\ No newline at end of file
{{- if .Values.single.enabled -}}
{{- if .Values.single.service.enabled -}}
apiVersion: v1
kind: Service
metadata:
name: {{ template "fullname" . }}-s
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
spec:
type: {{ .Values.single.service.type }}
ports:
{{- range $key, $value := .Values.single.config.inputs }}
{{- if eq $key "http_listener" }}
- port: {{ trimPrefix ":" $value.service_address | int64 }}
targetPort: {{ trimPrefix ":" $value.service_address | int64 }}
name: "http-listener"
{{- end }}
{{- if eq $key "statsd" }}
- port: {{ trimPrefix ":" $value.service_address | int64 }}
targetPort: {{ trimPrefix ":" $value.service_address | int64 }}
name: "statsd"
{{- end }}
{{- if eq $key "tcp-listener" }}
- port: {{ trimPrefix ":" $value.service_address | int64 }}
targetPort: {{ trimPrefix ":" $value.service_address | int64 }}
name: "tcp_listener"
{{- end }}
{{- if eq $key "udp-listener" }}
- port: {{ trimPrefix ":" $value.service_address | int64 }}
targetPort: {{ trimPrefix ":" $value.service_address | int64 }}
name: "udp_listener"
{{- end }}
{{- if eq $key "webhooks" }}
- port: {{ trimPrefix ":" $value.service_address | int64 }}
targetPort: {{ trimPrefix ":" $value.service_address | int64 }}
name: "webhooks"
{{- end }}
{{- end }}
selector:
app: {{ template "fullname" . }}-s
{{- end -}}
{{- end -}}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment