bundlewrap/bundles/telegraf/items.py

124 lines
3.1 KiB
Python

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,
},
'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()),
'needs': {
'pkg_apt:telegraf',
},
'triggers': {
'svc_systemd:telegraf:restart',
},
},
}
svc_systemd = {
'telegraf': {
'needs': {
'file:/etc/telegraf/telegraf.conf',
'file:/etc/systemd/system/telegraf.service.d/bundlewrap.conf',
'pkg_apt:telegraf',
'user:telegraf',
},
},
}