diff --git a/bundles/telegraf/files/telegraf.conf b/bundles/telegraf/files/telegraf.conf new file mode 100644 index 0000000..1006843 --- /dev/null +++ b/bundles/telegraf/files/telegraf.conf @@ -0,0 +1,4 @@ +<% + from tomlkit import dumps as toml_dumps + from bundlewrap.utils.text import toml_clean +%>${toml_clean(toml_dumps(repo.libs.toml.dict_to_toml(config)))} diff --git a/bundles/telegraf/items.py b/bundles/telegraf/items.py new file mode 100644 index 0000000..a287fc4 --- /dev/null +++ b/bundles/telegraf/items.py @@ -0,0 +1,73 @@ +metadata = node.metadata['telegraf'] + +telegraf_config = { + 'agent': { + 'collection_jitter': '5s', + 'debug': False, + 'flush_buffer_when_full': True, + 'flush_interval': '10s', + 'flush_jitter': '5s', + 'hostname': node.name, + 'interval': '60s', + 'metric_buffer_limit': 1_000_000, + 'quiet': False, + 'round_interval': False, + }, + 'inputs': { + 'cpu': [{ + 'percpu': False, + 'totalcpu': True, + 'fielddrop': [ + 'time_*', + ], + }], + 'disk': [{ + 'ignore_fs': [ + 'aufs', + 'devtmpfs', + 'nsfs', + 'tmpfs', + ], + }], + 'diskio': [{ + 'skip_serial_number': True, + }], + 'kernel': [{}], + 'mem': [{}], + 'net': [{ + 'interfaces': [ + 'en*', + 'eth*', + 'wg*', + 'wlp*', + ], + }], + 'nstat': [{}], + 'processes': [{}], + 'system': [{}], + **metadata.get('input_plugins', {}).get('builtin', {}), + }, + 'outputs': { + 'influxdb_v2': [{ + 'urls': [metadata['influxdb_url']], + 'token': metadata['influxdb_token'], + 'organization': metadata['influxdb_org'], + 'bucket': metadata['influxdb_bucket'], + }], + }, +} + +for config in metadata.get('input_plugins', {}).get('exec', {}).values(): + if 'exec' not in telegraf_config['inputs']: + telegraf_config['inputs']['exec'] = [] + + telegraf_config['inputs']['exec'].append(config) + +files = { + '/etc/telegraf/telegraf.conf': { + 'content_type': 'mako', + 'context': { + 'config': telegraf_config, + }, + }, +} diff --git a/bundles/telegraf/metadata.py b/bundles/telegraf/metadata.py new file mode 100644 index 0000000..cd1a03d --- /dev/null +++ b/bundles/telegraf/metadata.py @@ -0,0 +1,23 @@ +defaults = { + 'apt': { + 'packages': { + 'telegraf': {}, + }, + 'repos': { + 'influxdb': { + 'items': { + 'deb https://repos.influxdata.com/{os} {os_release} stable', + }, + }, + }, + }, + 'icinga2_api': { + 'telegraf': { + 'services': { + 'TELEGRAF PROCESS': { + 'command_on_monitored_host': '/usr/lib/nagios/plugins/check_procs -C telegraf -c 1:', + }, + }, + }, + }, +} diff --git a/groups/os.py b/groups/os.py index 5f56bce..838a2d0 100644 --- a/groups/os.py +++ b/groups/os.py @@ -29,6 +29,7 @@ groups['linux'] = { 'sudo', 'systemd', 'systemd-networkd', + 'telegraf', 'users', }, 'metadata': { @@ -50,6 +51,12 @@ groups['linux'] = { }, }, }, + 'telegraf': { + 'influxdb_url': '', + 'influxdb_token': '', + 'influxdb_org': '', + 'influxdb_bucket': '', + }, }, 'pip_command': 'pip3', }