Exemple #1
0
def get_net(request, hostname, timing, net_id):
    data_time = []
    nic_in = []
    nic_out = []
    nic_name = ""
    range_time = TIME_SECTOR[int(timing)]
    net = GetSysData(hostname, "net", range_time)
    for doc in net.get_data():
        unix_time = doc['timestamp']
        times = time.localtime(unix_time)
        dt = time.strftime("%m%d-%H:%M", times)
        data_time.append(dt)
        in_ = doc['net'][int(net_id)]['traffic_in']
        out_ = doc['net'][int(net_id)]['traffic_out']
        nic_in.append(in_)
        nic_out.append(out_)
        if not nic_name:
            nic_name = doc['net'][int(net_id)]['nic_name']
    data = {
        "data_time": data_time,
        "nic_name": nic_name,
        "traffic_in": nic_in,
        "traffic_out": nic_out
    }
    return HttpResponse(json.dumps(data))
Exemple #2
0
def get_mem(request, machine_id, timing):
    data_time = []
    mem_percent = []
    pro_percent = []
    pro_name = ''
    range_time = TIME_SECTOR[int(timing)]
    mem_data = GetSysData(machine_id, "mem", range_time)
    for doc in mem_data.get_data():
        unix_time = doc['timestamp']
        times = time.localtime(unix_time)
        dt = time.strftime("%m-%d %H:%M", times)
        data_time.append(dt)
        m_percent = doc['mem']['percent']
        mem_percent.append(m_percent)

        p_percent = doc['mem']["p_mem"][1]
        pro_name = doc['mem']["p_mem"][0]
        pro_percent.append(p_percent)
    data = {
        "data_time": data_time,
        "mem_percent": mem_percent,
        "pro_percent": pro_percent,
        'pro_name': pro_name
    }
    return HttpResponse(json.dumps(data))
Exemple #3
0
def get_net(request, machine_id, timing):
    data_time = []
    nic_in = []
    nic_out = []
    nic_name = ""
    range_time = TIME_SECTOR[int(timing)]
    net = GetSysData(machine_id, "net", range_time)
    for doc in net.get_data():
        unix_time = doc['timestamp']
        times = time.localtime(unix_time)
        dt = time.strftime("%m-%d %H:%M", times)
        data_time.append(dt)
        in_ = 0
        out_ = 0
        for i in range(len(doc['net'])):
            in_ += doc['net'][i]['traffic_in']
            out_ += doc['net'][i]['traffic_out']
        nic_in.append(in_)
        nic_out.append(out_)

    data = {
        "data_time": data_time,
        "nic_name": nic_name,
        "traffic_in": nic_in,
        "traffic_out": nic_out
    }
    return HttpResponse(json.dumps(data))
Exemple #4
0
def get_disk(request, machine_id, timing):
    data_time = []
    disk_name_list = []
    disk_percent_list = []
    range_time = TIME_SECTOR[int(timing)]
    disk = GetSysData(machine_id, "disk", range_time)
    for doc in disk.get_data():
        unix_time = doc['timestamp']
        times = time.localtime(unix_time)
        dt = time.strftime("%m-%d %H:%M", times)
        data_time.append(dt)

        disk_name_list = doc['disk']['id']
        if not disk_percent_list:
            for i in range(len(doc['disk']['percent'])):
                disk_percent_list.append([])
        for i in range(len(doc['disk']['percent'])):
            disk_percent_list[i].append(doc['disk']['percent'][i])

    data = {
        "data_time": data_time,
        "disk_name_list": disk_name_list,
        "disk_percent_list": disk_percent_list
    }
    return HttpResponse(json.dumps(data))
Exemple #5
0
def node_status(request, ids):
    data = 2
    host = Host.objects.get(id=ids)
    cpu_data = GetSysData(host.hostname, "cpu", 1800)
    for doc in cpu_data.get_data():
        if doc:
            data = 1
            break
    return HttpResponse(data)
