示例#1
0
def render(draw, width, height):
    percentages = psutil.cpu_percent(interval=None, percpu=True)

    margin = 3
    top_margin = 3
    bottom_margin = 3

    title_text(draw, top_margin, width, "Net: wlan0")
    address = psutil.net_if_addrs()["wlan0"][0].address
    counters = psutil.net_io_counters(pernic=True)["wlan0"]

    draw.text((margin, 20), text=address, font=tiny_font, fill="white")
    draw.text((margin, 30), text="Rx:", font=tiny_font, fill="white")
    draw.text((margin, 40), text="Tx:", font=tiny_font, fill="white")
    right_text(draw, 30, width, margin, text=bytes2human(counters.bytes_recv))
    right_text(draw, 40, width, margin, text=bytes2human(counters.bytes_sent))

    x = (width - draw.textsize("CPU Load")[0]) / 2
    draw.text((x, 55), text="CPU Load", fill="yellow")
    bar_height = (height - 15 - top_margin - bottom_margin) / 2
    width_cpu = width / len(percentages)
    bar_width = 0.5 * width_cpu
    bar_margin = (width_cpu - bar_width) / 2

    x = bar_margin

    for cpu in percentages:
        cpu_height = bar_height * (cpu / 100.0)
        y2 = height - bottom_margin
        vertical_bar(draw, x, y2 - bar_height - 1, x + bar_width, y2,
                     y2 - cpu_height)

        x += width_cpu
示例#2
0
def render(draw, width, height):
    boot_time = datetime.fromtimestamp(psutil.boot_time())
    elapsed = datetime.now() - boot_time
    margin = 3
    title_text(draw, margin, width, "Uptime")
    right_text(draw,
               20,
               width,
               margin,
               text="{0} s".format(int(elapsed.total_seconds())))
示例#3
0
    def render(draw, width, height):
        margin = 3
        title_text(draw, margin, width, text="Net:{0}".format(interface))
        try:
            address = psutil.net_if_addrs()[interface][0].address
            counters = psutil.net_io_counters(pernic=True)[interface]

            draw.text((margin, 20), text=address, font=tiny_font, fill="white")
            draw.text((margin, 35), text="Rx:", font=tiny_font, fill="white")
            draw.text((margin, 45), text="Tx:", font=tiny_font, fill="white")

            right_text(draw, 35, width, margin, text=bytes2human(counters.bytes_recv))
            right_text(draw, 45, width, margin, text=bytes2human(counters.bytes_sent))
        except:
            draw.text((margin, 20), text="n/a", font=tiny_font, fill="white")
示例#4
0
def render(draw, width, height):
    boot_time = datetime.fromtimestamp(psutil.boot_time())
    elapsed = datetime.now() - boot_time
    margin = 3
    title_text(draw, margin, width, "Uptime")
    right_text(draw, 20, width, margin, text="{0} s".format(int(elapsed.total_seconds())))

    if int(elapsed.total_seconds()) > 172800:
        days = str(int(elapsed.total_seconds())/86400) + " days"
    elif int(elapsed.total_seconds()) > 86400:
        days = "1 day"
    else:
        days = None

    if days:
        right_text(draw, 35, width, margin, days)
def render_network_cpu(draw, width, height):
    global input_data
    if not input_data:
        return

    logging.info('Rendering Network and CPU...')
    margin = 3
    top_margin = 3
    bottom_margin = 3

    # Network
    title_text(draw, top_margin, width,
               "Net: {}".format(input_data["network"]["interface_name"]))
    # interface_address = input_data["network"]["interface_address"]
    ip_address = input_data["network"]["ip_address"]
    # draw.text((margin, 15), text=interface_address, font=tiny_font, fill="white")
    draw.text((margin, 15), text=ip_address, font=tiny_font, fill="white")
    draw.text((margin, 25), text="Rx:", font=tiny_font, fill="white")
    draw.text((margin, 35), text="Tx:", font=tiny_font, fill="white")
    right_text(draw,
               25,
               width,
               margin,
               text=bytes2human(input_data["network"]["bytes_recv"]))
    right_text(draw,
               35,
               width,
               margin,
               text=bytes2human(input_data["network"]["bytes_sent"]))

    # CPU
    x = (width - draw.textsize("CPU Load")[0]) / 2
    draw.text((x, 45), text="CPU Load", fill="yellow")
    bar_height = (height - 15 - top_margin - bottom_margin) / 1.95
    width_cpu = width / len(input_data["cpu"]["cpu_percent_each"])
    bar_width = 0.5 * width_cpu
    bar_margin = (width_cpu - bar_width) / 1.95
    cpu_percent_string = "{}%".format(str(input_data["cpu"]["cpu_percent"]))
    x = (width - draw.textsize(cpu_percent_string)[0]) / 1.7
    draw.text((x, 57), text=cpu_percent_string, font=tiny_font, fill="white")
    x = bar_margin
    for cpu in input_data["cpu"]["cpu_percent_each"]:
        cpu_height = bar_height * (cpu / 100.0)
        y2 = height - bottom_margin
        vertical_bar(draw, x, y2 - bar_height - 1, x + bar_width, y2,
                     y2 - cpu_height)
        x += width_cpu
示例#6
0
def render(draw, width, height):
    df = psutil.disk_usage("/")

    margin = 3

    title_text(draw, margin, width, text="Disk")
    draw.text((margin, 20), text="Used:", font=tiny_font, fill="white")
    draw.text((margin, 35), text="Free:", font=tiny_font, fill="white")
    draw.text((margin, 45), text="Total:", font=tiny_font, fill="white")

    right_text(draw, 20, width, margin, text="{0:0.1f}%".format(df.percent))
    right_text(draw, 35, width, margin, text=bytes2human(df.free, "{0:0.0f}"))
    right_text(draw, 45, width, margin, text=bytes2human(df.total, "{0:0.0f}"))
