Skip to content

Instantly share code, notes, and snippets.

@viq
Last active August 4, 2019 23:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viq/6e913db7ee6e811fba403c779bbc1465 to your computer and use it in GitHub Desktop.
Save viq/6e913db7ee6e811fba403c779bbc1465 to your computer and use it in GitHub Desktop.
Generate telegraf config for multiple nightscout servers
#!/bin/bash
cat << END
[agent]
omit_hostname = true
[[outputs.file]]
files = ["stdout"]
data_format = "influx"
[[inputs.http]]
urls = [
END
while read name url
do
cat << END
"${url}/api/v1/entries.json?count=1&name=${name}",
END
done < nightscouts
cat << END
]
data_format = "json"
json_string_fields = [
"dateString",
"sysTime",
"device",
"direction"
]
json_name_key = "type"
json_time_key = "date"
json_time_format = "unix_ms"
[[inputs.http]]
name_override = "openaps_suggested"
urls = [
END
while read name url
do
cat << END
"${url}/api/v1/devicestatus.json?count=1&name=${name}",
END
done < nightscouts
cat << END
]
data_format = "json"
json_query = "0.openaps.suggested"
json_string_fields = [
"created_at",
"device",
"reason",
"deliverAt"
]
json_time_key = "deliverAt"
json_time_format = "2006-01-02T15:04:05Z07:00"
fielddrop = [
"predBGs_*",
]
[[inputs.http]]
name_override = "treatments"
urls = [
END
while read name url
do
cat << END
"${url}/api/v1/treatments.json?count=1&name=${name}",
END
done < nightscouts
cat << END
]
data_format = "json"
json_string_fields = [
"eventType",
"glucoseType",
"boluscalc_profile"
]
json_time_key = "created_at"
json_time_format = "2006-01-02T15:04:05Z07:00"
[[processors.regex]]
[[processors.regex.tags]]
key = "url"
pattern = "https://.*/api/.*&name=(.*)"
replacement = "\${1}"
[[processors.rename]]
[[processors.rename.replace]]
tag = "url"
dest = "name"
[[processors.printer]]
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment