Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added cpuload block #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions i3-dstatus.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
# string to use the markup features
---
general:
generators: [ focused-window, scratchpad, playerctl, clipboard, netifaces, disk, battery, clock ]
separator-block-width: 25
clock:
format: '%h %d <b>%H:%M</b>'
generators: [ github-repos, scratchpad, playerctl, netifaces, disk, cpuload, clock ]
separator-block-width: 15
disk:
'/':
prefix: 'custom'
Expand All @@ -33,9 +31,15 @@ check-http:
format-up: ''
format-down: '<span color="red">%site is down (status: %status, %reason)</span>'
github-repos:
users: [ altdesktop ]
users: [ robertu ]
robertu marked this conversation as resolved.
Show resolved Hide resolved
interval: 600
format: '<span color="yellow">★</span>%stars <small>?</small>%issues'
#auth: [ 'username', 'token' ]
battery:
format: '%icon%percentage%'
name: 'BAT0' # defaults to the first battery found
format: '%name %percentage%'
clock:
format: '%d %h %Y [ %H:%M ] '
robertu marked this conversation as resolved.
Show resolved Hide resolved
cpuload:
interval: 10
format: 'cpu %cpuload <span color="yellow">%bar</span>'
Empty file removed i3dstatus/__main__.py
Empty file.
84 changes: 84 additions & 0 deletions i3dstatus/generators/cpuload
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env python3

from i3dstatus.block import Block

import time
import atexit
from requests.exceptions import ConnectionError
robertu marked this conversation as resolved.
Show resolved Hide resolved
import os
import asyncio

block = Block(os.path.basename(__file__))

# display aggregate info on your users github repos
robertu marked this conversation as resolved.
Show resolved Hide resolved

block_name = 'cpuload'
robertu marked this conversation as resolved.
Show resolved Hide resolved

INTERVAL = 0.1

def getTimeList():
robertu marked this conversation as resolved.
Show resolved Hide resolved
"""
Fetches a list of time units the cpu has spent in various modes
Detailed explanation at http://www.linuxhowtos.org/System/procstat.htm
"""
cpuStats = open("/proc/stat", "r").readline()
columns = cpuStats.replace("cpu", "").split(" ")
return map(int, filter(None, columns))

val = "▁▂▃▄▅▆▇█"
current = "▁▁▁load▁"

def deltaTime(interval):
"""
Returns the difference of the cpu statistics returned by getTimeList
that occurred in the given time delta
"""
timeList1 = getTimeList()
time.sleep(interval)
timeList2 = getTimeList()
return [(t2-t1) for t1, t2 in zip(timeList1, timeList2)]

def getCpuLoad():
"""
Returns the cpu load as a value from the interval [0.0, 1.0]
"""
dt = list(deltaTime(INTERVAL))
idle_time = float(dt[3])
total_time = sum(dt)
load = 1-(idle_time/total_time)
return load



async def show_block(block_format):
global current, val

load = getCpuLoad()
step = int(load*17)
if step > 7:
step = 7
current = (current+val[step])[1:]
context = {
'cpuload': f"{'%3.2f' % (load*100.0)}%",
'bar': current,
}
await block.show(block_format, context=context, markup='pango')


async def main():

await block.connect()
block_format = "%cpuload %bar"
interval = 5
if 'format' in block.config:
block_format = block.config['format']
if 'interval' in block.config:
interval = int(block.config['interval'])

while True:
await show_block(block_format)
await asyncio.sleep(interval)


loop = asyncio.get_event_loop()
loop.run_until_complete(main())
6 changes: 0 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,5 @@

scripts=['i3-dstatus'],

entry_points={
'console_scripts': [
'i3-dstatus = i3dstatus.__main__:main'
]
},

packages=find_packages(),
)