示例#7
0
def render(draw, width, height):
    mem = psutil.virtual_memory()
    swap = psutil.swap_memory()
    mem_used_pct = (mem.total - mem.available) * 100.0 / mem.total

    margin = 3

    title_text(draw, margin, width, text="Memory")
    draw.text((margin, 20), text="Used:", font=tiny_font, fill="white")
    draw.text((margin, 35), text="Phys:", font=tiny_font, fill="white")
    draw.text((margin, 45), text="Swap:", font=tiny_font, fill="white")

    right_text(draw, 20, width, margin, text="{0:0.1f}%".format(mem_used_pct))
    right_text(draw, 35, width, margin, text=bytes2human(mem.used))
    right_text(draw, 45, width, margin, text=bytes2human(swap.used))
示例#8
0
def render(draw, width, height):
    tFile = open('/sys/class/thermal/thermal_zone0/temp')
    tempC = float(tFile.read()) / 1000
    tFile.close()

    fFile = open('/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq')
    freqC = long(fFile.read()) / 1000
    fFile.close()

    margin = 3
    title_text(draw, margin, width, "CPU status")
    draw.text((margin, 20), text="Temp:", font=tiny_font, fill="white")
    draw.text((margin, 30), text="Freq:", font=tiny_font, fill="white")
    draw.text((margin, 40), text="Fan:", font=tiny_font, fill="white")
    draw.text((margin, 50), text="RPM:", font=tiny_font, fill="white")

    right_text(draw, 20, width, margin, text="{0:0.1f}C".format(tempC))
    right_text(draw, 30, width, margin, text="{0}k".format(int(freqC)))
    fan = fanOut()
    fanDC, fanRPM = fan.split(" ")
    if "Err" not in fanDC:
        fanDC += "%"
    right_text(draw, 40, width, margin, fanDC)
    right_text(draw, 50, width, margin, fanRPM)
def render_disk_memory_battery(draw, width, height):
    global input_data
    if not input_data:
        return

    logging.info('Rendering Disk and Memory...')
    margin = 3

    # Disk
    title_text(draw, margin, width, text="Disk")
    draw.text((margin, 15), text="Used:", font=tiny_font, fill="white")
    draw.text((margin, 25), text="Free:", font=tiny_font, fill="white")
    draw.text((margin, 35), text="Total:", font=tiny_font, fill="white")
    right_text(draw,
               15,
               width,
               margin,
               text="{0:0.1f}%".format(input_data["disk"]["used_pct"]))
    right_text(draw,
               25,
               width,
               margin,
               text=bytes2human(input_data["disk"]["free"], "{0:0.0f}"))
    right_text(draw,
               35,
               width,
               margin,
               text=bytes2human(input_data["disk"]["total"], "{0:0.0f}"))

    # Memory
    x = (width - draw.textsize("Memory")[0]) / 2
    draw.text((x, 45), text="Memory", fill="yellow")
    draw.text((margin, 57), text="Used:", font=tiny_font, fill="white")
    draw.text((margin, 67), text="Phys:", font=tiny_font, fill="white")
    draw.text((margin, 77), text="Swap:", font=tiny_font, fill="white")
    right_text(draw,
               57,
               width,
               margin,
               text="{0:0.1f}%".format(input_data["memory"]["mem_used_pct"]))
    right_text(draw,
               67,
               width,
               margin,
               text=bytes2human(input_data["memory"]["mem_used"]))
    right_text(draw,
               77,
               width,
               margin,
               text=bytes2human(input_data["memory"]["swap_used"]))

    # Battery
    draw.text((x, 90), text="Battery", fill="yellow")
    battery_pct = input_data["battery"]["battery_pct"]
    draw.text((margin, 105),
              text="{} %".format(battery_pct),
              font=tiny_font,
              fill="white")
示例#10
0
def render(draw, width, height):
    df = psutil.disk_usage("/")

    margin = 3

    title_text(draw, margin, width, text="Disk")
    draw.text((margin, 20), text="Used:", font=tiny_font, fill="white")
    draw.text((margin, 30), text="Free:", font=tiny_font, fill="white")
    draw.text((margin, 40), text="Total:", font=tiny_font, fill="white")

    right_text(draw, 20, width, margin, text="{0:0.1f}%".format(df.percent))
    right_text(draw, 30, width, margin, text=bytes2human(df.free, "{0:0.0f}"))
    right_text(draw, 40, width, margin, text=bytes2human(df.total, "{0:0.0f}"))

    mem = psutil.virtual_memory()
    swap = psutil.swap_memory()
    mem_used_pct = (mem.total - mem.available) * 100.0 / mem.total

    x = (width - draw.textsize("Memory")[0]) / 2
    draw.text((x, 55), text="Memory", fill="yellow")
    draw.text((margin, 75), text="Used:", font=tiny_font, fill="white")
    draw.text((margin, 85), text="Phys:", font=tiny_font, fill="white")
    draw.text((margin, 95), text="Swap:", font=tiny_font, fill="white")

    right_text(draw, 75, width, margin, text="{0:0.1f}%".format(mem_used_pct))
    right_text(draw, 85, width, margin, text=bytes2human(mem.used))
    right_text(draw, 95, width, margin, text=bytes2human(swap.used))