Skip to content

Commit

Permalink
upd cpu_usage.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
safocl committed Mar 15, 2017
1 parent dba8b58 commit 82cb76b
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 40 deletions.
Binary file modified .config/i3/.config.swp
Binary file not shown.
14 changes: 12 additions & 2 deletions .config/i3/config
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ font pango:xos4 Terminus 10
# Use Mouse+$mod to drag floating windows to their wanted position
floating_modifier $mod

# запуск/завершение deadbeef
bindsym XF86AudioPlay exec "$HOME/.config/i3/deadbeef_toggle.sh"

bindsym XF86MyComputer exec "gnome-system-monitor"

# редактирование данного конфига
bindsym $mod+Ctrl+c exec "urxvtc -e vim $HOME/.config/i3/config"
Expand All @@ -66,10 +70,10 @@ bindsym XF86AudioRaiseVolume exec "pamixer -i 5"
bindsym $mod+Ctrl+e exec pulseaudio-equalizer toggle

#reboot
bindsym $alt+Ctrl+r exec $HOME/.saf-scrypt/reboot.sh
bindsym $alt+Ctrl+r exec "bash $HOME/.saf-scrypt/reboot.sh"

#shutdown
bindsym $alt+Ctrl+h exec $HOME/.saf-scrypt/poweroff.sh
bindsym $alt+Ctrl+h exec "bash $HOME/.saf-scrypt/poweroff.sh"

set $browser chromium
bindsym $mod+b exec $browser
Expand Down Expand Up @@ -200,8 +204,14 @@ assign [class="(?i)steam"] → $ws3
assign [class="(?i)dota2"] → $ws3
assign [class="(?i)sylpheed"] → $ws4
assign [class="(?i)teamspeak"] → $ws5
assign [class="(?i)deadbeef"] → $ws5
assign [class="(?i)rss guard"] → $ws8

for_window [class="(?i)gnome-system-monitor"] floating enable
for_window [class="(?i)deadbeef"] floating enable
for_window [class="(?i)pavucontrol"] floating enable, move position mouse
for_window [class="(?i)pavucontrol" instance="pavucontrol-bar"] move up 34px

# reload the configuration file
bindsym $mod+Shift+c reload
# restart i3 inplace (preserves your layout/session, can be used to upgrade i3)
Expand Down
8 changes: 8 additions & 0 deletions .config/i3/deadbeef_toggle.sh
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
54 changes: 16 additions & 38 deletions .config/luastatus/cpu_usage.lua
Original file line number Diff line number Diff line change
@@ -1,55 +1,33 @@
-- posix = require("posix")
local color_warn = ''
local sleep_duration = 0.2
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)

function stat_upd()
stat:seek('set', 5)
local currentStats = stat:read()


local user, nice, system, idle, iowait, irq, softirq, steal, guest, guest_nice = string.match(currentStats, '(.*) +(.*) +(.*) +(.*) +(.*) +(.*) +(.*) +(.*) +(.*) +(.*)')
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

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)
function cpu_usage()
local cur, prev = {}, {}

prev = stat_upd()

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)
luastatus.rc{"sleep", sleep_duration}

cur = stat_upd()

local PrevIdle = previdle + previowait
local Idle = idle + iowait
local PrevIdle = prev.idle + prev.iowait
local Idle = cur.idle + cur.iowait

local PrevNonIdle = (prevuser + prevnice + prevsystem + previrq + prevsoftirq + prevsteal)
local NonIdle = (user + nice + system + irq + softirq + steal)
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)
Expand Down
79 changes: 79 additions & 0 deletions .config/luastatus/cpu_usage.lua.old
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,
}
58 changes: 58 additions & 0 deletions .config/luastatus/cpu_usage1.lua
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,
}

0 comments on commit 82cb76b

Please sign in to comment.