From a1eb9cb3fc058a6c0ea77aec5558896ad3a775a9 Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Wed, 31 Jul 2024 17:40:36 +0200 Subject: [PATCH] bundles/telegraf: add option to opt-out of default metrics --- bundles/telegraf/items.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/bundles/telegraf/items.py b/bundles/telegraf/items.py index 81b6375..4ee5ef2 100644 --- a/bundles/telegraf/items.py +++ b/bundles/telegraf/items.py @@ -11,7 +11,19 @@ telegraf_config = { 'quiet': False, 'round_interval': False, }, - 'inputs': { + 'outputs': { + 'influxdb_v2': [{ + 'urls': [node.metadata.get('telegraf/influxdb_url', repo.libs.defaults.influxdb_url)], + 'token': node.metadata.get('telegraf/influxdb_token', repo.vault.decrypt(repo.libs.defaults.influxdb_token)), + 'organization': node.metadata.get('telegraf/influxdb_org', repo.vault.decrypt(repo.libs.defaults.influxdb_org)), + 'bucket': node.metadata.get('telegraf/influxdb_bucket', repo.vault.decrypt(repo.libs.defaults.influxdb_bucket)), + }], + }, + 'inputs': {}, +} + +if node.metadata.get('telegraf/collect_default_metrics', True): + telegraf_config['inputs'] = { 'cpu': [{ 'percpu': False, 'totalcpu': True, @@ -43,17 +55,9 @@ telegraf_config = { 'nstat': [{}], 'processes': [{}], 'system': [{}], - **node.metadata.get('telegraf/input_plugins/builtin', {}), - }, - 'outputs': { - 'influxdb_v2': [{ - 'urls': [node.metadata.get('telegraf/influxdb_url', repo.libs.defaults.influxdb_url)], - 'token': node.metadata.get('telegraf/influxdb_token', repo.vault.decrypt(repo.libs.defaults.influxdb_token)), - 'organization': node.metadata.get('telegraf/influxdb_org', repo.vault.decrypt(repo.libs.defaults.influxdb_org)), - 'bucket': node.metadata.get('telegraf/influxdb_bucket', repo.vault.decrypt(repo.libs.defaults.influxdb_bucket)), - }], - }, -} + } + +telegraf_config['inputs'].update(node.metadata.get('telegraf/input_plugins/builtin', {})) # Bundlewrap can't merge lists. To work around this, telegraf/input_plugins/exec(d) # is a dict, of which we only use the value of it. This also allows us