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

70 lines
1.6 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:
2019-12-15 21:38:54 +01:00
![screenshot](../awesome-wm-widgets/assets/img/screenshots/cpu-widget/cpu.gif)
2018-09-15 23:33:42 +02:00
## How it works
2019-12-15 21:38:54 +01:00
To measure the load I took Paul Colby's bash [script](../awesome-wm-widgets/assets/img/screenshots/cpu-widgetttp://colby.id.au/calculating-cpu-usage-from-proc-stat/) and rewrote it in Lua, which was quite simple.
2018-09-15 23:33:42 +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-12-15 21:38:54 +01: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 |
2018-09-15 23:33:42 +02:00
2019-12-15 21:38:54 +01:00
### Example
2018-09-25 01:18:45 +02:00
2019-12-15 21:38:54 +01:00
```lua
cpu_widget({
width = 70,
step_width = 2,
step_spacing = 0,
color = '#434c5e'
})
```
The config above results in the following widget:
2018-09-25 01:18:45 +02:00
2019-12-15 21:38:54 +01:00
![custom](../awesome-wm-widgets/assets/img/screenshots/cpu-widget/custom.png)
2018-09-25 01:18:45 +02:00
2019-12-15 21:38:54 +01:00
## Installation
2018-09-25 01:18:45 +02:00
2019-12-15 21:38:54 +01:00
Clone/download repo and use widget in **rc.lua**:
2018-09-25 01:18:45 +02:00
2019-12-15 21:38:54 +01:00
```lua
local cpu_widget = require("awesome-wm-widgets.cpu-widget.cpu-widget")
...
s.mytasklist, -- Middle widget
{ -- Right widgets
layout = wibox.layout.fixed.horizontal,
...
-- default
cpu_widget(),
-- or custom
cpu_widget({
width = 70,
step_width = 2,
step_spacing = 0,
color = '#434c5e'
})
...
```