2017-09-28 01:45:25 +02:00
# CPU widget
This widget shows the average CPU load among all cores of the machine:
2019-06-03 04:05:37 +02:00
![screenshot ](cpu.gif )
2017-09-28 01:45:25 +02:00
## How it works
2017-09-28 15:39:16 +02:00
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.
2017-09-28 01:45:25 +02:00
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.
2019-06-03 04:05:37 +02:00
## Customization
It is possible to customize widget by providing a table with all or some of the following config parameters:
| Name | Default | Description |
|---|---|---|
| `width` | 50 | Width of the widget |
| `step_width` | 2 | Width of the step |
| `step_spacing` | 1 | Space size between steps |
| `color` | `beautiful.fg_normal` | Color of the graph |
### Example
```lua
cpu_widget({
width = 70,
step_width = 2,
step_spacing = 0,
color = '#434c5e'
})
```
The config above results in the following widget:
![custom ](./custom.png )
2017-09-28 01:45:25 +02:00
## Installation
Clone/download repo and use widget in **rc.lua** :
```lua
2018-12-08 02:00:22 +01:00
local cpu_widget = require("awesome-wm-widgets.cpu-widget.cpu-widget")
2017-09-28 01:45:25 +02:00
...
s.mytasklist, -- Middle widget
{ -- Right widgets
layout = wibox.layout.fixed.horizontal,
...
2019-06-03 04:05:37 +02:00
-- default
cpu_widget(),
-- or custom
cpu_widget({
width = 70,
step_width = 2,
step_spacing = 0,
color = '#434c5e'
})
2017-09-28 01:45:25 +02:00
...
2017-09-28 01:48:08 +02:00
```