feat: add metrics for nameko services 4
This commit is contained in:
parent
c6c5289e44
commit
c50e53ad53
|
@ -330,6 +330,7 @@ def metric_config_gen(module, class_name_str):
|
||||||
dest_dir = module.split('.')[0]
|
dest_dir = module.split('.')[0]
|
||||||
file_name = module.split('.')[-1]
|
file_name = module.split('.')[-1]
|
||||||
_module = __import__(module)
|
_module = __import__(module)
|
||||||
|
|
||||||
config_list = []
|
config_list = []
|
||||||
for class_name in class_name_str.split(','):
|
for class_name in class_name_str.split(','):
|
||||||
members = inspect.getmembers(getattr(getattr(_module, file_name), class_name), predicate=inspect.isfunction)
|
members = inspect.getmembers(getattr(getattr(_module, file_name), class_name), predicate=inspect.isfunction)
|
||||||
|
@ -346,28 +347,30 @@ def metric_config_gen(module, class_name_str):
|
||||||
})
|
})
|
||||||
|
|
||||||
# Generate one file of statsd config yaml for statsd exporter
|
# Generate one file of statsd config yaml for statsd exporter
|
||||||
metric_configs_dir = os.path.join(get_directory('chassis-agent'), 'metric-configs')
|
with status(f'Creating statsd_mapping.yml'):
|
||||||
template_file_path = os.path.join(metric_configs_dir, 'statsd_mapping.yml.mako')
|
metric_configs_dir = os.path.join(get_directory('chassis-agent'), 'metric-configs')
|
||||||
output_file = os.path.join('.', 'statsd_mapping.yml')
|
template_file_path = os.path.join(metric_configs_dir, 'statsd_mapping.yml.mako')
|
||||||
template_to_file(template_file=template_file_path, dest=output_file, output_encoding='utf-8',
|
output_file = os.path.join('.', 'statsd_mapping.yml')
|
||||||
**{'config_list': config_list})
|
template_to_file(template_file=template_file_path, dest=output_file, output_encoding='utf-8',
|
||||||
|
**{'config_list': config_list})
|
||||||
|
|
||||||
# Generate files of json for grafana dashboard
|
# Generate files of json for grafana dashboard
|
||||||
if not os.access('grafana_dashboards', os.F_OK):
|
if not os.access('grafana_dashboards', os.F_OK):
|
||||||
with status(f'Creating directory {os.path.abspath("grafana_dashboards")!r}'):
|
with status(f'Creating directory {os.path.abspath("grafana_dashboards")!r}'):
|
||||||
os.makedirs('grafana_dashboards')
|
os.makedirs('grafana_dashboards')
|
||||||
|
|
||||||
for class_name in class_name_str.split(','):
|
with status(f'Creating files of Grafana.json into the directory of grafana_dashboards'):
|
||||||
grafana_list = []
|
for class_name in class_name_str.split(','):
|
||||||
for config in config_list:
|
grafana_list = []
|
||||||
if config['class_name'] == class_name:
|
for config in config_list:
|
||||||
grafana_list.append(config)
|
if config['class_name'] == class_name:
|
||||||
grafana_configs_dir = os.path.join(get_directory('chassis-agent'), 'metric-configs')
|
grafana_list.append(config)
|
||||||
grafana_file_path = os.path.join(grafana_configs_dir, 'grafana.json.mako')
|
grafana_configs_dir = os.path.join(get_directory('chassis-agent'), 'metric-configs')
|
||||||
output_file = os.path.join('grafana_dashboards', f'{class_name}_Grafana.json')
|
grafana_file_path = os.path.join(grafana_configs_dir, 'grafana.json.mako')
|
||||||
template_to_file(template_file=grafana_file_path, dest=output_file, output_encoding='utf-8',
|
output_file = os.path.join('grafana_dashboards', f'{class_name}_Grafana.json')
|
||||||
**{'service_name': class_name, 'uid': shortuuid.uuid(),
|
template_to_file(template_file=grafana_file_path, dest=output_file, output_encoding='utf-8',
|
||||||
'grafana_list': grafana_list})
|
**{'service_name': class_name, 'uid': shortuuid.uuid(),
|
||||||
|
'grafana_list': grafana_list})
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue