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': [{}], **node.metadata.get('telegraf/input_plugins/builtin', {}), }, 'outputs': { 'influxdb_v2': [{ 'urls': [node.metadata['telegraf']['influxdb_url']], 'token': node.metadata['telegraf']['influxdb_token'], 'organization': node.metadata['telegraf']['influxdb_org'], 'bucket': node.metadata['telegraf']['influxdb_bucket'], }], }, } # 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 # to overwrite values set by metadata defaults/reactors in node and group # metadata, if needed. for config in sorted(node.metadata.get('telegraf/input_plugins/exec', {}).values(), key=lambda c: ''.join(c['commands'])): if 'exec' not in telegraf_config['inputs']: telegraf_config['inputs']['exec'] = [] telegraf_config['inputs']['exec'].append(config) for config in sorted(node.metadata.get('telegraf/input_plugins/execd', {}).values(), key=lambda c: ''.join(c['command'])): if 'execd' not in telegraf_config['inputs']: telegraf_config['inputs']['execd'] = [] telegraf_config['inputs']['execd'].append(config) files = { '/etc/telegraf/telegraf.conf': { 'content_type': 'mako', 'context': { 'config': telegraf_config, }, 'triggers': { 'svc_systemd:telegraf:restart', }, }, '/etc/sudoers.d/telegraf': { 'source': 'sudoers', 'content_type': 'mako', }, } if node.metadata.get('telegraf/additional_capabilities', set()): files['/etc/systemd/system/telegraf.service.d/bundlewrap.conf'] = { 'source': 'override.conf', 'content_type': 'mako', 'context': { 'capabilities': node.metadata['telegraf']['additional_capabilities'], }, 'triggers': { 'action:systemd-reload', 'svc_systemd:telegraf:restart', }, } else: files['/etc/systemd/system/telegraf.service.d/bundlewrap.conf'] = { 'delete': True, 'triggers': { 'action:systemd-reload', 'svc_systemd:telegraf:restart', }, } users = { 'telegraf': { 'groups': node.metadata.get('telegraf/additional_groups', set()), 'triggers': { 'svc_systemd:telegraf:restart', }, }, } svc_systemd = { 'telegraf': { 'needs': { 'file:/etc/telegraf/telegraf.conf', 'file:/etc/systemd/system/telegraf.service.d/bundlewrap.conf', 'user:telegraf', }, }, } if node.has_bundle('apt'): svc_systemd['telegraf']['needs'].add('pkg_apt:telegraf') users['telegraf']['needs'] = { 'pkg_apt:telegraf', } # Arch users: install telegraf or telegraf-bin from AUR