Exemplo n.º 1
0
    def __update_read_on_on_need(self, metric):
        if not metric.read_on:
            delta = self.__read_on_ttl_sec + 1
        else:
            read_on_timestamp = ttls.str_to_timestamp(metric.read_on)
            delta = int(time.time()) - int(read_on_timestamp)

        if delta >= self.__read_on_ttl_sec:
            # TODO: execute asynchronously
            self.__update_read_on(metric)
Exemplo n.º 2
0
    def touch_metric(self, metric):
        """See the real Accessor for a description."""
        super(_ElasticSearchAccessor, self).touch_metric(metric)
        metric_name = bg_accessor.sanitize_metric_name(metric.name)
        document = self.__get_document(metric_name)
        if not document.updated_on:
            delta = self.__updated_on_ttl_sec + 1
        else:
            updated_on_timestamp = ttls.str_to_timestamp(document.updated_on)
            delta = int(time.time()) - int(updated_on_timestamp)

        if delta >= self.__updated_on_ttl_sec:
            self.__touch_document(document)
Exemplo n.º 3
0
    def __update_read_on_on_need(self, metric):
        # TODO: remove the sampling rate once graphite.py stops using a cache
        # (that doesn't get updated when we updated read_on). Instead we
        # should collect the latest read_on when we list metrics.
        rate = int(1 / self.__read_on_sampling_rate)

        skip = self.__read_on_counter % rate > 0
        self.__read_on_counter += 1

        if skip:
            return

        if not metric.read_on:
            delta = self.__read_on_ttl_sec + 1
        else:
            read_on_timestamp = ttls.str_to_timestamp(metric.read_on)
            delta = int(time.time()) - int(read_on_timestamp)

        if delta >= self.__read_on_ttl_sec:
            self._executor.submit(self.__update_read_on, metric)
            # Make sure the caller also see the change without refreshing
            # the metric.
            metric.read_on = datetime.datetime.now()
Exemplo n.º 4
0
    def __update_read_on_on_need(self, metric):
        # TODO: remove the sampling rate once graphite.py stops using a cache
        # (that doesn't get updated when we updated read_on). Instead we
        # should collect the latest read_on when we list metrics.
        rate = int(1 / self.__read_on_sampling_rate)

        skip = self.__read_on_counter % rate > 0
        self.__read_on_counter += 1

        if skip:
            return

        if not metric.read_on:
            delta = self.__read_on_ttl_sec + 1
        else:
            read_on_timestamp = ttls.str_to_timestamp(metric.read_on)
            delta = int(time.time()) - int(read_on_timestamp)

        if delta >= self.__read_on_ttl_sec:
            self._executor.submit(self.__update_read_on, metric)
            # Make sure the caller also see the change without refreshing
            # the metric.
            metric.read_on = datetime.datetime.now()