Exemple #6
0
def get_mem(request, hostname, timing):
    data_time = []
    mem_percent = []
    range_time = TIME_SECTOR[int(timing)]
    mem_data = GetSysData(hostname, "mem", range_time)
    for doc in mem_data.get_data():
        unix_time = doc['timestamp']
        times = time.localtime(unix_time)
        dt = time.strftime("%m%d-%H:%M", times)
        data_time.append(dt)
        m_percent = doc['mem']['percent']
        mem_percent.append(m_percent)
    data = {"data_time": data_time, "mem_percent": mem_percent}
    return HttpResponse(json.dumps(data))
Exemple #7
0
def get_cpu(request, machine_id, timing):
    data_time = []
    cpu_percent = []
    range_time = TIME_SECTOR[int(timing)]
    cpu_data = GetSysData(machine_id, "cpu", range_time)
    for doc in cpu_data.get_data():
        unix_time = doc['timestamp']
        times = time.localtime(unix_time)
        dt = time.strftime("%m-%d %H:%M", times)
        data_time.append(dt)
        c_percent = doc['cpu']['percent']
        cpu_percent.append(c_percent)
    data = {"data_time": data_time, "cpu_percent": cpu_percent}
    return HttpResponse(json.dumps(data))
Exemple #8
0
def drop_sys_info():
    """
    :drop sys_info db
    """
    db = GetSysData.connect_db()
    db.drop_database(get_dir("mongodb_collection"))
    return HttpResponse("ok")
def get_disk(request, hostname, timing, partition):
    data_time = []
    disk_percent = []
    disk_name = ""
    range_time = TIME_SECTOR[int(timing)]
    disk = GetSysData(hostname, "disk", range_time)
    for doc in disk.get_data():
        unix_time = doc['timestamp']
        times = time.localtime(unix_time)
        dt = time.strftime("%m%d-%H:%M", times)
        data_time.append(dt)
        d_percent = doc['disk'][int(partition)]['percent']
        disk_percent.append(d_percent)
        if not disk_name:
            disk_name = doc['disk'][int(partition)]['mountpoint']
    data = {"data_time": data_time, "disk_name": disk_name, "disk_percent": disk_percent}
    return HttpResponse(json.dumps(data))
Exemple #10
0
def del_monitor_data(request, timing):
    timing = int(timing)
    if timing == 4:
        db = GetSysData.connect_db()
        db.drop_database("sys_info")
    else:
        host_list = Host.objects.all()
        client = GetSysData.connect_db()
        db = client.sys_info
        for host in host_list:
            try:
                collection = db[host]
            except:
                continue
            now_time = int(time.time())
            del_time = now_time-TIME_SECTOR[int(timing)]
            collection.remove({'timestamp': {'$lte': del_time}}, {"timestamp": 1})
    return HttpResponse("ok")
def syshost_info(request, hostname, timing):
    # 传递磁盘号给前端JS,用以迭代分区图表
    disk = GetSysData(hostname, "disk", 3600, 1)
    disk_data = disk.get_data()
    partitions_len = []
    for d in disk_data:
        p = len(d["disk"])
        for x in range(p):
            partitions_len.append(x)
    # 传递网卡号给前端,用以迭代分区图表
    net = GetSysData(hostname, "net", 3600, 1)
    nic_data = net.get_data()
    nic_len = []
    for n in nic_data:
        p = len(n["net"])
        for x in range(p):
            nic_len.append(x)
    return render(request, "monitor/host_info.html", locals())
Exemple #12
0
def host_info(request, machine_id, timing):

    # 传递磁盘号给前端JS,用以迭代分区图表
    disk = GetSysData(machine_id, "disk", 3600, 1)
    disk_data = disk.get_data()
    partitions_len = []
    for d in disk_data:
        p = len(d['disk']['id'])
        for x in range(p):
            partitions_len.append(x)

    # 传递网卡号给前端,用以迭代分区图表
    net = GetSysData(machine_id, "net", 3600, 1)
    nic_data = net.get_data()
    nic_len = []
    for n in nic_data:
        p = len(n["net"])
        for x in range(p):
            nic_len.append(x)

    return render(request, "monitor/host_info_{}.html".format(timing),
                  locals())