in src/worker/exporters/node_exporter.py [0:0]
def init_config(job_id, port=None, ethernet_device='eth0'):
'''Example of config initialization'''
global config
if not port:
port = 8002
config = {
'exit': False,
'update_freq': 1,
'listen_port': port,
'publish_interval': 1,
'job_id': job_id,
'fieldFiles': {},
'counter': {},
'sample_timestamp': {},
'ethernet_device': ethernet_device
}
# for xid and link flaps
config['command'] = {}
cmd = "awk -F= '/^NAME/{print $2}' /etc/os-release"
result = shell_cmd(cmd, 5)
if "Ubuntu" in result:
config['command']['link_flap'] = "sudo grep 'Lost carrier' /var/log/syslog"
config['command']['xid_error'] = "sudo grep 'NVRM: Xid' /var/log/syslog"
init_nvidia_config()
init_ib_config()
elif "AlmaLinux" in result:
config['command']['link_flap'] = "sudo grep 'Lost carrier' /var/log/messages"
config['command']['xid_error'] = "sudo grep 'NVRM: Xid' /var/log/messages"
init_nvidia_config()
init_ib_config()
else:
logging.info('OS not supported attempting to continue...')
# get NUMA domain
config['num_cores'] = psutil.cpu_count()
config['cpu_numa_map'] = get_core_numa_mapping(config['num_cores'])
# initalize field specific config parameters
for field_name in FIELD_LIST:
config['sample_timestamp'][field_name] = datetime.now() - timedelta(seconds=5)
if 'net' in field_name:
config['fieldFiles'][field_name] = '/proc/net/dev'
# initialize counter, this will ensure a initial value is present
# to calculate bandwidth
cmd = "grep '{}' ".format(config['ethernet_device']) + config['fieldFiles'][field_name]
if field_name == 'net_rx':
config['counter'][field_name] = shell_cmd(cmd, 5).split()[1]
elif field_name == 'net_tx':
config['counter'][field_name] = shell_cmd(cmd, 5).split()[9]
elif 'cpu' in field_name:
if 'util' in field_name:
# Call cpu_percent to get intial 0.0 values
_ = psutil.cpu_percent(percpu=True)