2021-04-23 17:27:20 +00:00
|
|
|
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,
|
|
|
|
},
|
2024-07-31 15:40:36 +00:00
|
|
|
'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'] = {
|
2021-04-23 17:27:20 +00:00
|
|
|
'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': [{}],
|
2024-07-31 15:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
telegraf_config['inputs'].update(node.metadata.get('telegraf/input_plugins/builtin', {}))
|
2021-04-23 17:27:20 +00:00
|
|
|
|
2021-05-15 06:52:37 +00:00
|
|
|
# Bundlewrap can't merge lists. To work around this, telegraf/input_plugins/exec(d)
|
2021-04-24 12:39:13 +00:00
|
|
|
# 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.
|
2021-05-19 18:12:52 +00:00
|
|
|
for config in sorted(node.metadata.get('telegraf/input_plugins/exec', {}).values(), key=lambda c: ''.join(c['commands'])):
|
2021-04-23 17:27:20 +00:00
|
|
|
if 'exec' not in telegraf_config['inputs']:
|
|
|
|
telegraf_config['inputs']['exec'] = []
|
|
|
|
|
|
|
|
telegraf_config['inputs']['exec'].append(config)
|
|
|
|
|
2021-05-19 18:50:18 +00:00
|
|
|
for config in sorted(node.metadata.get('telegraf/input_plugins/execd', {}).values(), key=lambda c: ''.join(c['command'])):
|
2021-05-15 06:52:37 +00:00
|
|
|
if 'execd' not in telegraf_config['inputs']:
|
|
|
|
telegraf_config['inputs']['execd'] = []
|
|
|
|
|
|
|
|
telegraf_config['inputs']['execd'].append(config)
|
|
|
|
|
2021-06-05 13:53:02 +00:00
|
|
|
for name, config in sorted(node.metadata.get('telegraf/input_plugins/tail', {}).items()):
|
|
|
|
if 'tail' not in telegraf_config['inputs']:
|
|
|
|
telegraf_config['inputs']['tail'] = []
|
|
|
|
|
|
|
|
telegraf_config['inputs']['tail'].append(config)
|
|
|
|
|
2021-11-09 17:26:52 +00:00
|
|
|
for name, config in sorted(node.metadata.get('telegraf/input_plugins/http', {}).items()):
|
|
|
|
if 'http' not in telegraf_config['inputs']:
|
|
|
|
telegraf_config['inputs']['http'] = []
|
|
|
|
|
|
|
|
config['name_override'] = name
|
|
|
|
telegraf_config['inputs']['http'].append(config)
|
|
|
|
|
|
|
|
for name, config in sorted(node.metadata.get('telegraf/input_plugins/prometheus', {}).items()):
|
|
|
|
if 'prometheus' not in telegraf_config['inputs']:
|
|
|
|
telegraf_config['inputs']['prometheus'] = []
|
|
|
|
|
|
|
|
config['name_override'] = f'{name}_metrics'
|
|
|
|
telegraf_config['inputs']['prometheus'].append(config)
|
|
|
|
|
2021-04-23 17:27:20 +00:00
|
|
|
files = {
|
|
|
|
'/etc/telegraf/telegraf.conf': {
|
2024-03-23 09:34:41 +00:00
|
|
|
'content': repo.libs.faults.dict_as_toml(telegraf_config),
|
2021-04-24 08:05:52 +00:00
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:telegraf:restart',
|
|
|
|
},
|
|
|
|
},
|
2021-04-24 08:08:55 +00:00
|
|
|
'/etc/sudoers.d/telegraf': {
|
|
|
|
'source': 'sudoers',
|
|
|
|
'content_type': 'mako',
|
|
|
|
},
|
2021-04-24 08:05:52 +00:00
|
|
|
}
|
|
|
|
|
2021-04-24 09:44:55 +00:00
|
|
|
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',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-10-18 17:34:20 +00:00
|
|
|
directories = {
|
|
|
|
'/etc/telegraf/.cache': {
|
|
|
|
'owner': 'telegraf',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-04-24 09:44:55 +00:00
|
|
|
users = {
|
|
|
|
'telegraf': {
|
|
|
|
'groups': node.metadata.get('telegraf/additional_groups', set()),
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:telegraf:restart',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-04-24 08:05:52 +00:00
|
|
|
svc_systemd = {
|
|
|
|
'telegraf': {
|
|
|
|
'needs': {
|
|
|
|
'file:/etc/telegraf/telegraf.conf',
|
2021-04-24 09:44:55 +00:00
|
|
|
'file:/etc/systemd/system/telegraf.service.d/bundlewrap.conf',
|
|
|
|
'user:telegraf',
|
2021-04-24 08:05:52 +00:00
|
|
|
},
|
2021-04-23 17:27:20 +00:00
|
|
|
},
|
|
|
|
}
|