Esempio n. 1
0
def memcached_reset_stats(memcached_id) :
    _memcached = db_session.query(Memcacheds).filter_by(id = memcached_id).first()
    addr =  _memcached.ip + ':' + str(_memcached.port)
    print addr

    client = Client([addr])
    client.reset_stats()

    return redirect(url_for(".memcached_detail", memcached_id = memcached_id))
Esempio n. 2
0
def groups_index():
    from sqlalchemy import func
    groups = db_session.query(Groups, func.sum(Memcacheds.memory).label('group_total_memory'),func.count(Memcacheds.ip).label('memcached_count')) \
        .outerjoin(Memcacheds, Memcacheds.group_id == Groups.id) \
        .group_by(Groups.id).all()
    stats_hit = {}
    stats_useage = {}
    for group in groups :
        group_get = 0
        group_hit = 0
        group_useage = 0
        group_free = 0
        group_total = 0 
        memcacheds = db_session.query(Memcacheds).filter_by(group_id = group.Groups.id).all()
        for memcached in memcacheds :
            try :
                addr = memcached.ip + ":" + str(memcached.port)
                client = Client([addr])
                stats = client.get_stats()[0][1]
                stats['cmd_get'] = int(stats['cmd_get'])
                stats['get_hits'] = int(stats['get_hits'])
                stats['bytes'] = float(stats['bytes'])
                stats['limit_maxbytes'] = float(stats['limit_maxbytes'])
                stats['free'] = float(stats['limit_maxbytes'] - stats['bytes'])
            except Exception, e :
                continue
            group_get += int(stats['cmd_get'])
            group_hit += float(stats['get_hits'])
            group_useage += round((stats['bytes'] / 1024 / 1024 / 1024),2)
            group_free += round((stats['free'] / 1024 / 1024 / 1024),2)
            group_total += round((stats['limit_maxbytes'] / 1024 / 1024 / 1024),2)
        if (group_total != 0) :
            group_use_per = round((group_useage / group_total * 100),2)
            group_free_per = round((group_free / group_total * 100),2)
        else :
            group_use_per = "/"
            group_free_per = "/"
        stats_useage[group.Groups.id] = {"useage": group_useage, "free": group_free, "use_per": group_use_per, "free_per": group_free_per}
        if (group_get != 0) :
            stats_hit[group.Groups.id] = {"hit": round(((group_hit / group_get) * 100),2)}
        else :
            stats_hit[group.Groups.id] = {"hit": "/"}
Esempio n. 3
0
        hits_data['get_num'] = str(hits_history.get)
        #hits_data += "{date:'" + str(time.strftime('%H.%M',time.localtime(_hits_history.time))) + "',value:" + str(_hits_history.num) + "},"
        result.append(hits_data.copy())
    return json.dumps(result)

@mod.route('/memcached-<memcached_id>')
def memcached_detail(memcached_id) :
    try :
        memcached_id = int(memcached_id)
    except Exception, e :
        return 'invalid memcached id'

    _memcached = db_session.query(Memcacheds).filter_by(id = memcached_id).first()
    addr =  _memcached.ip + ':' + str(_memcached.port)

    client = Client([addr])
    temp = client.get_stats('slabs')
    if temp == None  or len(temp) == 0:
        return render_template("mc/memcached_err.html", 
                addr = addr,
                memcached = _memcached)
    slabs = temp[0]
    _slabs = client.get_slabs()[0][1]

    slabs_stats = []
    from pprint import pprint
    for slab_id in slabs :
        try :
            int(slab_id)
        except Exception, e :
            continue
Esempio n. 4
0
from cache.cache_server import Client
import json
import os
import time


memcacheds = db_session.query(Memcacheds).order_by(Memcacheds.group_id).order_by(Memcacheds.id).all()

logs_dir = "/var/www/memcache_cloud/logs/"

for memcached in memcacheds :
    ip = memcached.ip
    port = memcached.port
    addr = str(ip) + ":" + str(port)
    try :
        client = Client([addr])
        stats = client.get_stats()[0][1]
        current_get = stats['cmd_get']
        current_hit = stats['get_hits']
        mid = memcached.id
        log_file = logs_dir + str(memcached.id) + "_data"
        if os.path.isfile(log_file) :
            filehandler = open(log_file,'r')
            old_data = filehandler.readline().rstrip()
            old_data_arr = old_data.split(' ')
            if len(old_data_arr) == 2 :
                old_get = old_data_arr[0]
                old_hit = old_data_arr[1]
            else :
                old_get = 0
                old_hit = 0