Пример #1
0
 def _get_metrics_from_service_type(self, metric_information):
     if metric_information.is_aggregated:
         path = EtcdHelper.build_etcd_path([self._dynamite_config.ETCD.metrics_base_path, metric_information.service_type])
         self._get_metrics_from_instance("", path, metric_information)
     else:
         uuid_paths = self._get_instance_uuid_paths(metric_information.service_type)
         for uuid_path in uuid_paths:
             uuid = self._get_key_name_from_etcd_path(uuid_path)
             path = EtcdHelper.build_etcd_path([self._dynamite_config.ETCD.metrics_base_path, metric_information.service_type])
             self._get_metrics_from_instance(uuid, path, metric_information)
Пример #2
0
 def _build_services_path(self, resource):
     return EtcdHelper.build_etcd_path([
         self._services_base_path,
         resource.service_type,
         resource.instance_uuid,
         "service_instance_name"
     ])
Пример #3
0
    def _get_metrics_from_instance(self, uuid, path_to_service_type,
                                   metric_information):
        metric_name = metric_information.metric_name

        metrics_path = EtcdHelper.build_etcd_path(
            [path_to_service_type, uuid, metric_name])

        try:
            metric_folder = self.etcdctl.read(metrics_path,
                                              recursive=True,
                                              sorted=True)
            values = []
            for timestamp_node in metric_folder.children:
                if timestamp_node.value is not None:
                    value = self._read_value_from_etcd_node(
                        timestamp_node, metric_information)
                    values.append(value)
                    self._delete_key_in_etcd(timestamp_node.key)
            if len(values) > 0:
                self._create_and_send_metrics_message(metric_information, uuid,
                                                      values)
            else:
                self._logger.debug(
                    "No metrics found for metric {} in path {}".format(
                        metric_name, metrics_path))
        except etcd.EtcdKeyNotFound:
            self._logger.debug(
                "Could not find etcd key of metric %s in path %s", metric_name,
                metrics_path)
Пример #4
0
 def _build_metrics_path(self, event):
     return EtcdHelper.build_etcd_path([
         self._metrics_base_path,
         event.resource.service_type,
         event.resource.instance_uuid,
         event.resource.metric_name,
         event.get_formatted_time()
     ])
Пример #5
0
 def _get_metrics_from_service_type(self, metric_information):
     if metric_information.is_aggregated:
         path = EtcdHelper.build_etcd_path([
             self._dynamite_config.ETCD.metrics_base_path,
             metric_information.service_type
         ])
         self._get_metrics_from_instance("", path, metric_information)
     else:
         uuid_paths = self._get_instance_uuid_paths(
             metric_information.service_type)
         for uuid_path in uuid_paths:
             uuid = self._get_key_name_from_etcd_path(uuid_path)
             path = EtcdHelper.build_etcd_path([
                 self._dynamite_config.ETCD.metrics_base_path,
                 metric_information.service_type
             ])
             self._get_metrics_from_instance(uuid, path, metric_information)
Пример #6
0
    def _get_instance_uuid_paths(self, service_type):
        try:
            service_type_path = EtcdHelper.build_etcd_path(
                [self._dynamite_config.ETCD.metrics_base_path, service_type])
            uuid_nodes = self.etcdctl.read(service_type_path)

            uuid_paths = []
            for uuid_node in uuid_nodes.children:
                uuid_paths.append(uuid_node.key)
            return uuid_paths

        except etcd.EtcdKeyNotFound:
            self._logger.warn("Metrics path does not exist in etcd: {}".format(
                repr(service_type_path)))
            return []
Пример #7
0
    def _get_instance_uuid_paths(self, service_type):
        try:
            service_type_path = EtcdHelper.build_etcd_path([
                self._dynamite_config.ETCD.metrics_base_path,
                service_type
            ])
            uuid_nodes = self.etcdctl.read(service_type_path)

            uuid_paths = []
            for uuid_node in uuid_nodes.children:
                uuid_paths.append(uuid_node.key)
            return uuid_paths

        except etcd.EtcdKeyNotFound:
            self._logger.warn("Metrics path does not exist in etcd: {}".format(repr(service_type_path)))
            return []
Пример #8
0
    def _get_metrics_from_instance(self, uuid, path_to_service_type, metric_information):
        metric_name = metric_information.metric_name

        metrics_path = EtcdHelper.build_etcd_path([path_to_service_type, uuid, metric_name])

        try:
            metric_folder = self.etcdctl.read(metrics_path, recursive=True, sorted=True)
            values = []
            for timestamp_node in metric_folder.children:
                if timestamp_node.value is not None:
                    value = self._read_value_from_etcd_node(timestamp_node, metric_information)
                    values.append(value)
                    self._delete_key_in_etcd(timestamp_node.key)
            if len(values) > 0:
                self._create_and_send_metrics_message(metric_information, uuid, values)
            else:
                self._logger.debug("No metrics found for metric {} in path {}".format(metric_name, metrics_path))
        except etcd.EtcdKeyNotFound:
            self._logger.debug("Could not find etcd key of metric %s in path %s", metric_name, metrics_path)
Пример #9
0
 def _build_metrics_path(self, event):
     return EtcdHelper.build_etcd_path([
         self._metrics_base_path, event.resource.service_type,
         event.resource.instance_uuid, event.resource.metric_name,
         event.get_formatted_time()
     ])
Пример #10
0
 def _build_services_path(self, resource):
     return EtcdHelper.build_etcd_path([
         self._services_base_path, resource.service_type,
         resource.instance_uuid, "service_instance_name"
     ])