Example #1
0
 def test_to_seconds(self):
     """Tests time interval to seconds conversion."""
     self.assertEquals(0, utils.to_seconds('0s'))
     self.assertEquals(3, utils.to_seconds('3s'))
     self.assertEquals(180, utils.to_seconds('3m'))
     self.assertEquals(7200, utils.to_seconds('2h'))
     self.assertEquals(259200, utils.to_seconds('3d'))
Example #2
0
def _get_data_retention(data):
    """Returns data retention timeout in seconds."""
    data_retention_timeout = data.get('data_retention_timeout')
    if data_retention_timeout is not None:
        return utils.to_seconds(data_retention_timeout)
    else:
        return None
Example #3
0
    def reaper(once, interval, threshold, proto, pattern, endpoint, command):
        """Removes unhealthy instances of the app.

        The health check script reads from STDIN and prints to STDOUT.

        The input it list of instance host:port, similar to discovery.

        Output - list of instances that did not pass health check.

        For example, specifying awk '{print $1}' as COMMAND will remove all
        instances.
        """
        command = list(command)

        failed = collections.Counter()
        while True:
            failed.update(_health_check(pattern, proto, endpoint, command))
            for instance, count in failed.items():
                _LOGGER.info('Failed: %s, count: %s', instance, count)

            reaped = _reap([
                instance for instance, count in failed.items()
                if count > threshold
            ])

            for instance in reaped:
                del failed[instance]

            if once:
                break

            time.sleep(utils.to_seconds(interval))
Example #4
0
def _cleanup(outdir, age):
    """Cleanup old report files."""
    _LOGGER.info('Running cleanup.')
    age_sec = utils.to_seconds(age)

    now = time.time()
    for filename in os.listdir(outdir):
        fullpath = os.path.join(outdir, filename)
        created_at = os.stat(fullpath).st_ctime
        if created_at < now - age_sec:
            _LOGGER.info('Removing old file: %s', fullpath)
            fs.rm_safe(fullpath)
    def controller(monitor, once, interval, name):
        """Control app monitors across cells"""
        monitors = list(monitor)

        while True:

            intended_total = 0
            actual_total = 0
            intended = 0

            for cellname, count in monitors:
                if cellname == context.GLOBAL.cell:
                    intended = count
                else:
                    actual = _count(cellname, name)

                    _LOGGER.info('state for cell %s, actual: %s, intended: %s',
                                 cellname, actual, count)

                    intended_total += count
                    actual_total += actual

            missing = intended_total - actual_total

            # If there are missing instances, start them locally. If there are
            # extra instances (missing < 0) just keep the indended state for
            # the cell.
            my_count = intended + max(0, missing)
            _LOGGER.info('intended: %s, actual: %s, missing: %s, my count: %s',
                         intended_total, actual_total, missing, my_count)

            _configure_monitor(name, my_count)

            if once:
                break

            time.sleep(utils.to_seconds(interval))
Example #6
0
def _get_lease(data):
    """Returns lease attribute converted to seconds."""
    return utils.to_seconds(data.get('lease', '0s'))