Beispiel #1
0
def initiate():
    # Boot first machines if not active:
    stack = openstack()
    backends = stack.backends()

    # Gathering first data
    data = {}
    data['acu'] = hastats.get_backend_cum_requests()['stot']
    data['diff'] = 0
    data['diffpt'] = 0
    data['date'] = datetime.datetime.now()
    data['active'] = len(
        stack.active_backends())  #len(hastats.get_backends_up())
    data['haactive'] = len(hastats.get_backends_up())
    data['needed'] = None
    data['epoch'] = (datetime.datetime.now() - epoch_start).seconds
    metrics.append(data)
    print metrics
    time.sleep(sleeptime)
    last = data
    data = {}
    data['acu'] = hastats.get_backend_cum_requests()['stot']
    data['diff'] = int(
        (float(data['acu']) - float(last['acu'])) / float(sleeptime))
    data['diffpt'] = data['diff'] * sleeptime
    data['date'] = datetime.datetime.now()
    data['needed'] = needed_servers(acu=data['acu'], diff=data['diff'])
    data['active'] = len(
        stack.active_backends())  #len(hastats.get_backends_up())
    data['haactive'] = len(hastats.get_backends_up())
    data['epoch'] = (datetime.datetime.now() - epoch_start).seconds
    metrics.append(data)
    time.sleep(sleeptime)
Beispiel #2
0
def initiate():
    # Boot first machines if not active:
    stack = openstack()
    backends = stack.backends()

    # Gathering first data
    data = {}
    data['acu'] = hastats.get_backend_cum_requests()['stot']
    data['diff'] = 0
    data['diffpt'] = 0
    data['date'] = datetime.datetime.now()
    data['active'] = len(stack.active_backends())#len(hastats.get_backends_up())
    data['haactive'] = len(hastats.get_backends_up())
    data['needed'] = None
    data['epoch'] = (datetime.datetime.now()-epoch_start).seconds
    metrics.append(data)
    print metrics
    time.sleep(sleeptime)
    last = data
    data = {}
    data['acu'] = hastats.get_backend_cum_requests()['stot']
    data['diff'] = int((float(data['acu']) - float(last['acu'])) / float(sleeptime))
    data['diffpt'] = data['diff'] * sleeptime
    data['date'] = datetime.datetime.now()
    data['needed'] = needed_servers(acu=data['acu'], diff=data['diff'])
    data['active'] = len(stack.active_backends())#len(hastats.get_backends_up())
    data['haactive'] = len(hastats.get_backends_up())
    data['epoch'] = (datetime.datetime.now()-epoch_start).seconds
    metrics.append(data)
    time.sleep(sleeptime)
Beispiel #3
0
def main():
    # Starting the first time
    # getting current cum connections
    try:
        if not metrics:
            print("Gathering initial data...")

            # Gathering first data
            initiate()

        while True:
            current = new_metrics(hastats.get_backend_cum_requests()['stot'])
            print metrics[-1]
            print "Needed servers: %s" % str(
                needed_servers(diff=current['diff']))

            # What to do? Scale up/down or are we happy?
            stack = openstack()
            active_backends = stack.active_backends()
            up_backends = hastats.get_backends_up()

            needed = needed_servers(diff=current['diff'])
            if needed > len(active_backends):
                print "Scaling up"
                scale_up(needed - len(active_backends))
            elif needed < len(active_backends):
                print "Scaling down"
                if not scale_down(Needed=needed):
                    print "Lowest number"
            else:
                # Sleeping
                print "Sleeping one more round"

            if update_conf():
                print "HAproxy config reloaded"
                print ha_last_reload

            for line in hastats.get_stat_backends():
                print line['svname'] + ', ' + line['status']

            time.sleep(sleeptime)

    except KeyboardInterrupt:
        write_data()
Beispiel #4
0
def main():
    # Starting the first time
    # getting current cum connections
    try:
        if not metrics:
            print("Gathering initial data...")

            # Gathering first data
            initiate()

        while True:
            current = new_metrics(hastats.get_backend_cum_requests()['stot'])
            print metrics[-1]
            print "Needed servers: %s" % str(needed_servers(diff=current['diff']))

            # What to do? Scale up/down or are we happy?
            stack = openstack()
            active_backends = stack.active_backends()
            up_backends = hastats.get_backends_up()

            needed = needed_servers(diff=current['diff'])
            if needed > len(active_backends):
                print "Scaling up"
                scale_up(needed-len(active_backends))
            elif needed < len(active_backends):
                print "Scaling down"
                if not scale_down(Needed=needed):
                    print "Lowest number"
            else:
                # Sleeping
                print "Sleeping one more round"

            if update_conf():
                print "HAproxy config reloaded"
                print ha_last_reload

            for line in hastats.get_stat_backends():
                print line['svname'] + ', ' + line['status']

            time.sleep(sleeptime)

    except KeyboardInterrupt:
        write_data()