-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
173 additions
and
40 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#! /bin/bash | ||
|
||
if pgrep -f '^deadbeef$'>/dev/null | ||
then | ||
deadbeef --quit | ||
else | ||
deadbeef | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
-- posix = require("posix") | ||
local color_warn = '' | ||
local sleep_duration = 0.2 | ||
|
||
local stat = io.open('/proc/stat', 'r') | ||
stat:setvbuf('no') | ||
|
||
|
||
function cpu_usage() | ||
|
||
stat:seek('set', 5) | ||
local previousStats = stat:read() | ||
|
||
luastatus.rc{"sleep", sleep_duration} | ||
-- posix.sleep(sleep_duration) | ||
|
||
stat:seek('set', 5) | ||
local currentStats = stat:read() | ||
|
||
|
||
local user, nice, system, idle, iowait, irq, softirq, steal, guest, guest_nice = string.match(currentStats, '(.*) +(.*) +(.*) +(.*) +(.*) +(.*) +(.*) +(.*) +(.*) +(.*)') | ||
|
||
local prevuser, prevnice, prevsystem, previdle, previowait, previrq, prevsoftirq, prevsteal, prevguest, prevguest_nice = string.match(previousStats, '(.*) +(.*) +(.*) +(.*) +(.*) +(.*) +(.*) +(.*) +(.*) +(.*)') | ||
|
||
user = tonumber(user) | ||
nice = tonumber(nice) | ||
system = tonumber(system) | ||
idle = tonumber(idle) | ||
iowait = tonumber(iowait) | ||
irq = tonumber(irq) | ||
softirq = tonumber(softirq) | ||
steal = tonumber(steal) | ||
guest = tonumber(guest) | ||
guest_nice = tonumber(guest_nice) | ||
|
||
prevuser = tonumber(prevuser) | ||
prevnice = tonumber(prevnice) | ||
prevsystem = tonumber(prevsystem) | ||
previdle = tonumber(previdle) | ||
previowait = tonumber(previowait) | ||
previrq = tonumber(previrq) | ||
prevsoftirq = tonumber(prevsoftirq) | ||
prevsteal = tonumber(prevsteal) | ||
prevguest = tonumber(prevguest) | ||
prevguest_nice = tonumber(prevguest_nice) | ||
|
||
|
||
local PrevIdle = previdle + previowait | ||
local Idle = idle + iowait | ||
|
||
local PrevNonIdle = (prevuser + prevnice + prevsystem + previrq + prevsoftirq + prevsteal) | ||
local NonIdle = (user + nice + system + irq + softirq + steal) | ||
|
||
local PrevTotal = (PrevIdle + PrevNonIdle) | ||
local Total = (Idle + NonIdle) | ||
|
||
local totald = (Total - PrevTotal) | ||
local idled = (Idle - PrevIdle) | ||
|
||
local CPU_Percentage = (totald - idled) / totald * 100 | ||
|
||
if CPU_Percentage > 90 then | ||
color_warn = '#FF4040' | ||
else | ||
color_warn = '#00e0ff' | ||
end | ||
return string.format('%3.0f%s', CPU_Percentage, '%') | ||
end | ||
|
||
widget = { | ||
plugin = 'timer', | ||
opts = { | ||
period = 2 | ||
--fifo = '/proc/stat' | ||
}, | ||
cb = function() | ||
return {full_text='CPU'..cpu_usage(), color=color_warn} | ||
end, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
-- posix = require("posix") | ||
local color_warn = '' | ||
local sleep_duration = 0.2 | ||
|
||
local stat = io.open('/proc/stat', 'r') | ||
stat:setvbuf('no') | ||
|
||
|
||
function stat_upd() | ||
stat:seek('set', 5) | ||
-- local Stats = stat:read() | ||
local point = {} | ||
point.user, point.nice, point.system, point.idle, point.iowait, point.irq, point.softirq, point.steal, point.guest, point.guest_nice = string.match(stat:read(), '(.*) +(.*) +(.*) +(.*) +(.*) +(.*) +(.*) +(.*) +(.*) +(.*)') | ||
return point | ||
end | ||
|
||
|
||
function cpu_usage() | ||
local cur, prev = {}, {} | ||
|
||
prev = stat_upd() | ||
|
||
luastatus.rc{"sleep", sleep_duration} | ||
|
||
cur = stat_upd() | ||
|
||
local PrevIdle = prev.idle + prev.iowait | ||
local Idle = cur.idle + cur.iowait | ||
|
||
local PrevNonIdle = (prev.user + prev.nice + prev.system + prev.irq + prev.softirq + prev.steal) | ||
local NonIdle = (cur.user + cur.nice + cur.system + cur.irq + cur.softirq + cur.steal) | ||
|
||
local PrevTotal = (PrevIdle + PrevNonIdle) | ||
local Total = (Idle + NonIdle) | ||
|
||
local totald = (Total - PrevTotal) | ||
local idled = (Idle - PrevIdle) | ||
|
||
local CPU_Percentage = (totald - idled) / totald * 100 | ||
|
||
if CPU_Percentage > 90 then | ||
color_warn = '#FF4040' | ||
else | ||
color_warn = '#00e0ff' | ||
end | ||
return string.format('%3.0f%s', CPU_Percentage, '%') | ||
end | ||
|
||
widget = { | ||
plugin = 'timer', | ||
opts = { | ||
period = 2 | ||
--fifo = '/proc/stat' | ||
}, | ||
cb = function() | ||
return {full_text='CPU'..cpu_usage(), color=color_warn} | ||
end, | ||
} |