- for vnfr in vnfrs:
- nsr_id = vnfr["nsr-id-ref"]
- ns_name = self.common_db.get_nsr(nsr_id)["name"]
- vnf_member_index = vnfr["member-vnf-index-ref"]
- if vnfr["_admin"]["projects_read"]:
- vnfr_project_id = vnfr["_admin"]["projects_read"][0]
- else:
- vnfr_project_id = ""
- for vdur in vnfr["vdur"]:
- resource_uuid = vdur["vim-id"]
- tags = {
- "vim_account_id": self.vim_account_id,
- "resource_uuid": resource_uuid,
- "nsr_id": nsr_id,
- "ns_name": ns_name,
- "vnf_member_index": vnf_member_index,
- "vdur_name": vdur["name"],
- "project_id": vnfr_project_id,
- }
- try:
- vm_list = self.check_vm_status(resource_uuid)
- for vm in vm_list:
- if vm["status"] == "4" and vm["deployed"] == "true":
- vm_status = 1
- else:
- vm_status = 0
- vm_status_metric = Metric(tags, "vm_status", vm_status)
- except Exception:
- log.exception("VM status is not OK!")
- vm_status_metric = Metric(tags, "vm_status", 0)
- metrics.append(vm_status_metric)
+ if self.conf.get("collector", "vm_infra_metrics"):
+ vm_infra_metrics_enabled = str(
+ self.conf.get("collector", "vm_infra_metrics")
+ ).lower() in ("yes", "true", "1")
+ else:
+ vm_infra_metrics_enabled = True
+ if vm_infra_metrics_enabled:
+ for vnfr in vnfrs:
+ nsr_id = vnfr["nsr-id-ref"]
+ ns_name = self.common_db.get_nsr(nsr_id)["name"]
+ vnf_member_index = vnfr["member-vnf-index-ref"]
+ if vnfr["_admin"]["projects_read"]:
+ vnfr_project_id = vnfr["_admin"]["projects_read"][0]
+ else:
+ vnfr_project_id = ""
+ for vdur in vnfr["vdur"]:
+ resource_uuid = vdur["vim-id"]
+ tags = {
+ "vim_account_id": self.vim_account_id,
+ "resource_uuid": resource_uuid,
+ "nsr_id": nsr_id,
+ "ns_name": ns_name,
+ "vnf_member_index": vnf_member_index,
+ "vdur_name": vdur["name"],
+ "project_id": vnfr_project_id,
+ }
+ try:
+ vm_list = self.check_vm_status(resource_uuid)
+ for vm in vm_list:
+ if vm["status"] == "4" and vm["deployed"] == "true":
+ vm_status = 1
+ else:
+ vm_status = 0
+ vm_status_metric = Metric(tags, "vm_status", vm_status)
+ except Exception:
+ log.exception("VM status is not OK!")
+ vm_status_metric = Metric(tags, "vm_status", 0)
+ metrics.append(vm_status_metric)