Exemplo n.º 1
0
def render(draw, width, height):
    boot_time = datetime.fromtimestamp(psutil.boot_time())
    uptime = naturaldelta(datetime.now() - boot_time)
    draw.text((0, 0), 'Uptime', fill='white', font=default)
    right_text(draw, width, 0, text=uptime, font=default)
    draw.text((0, 10), 'Booted', fill='white', font=default)
    right_text(draw, width, 10, text=boot_time.strftime("%Y/%m/%d %H:%M"), font=default)
Exemplo n.º 2
0
def render(draw, width, height):
    usage = psutil.virtual_memory()
    draw.text((0, 0), 'Memory', fill='white', font=default)
    right_text(draw,
               width,
               0,
               text=f'{naturalsize(usage.used, gnu=True)}B / {usage.percent}%',
               font=default)
Exemplo n.º 3
0
    def render(draw, width, height):
        snapshot = list(datalogger.entries)
        y_offset = 0
        height = 12

        min_temp, max_temp, _ = get_temperature_scale(snapshot, temp_spec)

        for label, reading in temp_spec.items():
            latest_temp = snapshot[-1]['value'].get(reading)
            latest_temp = 'n/a' if latest_temp is None else f'{latest_temp:.0f}°C'

            draw.text((0, y_offset + 1), label, fill='white', font=default)
            right_text(draw,
                       width / 2 + 8,
                       y_offset + 1,
                       text=latest_temp,
                       font=default)

            for index, entry in enumerate(reversed(snapshot)):
                x_offset = width - index - 2
                y_value = int(
                    (height - 2) * entry['value'].get(reading, 0) / max_temp)
                draw.line([
                    x_offset, y_offset + height - 2, x_offset,
                    y_offset + height - y_value
                ],
                          fill='grey',
                          width=1)

            draw.rectangle([
                width - datalogger.max_entries - 2, y_offset, width - 2,
                y_offset + height - 2
            ],
                           outline='white',
                           width=1)
            y_offset += height

        draw.text((0, y_offset + 1), 'Fans', fill='white', font=default)
        for index, (label, reading) in enumerate(fan_spec.items()):
            latest_speed = int(snapshot[-1]['value'].get(reading, 0))
            right_text(draw,
                       56 + (index * 24),
                       y_offset + 1,
                       text=f'{latest_speed}',
                       font=default)
Exemplo n.º 4
0
def render(draw, width, height):
    stats = psutil.cpu_stats()
    draw.text((10, 0), 'Ctx switch', fill='white', font=default)
    right_text(draw, width, 0, text=str(stats.ctx_switches), font=default)
    draw.text((10, 10), 'Interrupts', fill='white', font=default)
    right_text(draw, width, 10, text=str(stats.interrupts), font=default)
    draw.text((10, 20), 'Soft intr', fill='white', font=default)
    right_text(draw, width, 20, text=str(stats.soft_interrupts), font=default)
Exemplo n.º 5
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}"))
Exemplo n.º 6
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))
Exemplo n.º 7
0
def render(draw, width, height):
    percent = psutil.cpu_percent()
    cpu_freqs = psutil.cpu_freq(percpu=True)
    max_freq = max(cpu_freqs, key=_get_current).current / 1024.0
    min_freq = min(cpu_freqs, key=_get_current).current / 1024.0

    draw.text((0, 0), 'CPU', fill='white', font=default)
    right_text(draw, width, 0, text=f'{percent:.1f}%', font=default)

    if max_freq != min_freq:
        right_text(draw,
                   width - 32,
                   0,
                   text=f'{min_freq:.2f}/{max_freq:.2f} GHz',
                   fill='white',
                   font=default)
    else:
        right_text(draw,
                   width - 40,
                   0,
                   text=f'{max_freq:.2f} GHz',
                   fill='white',
                   font=default)
Exemplo n.º 8
0
 def render(draw, width, height):
     usage = psutil.disk_usage(dir)
     draw.text((0, 0), f'Disk', fill='white', font=default)
     right_text(draw, width, 0, text=f'{naturalsize(usage.used, gnu=True)}B / {usage.percent}%', font=default)
Exemplo n.º 9
0
    def render(draw, width, height):
        global count

        snapshot = list(datalogger.entries)
        stat = snapshot[-1]['value']
        last_invoked = snapshot[-1]['timestamp']

        if len(snapshot) > 1:
            prev_stat = snapshot[-2]['value']
            prev_invoked = snapshot[-2]['timestamp']
            elapsed = (last_invoked - prev_invoked).total_seconds()
            upload_rate = (stat.bytes_sent - prev_stat.bytes_sent) / elapsed
            download_rate = (stat.bytes_recv - prev_stat.bytes_recv) / elapsed
        else:
            upload_rate = 0
            download_rate = 0

        ip_addr = ext_ip_addr if ext_ip_addr and count % 10 < 5 else local_ip_addr

        draw.text((0, 0), f'Net: {iface}', fill="white", font=default)
        right_text(draw, width, 0, text=ip_addr, fill="white", font=default)

        draw.text((5, 10), f'Up:', fill='white', font=default)
        right_text(draw,
                   width - 44,
                   10,
                   text=f'{naturalsize(upload_rate)}B/s',
                   fill='white',
                   font=default)
        right_text(draw,
                   width,
                   10,
                   text=f'{naturalsize(stat.bytes_sent)}B',
                   fill='white',
                   font=default)

        draw.text((0, 20), f' Down:', fill='white', font=default)
        right_text(draw,
                   width - 44,
                   20,
                   text=f'{naturalsize(download_rate)}B/s',
                   fill='white',
                   font=default)
        right_text(draw,
                   width,
                   20,
                   text=f'{naturalsize(stat.bytes_recv)}B',
                   fill='white',
                   font=default)

        pairs = list(window(snapshot, size=2))
        bytes_sent = [
            second['value'].bytes_sent - first['value'].bytes_sent
            for first, second in pairs
        ]
        bytes_recv = [
            second['value'].bytes_recv - first['value'].bytes_recv
            for first, second in pairs
        ]

        arrow(draw, (5, 33), fill='white', direction='up', size=6)
        chart(draw, (13, 30),
              height=12,
              width=datalogger.max_entries,
              data=bytes_sent)
        arrow(draw, (width / 2 + 5, 33),
              fill='white',
              direction='down',
              size=6)
        chart(draw, ((width / 2) + 13, 30),
              height=12,
              width=datalogger.max_entries,
              data=bytes_recv)

        count += 1
Exemplo n.º 10
0
def render(draw, width, height):
    av1, av2, av3 = os.getloadavg()
    draw.text((0, 0), 'Load', fill='white', font=default)
    right_text(draw, width, 0, text=f'{av1:.1f} / {av2:.1f} / {av3:.1f}', font=default)