awesome-wm-widgets/_widgets/cpu-widget.md

48 lines
1.2 KiB
Markdown
Raw Normal View History

2018-09-15 23:33:42 +02:00
---
layout: page
---
# CPU widget
This widget shows the average CPU load among all cores of the machine:
2018-09-25 15:56:49 +02:00
![screenshot]({{'/assets/img/screenshots/cpu-widget.gif' | relative_url }}){:.center-image}
2018-09-15 23:33:42 +02:00
When the load is more than 80% the graph becomes red. You can easily customize the widget by changing colors, step width, step spacing, width and interval.
## How it works
To measure the load I took Paul Colby's bash [script](http://colby.id.au/calculating-cpu-usage-from-proc-stat/) and rewrote it in Lua, which was quite simple.
So awesome simply reads the first line of /proc/stat:
```bash
$ cat /proc/stat | grep '^cpu '
cpu 197294 718 50102 2002182 3844 0 2724 0 0 0
```
and calculates the percentage.
## Installation
2018-09-25 01:18:45 +02:00
1. Clone this repo under **~/.config/awesome/**
```bash
git clone https://github.com/streetturtle/awesome-wm-widgets.git ~/.config/awesome/
```
1. Require spotify-widget at the beginning of **rc.lua**:
```lua
local cpu_widget = require("awesome-wm-widgets.cpu-widget.cpu-widget")
```
1. Add widget to the tasklist:
```lua
s.mytasklist, -- Middle widget
{ -- Right widgets
layout = wibox.layout.fixed.horizontal,
...
cpu_widget,
...
```