Skip to content

Commit

Permalink
Allow Inputs Loop in Telegraf-DS like in Telegraf (#557)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulojmdias authored Sep 1, 2023
1 parent 65564b1 commit cf607dc
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 23 deletions.
2 changes: 1 addition & 1 deletion charts/telegraf-ds/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v1
name: telegraf-ds
version: 1.1.14
version: 1.1.15
appVersion: 1.27.4
deprecated: false
description: Telegraf is an agent written in Go for collecting, processing, aggregating, and writing metrics.
Expand Down
110 changes: 110 additions & 0 deletions charts/telegraf-ds/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,116 @@ app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{- end -}}

{{- define "inputs" -}}
{{- range $inputIdx, $configObject := . -}}
{{- range $input, $config := . -}}

[[inputs.{{- $input }}]]
{{- if $config -}}
{{- $tp := typeOf $config -}}
{{- if eq $tp "map[string]interface {}" -}}
{{- 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 {}" }}
{{- if eq (index $value 0 | typeOf) "map[string]interface {}" -}}
{{- range $b, $val := $value }}
[[inputs.{{- $input }}.{{- $key }}]]
{{- range $k, $v := $val }}
{{- $tps := typeOf $v }}
{{- if eq $tps "string" }}
{{ $k }} = {{ $v | quote }}
{{- end }}
{{- if eq $tps "float64" }}
{{ $k }} = {{ $v | int64 }}
{{- end }}
{{- if eq $tps "bool" }}
{{ $k }} = {{ $v }}
{{- end }}
{{- end }}
{{- end }}
{{- else }}
{{ $key }} = [
{{- $numOut := len $value }}
{{- $numOut := sub $numOut 1 }}
{{- range $b, $val := $value }}
{{- $i := int64 $b }}
{{- $tp := typeOf $val }}
{{- if eq $tp "string" }}
{{ $val | quote }}
{{- end }}
{{- if eq $tp "float64" }}
{{- if eq $key "percentiles" }}
{{- $xval := float64 (int64 $val) }}
{{- if eq $val $xval }}
{{ $val | int64 }}.0
{{- else }}
{{ $val | float64 }}
{{- end }}
{{- else }}
{{ $val | int64 }}
{{- end }}
{{- end }}
{{- if ne $i $numOut -}}
,
{{- end -}}
{{- end }}
]
{{- end }}
{{- end }}
{{- end }}
{{- range $key, $value := $config -}}
{{- $tp := typeOf $value -}}
{{- if eq $tp "map[string]interface {}" }}
[inputs.{{ $input }}.{{ $key }}]
{{- range $k, $v := $value }}
{{- $tps := typeOf $v }}
{{- if eq $tps "string" }}
{{ $k }} = {{ $v | quote }}
{{- end }}
{{- if eq $tps "[]interface {}"}}
{{ $k }} = [
{{- $numOut := len $v }}
{{- $numOut := sub $numOut 1 }}
{{- range $b, $val := $v }}
{{- $i := int64 $b }}
{{- if eq $i $numOut }}
{{ $val | quote }}
{{- else }}
{{ $val | quote }},
{{- end }}
{{- end }}
]
{{- end }}
{{- end }}
{{- range $k, $v := $value }}
{{- $tps := typeOf $v }}
{{- 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 }}
{{- end }}
{{- end -}}

{{/*
Create the name of the service account to use
*/}}
Expand Down
23 changes: 1 addition & 22 deletions charts/telegraf-ds/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,10 @@ data:
{{ template "aggregators" .Values.config.aggregators }}
{{ template "outputs" .Values.config.outputs }}
{{ template "monitor_self" .Values.config.monitor_self }}
[[inputs.diskio]]
[[inputs.kernel]]
[[inputs.mem]]
[[inputs.net]]
[[inputs.processes]]
[[inputs.swap]]
[[inputs.system]]
[[inputs.cpu]]
percpu = true
totalcpu = true
collect_cpu_time = false
report_active = false
[[inputs.disk]]
ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"]
{{ template "inputs" .Values.config.inputs }}
{{- if .Values.config.docker_endpoint }}
[[inputs.docker]]
endpoint = {{ .Values.config.docker_endpoint | quote }}
{{- end }}
[[inputs.kubernetes]]
url = "https://$HOSTIP:10250"
bearer_token = "/var/run/secrets/kubernetes.io/serviceaccount/token"
insecure_skip_verify = true
{{- end }}
26 changes: 26 additions & 0 deletions charts/telegraf-ds/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,32 @@ config:
logfile: ""
hostname: "$HOSTNAME"
omit_hostname: false
inputs:
- diskio: {}
- kernel: {}
- mem: {}
- net: {}
- processes: {}
- swap: {}
- system: {}
- cpu:
percpu: true
totalcpu: true
collect_cpu_time: false
report_active: false
- disk:
ignore_fs:
- tmpfs
- devtmpfs
- devfs
- iso9660
- overlay
- aufs
- squashfs
- kubernetes:
url: "https://$HOSTIP:10250"
bearer_token: "/var/run/secrets/kubernetes.io/serviceaccount/token"
insecure_skip_verify: true
outputs:
- influxdb:
urls:
Expand Down

0 comments on commit cf607dc

Please sign in to comment.