Exemplo n.º 1
0
def f_cpu():
    command = executeCmd("sar -u 3 1 |tail -1", raw=True)#Example ['Average:', 'all', '1.96\x00', '0.00\x00', '0.63\x00', '0.00\x00', '0.00\x00', '97.41\x00']
    command = command.replace(b"\x00", b"").decode(errors="replace").strip(" \n\t")
    state = re.findall(r"all\s+(\w*\.*\w*)\s+(\w*\.*\w*)\s+(\w*\.*\w*)\s+(\w*\.*\w*)\s+(\w*\.*\w*)\s+(\w*\.*\w*)", command)[0]
    sqlib.execDB(
        "INSERT INTO `stat` (users, nice, sys, iowait, steal, idle, times) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', {6});"
        .format(state[0], state[1], state[2], state[3], state[4], state[5], int(time.time())), dbPath)
Exemplo n.º 2
0
def f_disk():
    command = executeCmd("sudo iostat -x 4 2 -Nm", raw=True)
    command = command.replace(b"\x00",
                              b"").decode(errors="replace").strip(" \n\t")
    command = command.split('Device')
    result = command[2].split('\n')
    res_d_st = []
    del result[0]
    for stroka in result:
        delenie = stroka.split()
        if "5000" in delenie[0]:
            res_d_st.append((delenie[0], delenie[1], delenie[2], delenie[3],
                             delenie[4], delenie[15], 0))

    #For Engine-1
    # if len(arg) == 1:
    #     remote_hostname = "ENGINE-1" if hostname == "ENGINE-0" else "ENGINE-0"
    #     rState = aerodisk_ssh.execute(remote_hostname, 'sudo ' + curPath + 'writeDisks.py ssh', timeout=30).split('\n')
    #     for a in rState:
    #         rea = a.split(';')
    #         res_d_st.append((rea[0], rea[3], rea[1], rea[4], rea[2], rea[5], 1))

    times = int(time.time())
    if len(arg) == 1:
        for add in res_d_st:
            sqlib.execDB(
                "INSERT INTO `stat` ( times, name, read_speed, read_iops, write_speed, write_iops, util, remoute) VALUES ({0}, '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', {7});"
                .format(times, add[0], add[3], add[1], add[4], add[2], add[5],
                        add[6]), dbPath)
    else:
        for add in res_d_st:
            print("{0};{1};{2};{3};{4};{5};1".format(add[0], add[3], add[1],
                                                     add[4], add[2], add[5]))
Exemplo n.º 3
0
def f_mem():
    command = executeCmd("sudo sudo free -m").split('\n')
    del command[0]
    result = []
    for pa in command:
        result.append(pa.split())
    sqlib.execDB(
        'INSERT INTO `stat` (_total, _used, _free, _shared, _buffers, _cached, buf_ca_used, buf_ca_free, swap_total, swap_used, swap_free, times) VALUES ({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11});'
        .format(int(result[0][1]), int(result[0][2]), int(result[0][3]),
                int(result[0][4]), int(result[0][5]), int(result[0][6]),
                int(result[1][2]), int(result[1][3]), int(result[2][1]),
                int(result[2][2]), int(result[2][3]),
                int(time.time())), dbPath)
Exemplo n.º 4
0
def f_ether():
    command = executeCmd("sudo sar -n DEV 3 2", raw=True)
    command = command.replace(b"\x00",
                              b"").decode(errors="replace").strip(" \n\t")
    command = command.split('IFACE')
    average = command[3].split('\n')
    del average[0]
    result = []
    for stroka in average:
        delimetr = stroka.split()
        if delimetr[1] != "lo":
            #               name                  read mb/s               read IOPS               write mb/s            write iops      util
            result.append(
                (delimetr[1], convertToMegabytes(delimetr[5]), delimetr[3],
                 convertToMegabytes(delimetr[4]), delimetr[2], delimetr[9]))

    for add in result:
        sqlib.execDB(
            "INSERT INTO `stat` ( times, name, read_speed, read_iops, write_speed, write_iops, util) VALUES ({0}, '{1}', '{2}', '{3}', '{4}', '{5}', '{6}');"
            .format(int(time.time()), add[0], add[1], add[2], add[3], add[4],
                    add[5]), dbPath)
Exemplo n.º 5
0
def create_database(patch):
    con = sqlite3.connect(patch)
    con.close()
    sqlib.execDB("CREATE TABLE 'stat' ( `id`	INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, `users`	TEXT, `nice`	TEXT, `sys`	TEXT, `idle`	TEXT, `iowait`	TEXT, `steal`	TEXT, `times`	INTEGER)", patch)
Exemplo n.º 6
0
        return out
    return out.decode(errors="replace").strip(" \n\t")



def create_database(patch):
    con = sqlite3.connect(patch)
    con.close()
    sqlib.execDB("CREATE TABLE 'stat' ( `id`	INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, `users`	TEXT, `nice`	TEXT, `sys`	TEXT, `idle`	TEXT, `iowait`	TEXT, `steal`	TEXT, `times`	INTEGER)", patch)

def f_cpu():
    command = executeCmd("sar -u 3 1 |tail -1", raw=True)#Example ['Average:', 'all', '1.96\x00', '0.00\x00', '0.63\x00', '0.00\x00', '0.00\x00', '97.41\x00']
    command = command.replace(b"\x00", b"").decode(errors="replace").strip(" \n\t")
    state = re.findall(r"all\s+(\w*\.*\w*)\s+(\w*\.*\w*)\s+(\w*\.*\w*)\s+(\w*\.*\w*)\s+(\w*\.*\w*)\s+(\w*\.*\w*)", command)[0]
    sqlib.execDB(
        "INSERT INTO `stat` (users, nice, sys, iowait, steal, idle, times) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', {6});"
        .format(state[0], state[1], state[2], state[3], state[4], state[5], int(time.time())), dbPath)


if __name__ == "__main__":
    if os.path.exists(dbPath) != True:
        create_database(dbPath)
    startTime = time.time()
    c = 0
    while c <= 19 and time.time() - startTime < 57:
        f_cpu()
        c += 1

    del_time = int(time.time()) - 2592000
    sqlib.execDB("DELETE FROM stat WHERE times < '{0}'".format(del_time), dbPath)
Exemplo n.º 7
0
def create_database(patch):
    con = sqlite3.connect(patch)
    con.close()
    sqlib.execDB(
        "CREATE TABLE `stat` (`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, `times`	INTEGER, `name` TEXT, `read_speed` TEXT, `read_iops` TEXT, `write_speed` TEXT, `write_iops` TEXT, `util` TEXT)",
        patch)
Exemplo n.º 8
0
def create_database(patch):
    con = sqlite3.connect(patch)
    con.close()
    sqlib.execDB(
        "CREATE TABLE `stat` (`id`	INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, `_total`	INTEGER, `_used`	INTEGER, `_free`	INTEGER, `_shared`	INTEGER, `_buffers`	INTEGER, `_cached`	INTEGER, `buf_ca_used`	INTEGER, `buf_ca_free`	INTEGER, `swap_total`	INTEGER, `swap_used`	INTEGER, `swap_free`	INTEGER,`times`	INTEGER)",
        patch)