feat: add metrics for nameko services 4

This commit is contained in:
BryantHe 2023-07-28 11:04:33 +08:00
parent c6c5289e44
commit c50e53ad53
1 changed files with 19 additions and 16 deletions

View File

@ -330,6 +330,7 @@ def metric_config_gen(module, class_name_str):
dest_dir = module.split('.')[0]
file_name = module.split('.')[-1]
_module = __import__(module)
config_list = []
for class_name in class_name_str.split(','):
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
metric_configs_dir = os.path.join(get_directory('chassis-agent'), 'metric-configs')
template_file_path = os.path.join(metric_configs_dir, 'statsd_mapping.yml.mako')
output_file = os.path.join('.', 'statsd_mapping.yml')
template_to_file(template_file=template_file_path, dest=output_file, output_encoding='utf-8',
**{'config_list': config_list})
with status(f'Creating statsd_mapping.yml'):
metric_configs_dir = os.path.join(get_directory('chassis-agent'), 'metric-configs')
template_file_path = os.path.join(metric_configs_dir, 'statsd_mapping.yml.mako')
output_file = os.path.join('.', 'statsd_mapping.yml')
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
if not os.access('grafana_dashboards', os.F_OK):
with status(f'Creating directory {os.path.abspath("grafana_dashboards")!r}'):
os.makedirs('grafana_dashboards')
for class_name in class_name_str.split(','):
grafana_list = []
for config in config_list:
if config['class_name'] == class_name:
grafana_list.append(config)
grafana_configs_dir = os.path.join(get_directory('chassis-agent'), 'metric-configs')
grafana_file_path = os.path.join(grafana_configs_dir, 'grafana.json.mako')
output_file = os.path.join('grafana_dashboards', f'{class_name}_Grafana.json')
template_to_file(template_file=grafana_file_path, dest=output_file, output_encoding='utf-8',
**{'service_name': class_name, 'uid': shortuuid.uuid(),
'grafana_list': grafana_list})
with status(f'Creating files of Grafana.json into the directory of grafana_dashboards'):
for class_name in class_name_str.split(','):
grafana_list = []
for config in config_list:
if config['class_name'] == class_name:
grafana_list.append(config)
grafana_configs_dir = os.path.join(get_directory('chassis-agent'), 'metric-configs')
grafana_file_path = os.path.join(grafana_configs_dir, 'grafana.json.mako')
output_file = os.path.join('grafana_dashboards', f'{class_name}_Grafana.json')
template_to_file(template_file=grafana_file_path, dest=output_file, output_encoding='utf-8',
**{'service_name': class_name, 'uid': shortuuid.uuid(),
'grafana_list': grafana_list})
if __name__ == '__main__':