Beispiel #1
0
def get_disk_usage():
    device_is_connected = LocalMachine.run_command_safe("echo /dev/sd*")
    if "/dev/sd*" not in device_is_connected:
        data_tmp = LocalMachine.run_command_safe("df -h / /dev/sd* | grep -v devtmpfs")
    else:
        data_tmp = LocalMachine.run_command_safe("df -h /")
    data_list = data_tmp.split("\n")
    data = ""
    for index, line in enumerate(data_list):
        data += " " + line + "\n"
    return data
Beispiel #2
0
def get_logged_in_users():
    data_tmp = LocalMachine.run_command_safe("ps -ef | grep [s]shd | grep -v ^root")
    data_list = data_tmp.split("\n")
    data = ""
    for index, line in enumerate(data_list):
        data += " " + line + "\n"
    return data
Beispiel #3
0
def get_internal_ip():
    data = LocalMachine.run_command_safe("hostname -I")
    data_list = data.split(" ")
    ip_printout = ""
    for index, ip in enumerate(data_list):
        ip_printout += "IP[{}]: {} ".format(index, ip)
    return ip_printout
Beispiel #4
0
def get_mem_usage():
    mem_total = LocalMachine.run_command_safe(
        "sudo cat /proc/meminfo | grep 'MemTotal' | tr -dc '0-9'")
    mem_available = LocalMachine.run_command_safe(
        "sudo cat /proc/meminfo | grep 'MemAvailable' | tr -dc '0-9'")
    mem_free = LocalMachine.run_command_safe(
        "sudo cat /proc/meminfo | grep 'MemFree' | tr -dc '0-9'")

    available_percent = (float(int(mem_total) - int(mem_available)) /
                         float(mem_total)) * 100
    available_percent = '%.1f' % available_percent

    free_percent = (float(int(mem_total) - int(mem_free)) /
                    float(mem_total)) * 100
    free_percent = '%.1f' % free_percent
    return float(available_percent), float(
        free_percent), mem_total, mem_available, mem_free
Beispiel #5
0
def get_mac_addresses():
    output = ""
    devices = LocalMachine.run_command_safe("ls -1 /sys/class/net")
    devices_list = devices.split("\n")
    for index, device in enumerate(devices_list):
        if device != "lo":
            cmd = "ifconfig " + device + " | grep 'HWaddr'"
            mac_line = LocalMachine.run_command_safe(cmd, check_exitcode=False)
            substring_index = -17
            if mac_line == "":
                cmd = "ifconfig " + device + " | grep 'ether'"
                mac_line = LocalMachine.run_command_safe(cmd, check_exitcode=False)
                substring_index = 13
            if str(mac_line) != "" and mac_line is not None:
                output += " \t" + device + "\t\t" + str(mac_line)[substring_index:]
                if index < len(devices_list) - 1:
                    output += "\n"
    return output
Beispiel #6
0
def get_top_processes(char_width, topx=3):
    output = ""
    cmd = "ps aux | head -n 1; ps aux --sort -rss | sort -nrk 3,3 | head -n " + str(
        topx)
    data = LocalMachine.run_command_safe(cmd)
    data_list = data.split("\n")
    for line in data_list:
        output += " " + line[0:char_width] + "\n"
    return output
Beispiel #7
0
def ip_default_route():
    # get ip route command output and hughlight device
    formatted_ip_route = ""
    color = ""
    highlighted_word = ""

    ip_route = LocalMachine.run_command_safe("ip route")
    ip_route_lines = ip_route.split("\n")
    for line in ip_route_lines:
        formatted_ip_route += "\t\t\t"
        for index, word in enumerate(line.split(" ")):
            if word == "dev":
                highlighted_word = line.split(" ")[index + 1]
                color = Colors.DARK_GRAY
            if highlighted_word != ""  and highlighted_word == word:
                color = Colors.DARK_GRAY
                highlighted_word = ""
            else:
                color = ""
            formatted_ip_route += "{}{}{} ".format(color, word, Colors.NC)
        formatted_ip_route += "\n"
    return formatted_ip_route
Beispiel #8
0
def get_dedicated_gpu_mem():
    # gpu memory size
    gpu_memory = LocalMachine.run_command_safe("vcgencmd get_mem gpu")
    gpu_memory = gpu_memory[4:-1]
    return gpu_memory
Beispiel #9
0
def get_gpu_temp():
    data = LocalMachine.run_command_safe("cat /sys/class/thermal/thermal_zone0/temp")
    data = float(data) / 1000
    data = '%.1f' % data
    return float(data)
Beispiel #10
0
def get_cpu_temp():
    data = LocalMachine.run_command_safe("/opt/vc/bin/vcgencmd measure_temp")
    data = data[5:-2]
    return float(data)
Beispiel #11
0
def get_date_time():
    data = LocalMachine.run_command_safe("date")
    return data
Beispiel #12
0
def get_username():
    data = LocalMachine.run_command_safe("echo $USER")
    return data
Beispiel #13
0
def get_device_version():
    # sap memory size
    dev_version = LocalMachine.run_command_safe("cat /sys/firmware/devicetree/base/model")
    return dev_version.rstrip()
Beispiel #14
0
def get_swap_memory_size():
    # sap memory size
    swap_size = LocalMachine.run_command_safe("cat /etc/dphys-swapfile | grep CONF_SWAPSIZE")
    swap_size = swap_size[14:]
    return swap_size
Beispiel #15
0
def ac_user_statistic():
    user_stat = LocalMachine.run_command_safe("ac -p").rstrip()
    return Colors.LIGHT_BLUE + " USER STATISTIC\n" + Colors.NC + str(user_stat)
Beispiel #16
0
def get_external_ip():
    data = LocalMachine.run_command_safe("curl http://ipecho.net/plain 2>/dev/null")
    return data
Beispiel #17
0
def get_cpu_freq():
    data = LocalMachine.run_command_safe("cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq")
    return data
Beispiel #18
0
def get_pi_version():
    data = LocalMachine.run_command_safe("sudo uname -a")
    return data
Beispiel #19
0
    except KeyboardInterrupt as e:
        is_interrupted = True
        sys.exit(0)
    finally:
        return output


# MAIN SCOPE
logo()
while True:
    output = main(_all, _temp, _cpu, _memory, _disk, _loggedin, _general,
                  _services)

    if output != "":
        if _loop:
            print(LocalMachine.run_command_safe("clear"))
        print(output)
    else:
        _all = True
        output = main(_all, _temp, _cpu, _memory, _disk, _loggedin, _general,
                      _services)
        if _loop:
            print(LocalMachine.run_command_safe("clear"))
        print(output)

    if not _loop or is_interrupted:
        print("Goodbye :)")
        break
    else:
        try:
            time.sleep(0.1)
Beispiel #20
0
def get_cpu_usage():
    data = LocalMachine.run_command_safe(
        "/home/$USER/rpitools/tools/proc_stat.sh")
    data = data[6:-6]
    return int(data)