Modul pro Conky zobrazující top procesy řazené podle využití cpu, paměti, cpu času.
Skript modulu stačí vložit na konec již uveřejněného základního nastavení LUA skriptu a do tabulky ‚modul‘ zadat název modulu. Název modulu naleznete za nápovědou v proměnné:
local name = "procesy"
Skript modulu:
function modul_procesy() ------------------------------------------------------------ -- VLKODLAK -- 2015 ver 0.1 ------------------------------------------------------------ -- zobrazuje procesy podle vytížení cpu / paměti / času -- --########################################################## -- -- pro svou činnost potřebuje: funkce --[[ kurzor() pozadi(poz,vyska) --]] -- -- pro svou činnost potřebuje: globální tabulky (před hlavní funkcí - conky_main()) --[[ update = { ["procesy"] = nil, } interval = { ["procesy"] = 300, } klik_menu = { ["procesy"] = 0, } --]] -- -- pro svou činnost potřebuje: globální proměnné (před hlavní funkcí - conky_main()) --[[ pozadi_menu --nastavuje pozadí pro menu pozadi_panel --nastavuje pozadí pro panel pozadi_barva --nastavuje barvu pozadí rozmer_panelu_x --rozměr panelu v pixelech, musí se shodovat s nastavením --hodnoty 'minimum_size' v conky.rc --]] ------------------------------------------------------------ --proměnná pro identifikaci modulu local name = "procesy" ---------------------------------------- --podmínky pro interval dat modulu ---------------------------------------- if tonumber(update[tostring(name)]) == nil then --první průchod skriptem --nastavení intervalu update[tostring(name)] = updates + tonumber(interval[tostring(name)]) ---------------------------------------- --definování tabulky pro nastavení modulu procesy_tab = { ["vyber"] = "cpu", ["pozice_y"] = nil, } --smyčka pro nastavení pozice modulu for a = 1,#modul.name do local text = tostring(modul.name[a]) if string.match(text, "(%S*)") == tostring(name) then procesy_tab.pozice_y = a break end--if string.match(text, "(%S)") == tostring(name) then end--for a = 1,#modul.name do ---------------------------------------- --definování tabulky pro data top = {["cpu"] = {},["mem"] = {},["time"] = {},} --podtabulky pro tabulku top for a = 1,9 do top.cpu[tonumber(a)] = {} top.mem[tonumber(a)] = {} top.time[tonumber(a)] = {} end elseif tonumber(update[tostring(name)]) <= updates then --ostatní průchody skriptem --nastavení intervalu update[tostring(name)] = updates + tonumber(interval[tostring(name)]) ---------------------------------------- --smyčka pro naplnění tabulky for a = 1,9 do top.cpu[tonumber(a)].name = conky_parse("${top name "..a.."}") top.cpu[tonumber(a)].pid = conky_parse("${top pid "..a.."}") top.cpu[tonumber(a)].cpu = conky_parse("${top cpu "..a.."}") --top.cpu[tonumber(a)].mem = conky_parse("${top mem "..a.."}") top.cpu[tonumber(a)].mem_res = conky_parse("${top mem_res "..a.."}") --top.cpu[tonumber(a)].mem_vsize = conky_parse("${top mem_vsize "..a.."}") --top.cpu[tonumber(a)].time = conky_parse("${top time "..a.."}") top.cpu[tonumber(a)].uid = conky_parse("${top uid "..a.."}") --top.cpu[tonumber(a)].user = conky_parse("${top user "..a.."}") top.cpu[tonumber(a)].io_perc = conky_parse("${top io_perc "..a.."}") --top.cpu[tonumber(a)].io_read = conky_parse("${top io_read "..a.."}") --top.cpu[tonumber(a)].io_write = conky_parse("${top io_write "..a.."}") top.mem[tonumber(a)].name = conky_parse("${top_mem name "..a.."}") top.mem[tonumber(a)].pid = conky_parse("${top_mem pid "..a.."}") top.mem[tonumber(a)].cpu = conky_parse("${top_mem cpu "..a.."}") --top.mem[tonumber(a)].mem = conky_parse("${top_mem mem "..a.."}") top.mem[tonumber(a)].mem_res = conky_parse("${top_mem mem_res "..a.."}") --top.mem[tonumber(a)].mem_vsize = conky_parse("${top_mem mem_vsize "..a.."}") --top.mem[tonumber(a)].time = conky_parse("${top_mem time "..a.."}") top.mem[tonumber(a)].uid = conky_parse("${top_mem uid "..a.."}") --top.mem[tonumber(a)].user = conky_parse("${top_mem user "..a.."}") top.mem[tonumber(a)].io_perc = conky_parse("${top_mem io_perc "..a.."}") --top.mem[tonumber(a)].io_read = conky_parse("${top_mem io_read "..a.."}") --top.mem[tonumber(a)].io_write = conky_parse("${top_mem io_write "..a.."}") top.time[tonumber(a)].name = conky_parse("${top_time name "..a.."}") top.time[tonumber(a)].pid = conky_parse("${top_time pid "..a.."}") top.time[tonumber(a)].cpu = conky_parse("${top_time cpu "..a.."}") --top.time[tonumber(a)].mem = conky_parse("${top_time mem "..a.."}") top.time[tonumber(a)].mem_res = conky_parse("${top_time mem_res "..a.."}") --top.time[tonumber(a)].mem_vsize = conky_parse("${top_time mem_vsize "..a.."}") --top.time[tonumber(a)].time = conky_parse("${top_time time "..a.."}") top.time[tonumber(a)].uid = conky_parse("${top_time uid "..a.."}") --top.time[tonumber(a)].user = conky_parse("${top_time user "..a.."}") top.time[tonumber(a)].io_perc = conky_parse("${top_time io_perc "..a.."}") --top.time[tonumber(a)].io_read = conky_parse("${top_time io_read "..a.."}") --top.time[tonumber(a)].io_write = conky_parse("${top_time io_write "..a.."}") end--for a = 1,9 do end--if tonumber(update[tostring(name)]) == nil then ---------------------------------------- --vypis dat modulu ---------------------------------------- local x = 0 local y = modul.pozice[tonumber(procesy_tab.pozice_y)] --nastavení fontu cairo_select_font_face (cr, "Mono", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); ---------------------------------------- --vykreslení pozadí pro menu if pozadi_menu == 1 then pozadi(y-12,15) end ---------------------------------------- --konstrukce pro klikutí na menu local menu = "TOP PROCESY" local delka = tonumber(string.len(menu)*7) --linie - první část cairo_select_font_face (cr, "Mono", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); cairo_set_font_size (cr, 12.0); cairo_set_source_rgba (cr, 1,0.7,0,1); local linie1 = (rozmer_panelu_x - delka)/2 - 5 cairo_rectangle (cr, x,y-5,linie1,1);cairo_fill (cr); --pozice kurzoru/kliknuti if mx>=x+linie1+5 and mx<=x+linie1+5+delka+3 and my<=y and my>=y-12 then cairo_set_source_rgba (cr, 0.7,0.7,0.7,1); if mx == kx and my == ky and klik_menu[tostring(name)] == 0 then klik_menu[tostring(name)] = 1 elseif mx == kx and my == ky and klik_menu[tostring(name)] == 1 then klik_menu[tostring(name)] = 0 end--kliknuti else cairo_set_source_rgba (cr, 1,0.7,0,1); end--pozice kurzoru cairo_move_to (cr, x+linie1+5, y);cairo_show_text (cr, menu);--text menu --linie - druha cast cairo_set_source_rgba (cr, 1,0.7,0,1); local linie2 = rozmer_panelu_x - (linie1+5+delka+7) cairo_rectangle (cr, x+linie1+5+delka+7,y-5,linie2,1);cairo_fill (cr); ---------------------------------------- --vykreslení pozadí pro panel if pozadi_panel == 1 and klik_menu[tostring(name)] == 1 then local poz = y + 5 local vyska = 174 pozadi(poz,vyska) end--if pozadi_panel == 1 and klik_menu[tostring(name)] == 1 then ---------------------------------------- --otevřený panel - tlačítka if klik_menu[tostring(name)] == 1 then cairo_select_font_face (cr, "Mono", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); y = y + 8 --tlačítko 'cpu' cairo_set_source_rgba (cr, 0.4,0.4,0.4,1); cairo_rectangle (cr, x+5,y,35,15);cairo_fill (cr); if mx>=x+5 and mx<=x+5+35 and my<=y+15 and my>=y then cairo_set_source_rgba (cr, 0,1,0,1);--barva při najetí kurzoru if mx == kx and my == ky then procesy_tab.vyber = "cpu" end else if procesy_tab.vyber == "cpu" then cairo_set_source_rgba (cr, 1,1,1,1);--barva vybrané položky else cairo_set_source_rgba (cr, 0.7,0.7,0.7,1);--barva nevybrané položky end--if procesy_tab.vyber == "cpu" then end--pozice kurzoru cairo_move_to (cr, x+12, y+11);cairo_show_text (cr, "cpu"); --tlačítko 'mem' cairo_set_source_rgba (cr, 0.4,0.4,0.4,1); cairo_rectangle (cr, x+45,y,35,15);cairo_fill (cr); if mx>=x+45 and mx<=x+45+35 and my<=y+15 and my>=y then cairo_set_source_rgba (cr, 0,1,0,1);--barva při najetí kurzoru if mx == kx and my == ky then procesy_tab.vyber = "mem" end else if procesy_tab.vyber == "mem" then cairo_set_source_rgba (cr, 1,1,1,1);--barva vybrané položky else cairo_set_source_rgba (cr, 0.7,0.7,0.7,1);--barva nevybrané položky end--if procesy_tab.vyber == "mem" then end--pozice kurzoru cairo_move_to (cr, x+52, y+11);cairo_show_text (cr, "mem"); --tlačítko 'time' cairo_set_source_rgba (cr, 0.4,0.4,0.4,1); cairo_rectangle (cr, x+85,y,35,15);cairo_fill (cr); if mx>=x+85 and mx<=x+85+35 and my<=y+15 and my>=y then cairo_set_source_rgba (cr, 0,1,0,1);--barva při najetí kurzoru if mx == kx and my == ky then procesy_tab.vyber = "time" end else if procesy_tab.vyber == "time" then cairo_set_source_rgba (cr, 1,1,1,1);--barva vybrané položky else cairo_set_source_rgba (cr, 0.7,0.7,0.7,1);--barva nevybrané položky end--if procesy_tab.vyber == "time" then end--pozice kurzoru cairo_move_to (cr, x+88, y+11);cairo_show_text (cr, "time"); end--if klik_menu[tostring(name)] == 1 then ---------------------------------------- --otevřený panel - výpis hodnot if klik_menu[tostring(name)] == 1 then cairo_set_font_size (cr, 10.0); cairo_set_source_rgba (cr, 0.7,0.7,0.7,1); cairo_move_to (cr, rozmer_panelu_x-95, y+11); cairo_show_text (cr, "Interval: "..interval[tostring(name)].." s"); y = y + 30 cairo_set_source_rgba (cr, 0.9,0.9,0.9,1); cairo_move_to (cr, x+5, y);cairo_show_text (cr, "Name"); cairo_move_to (cr, x+110, y);cairo_show_text (cr, "Cpu %"); cairo_move_to (cr, x+163, y);cairo_show_text (cr, "Mem"); cairo_move_to (cr, x+215, y);cairo_show_text (cr, "Pid"); cairo_move_to (cr, x+265, y);cairo_show_text (cr, "Uid"); cairo_move_to (cr, x+313, y);cairo_show_text (cr, "I/O %"); cairo_rectangle (cr, x+5,y+3,rozmer_panelu_x-10,0.5);cairo_fill (cr); for a = 1,9 do y = y + 15 if tostring(procesy_tab.vyber) == "cpu" then cairo_move_to (cr, x+5, y);cairo_show_text (cr, top.cpu[tonumber(a)].name); cairo_move_to (cr, x+105, y);cairo_show_text (cr, top.cpu[tonumber(a)].cpu); local uprav = top.cpu[tonumber(a)].mem_res z,k,vystup = string.find(uprav,"([%d%p]*%w)") cairo_move_to (cr, x+160, y);cairo_show_text (cr, vystup); cairo_move_to (cr, x+210, y);cairo_show_text (cr, top.cpu[tonumber(a)].pid); cairo_move_to (cr, x+257, y);cairo_show_text (cr, top.cpu[tonumber(a)].uid); cairo_move_to (cr, x+310, y);cairo_show_text (cr, top.cpu[tonumber(a)].io_perc); elseif tostring(procesy_tab.vyber) == "mem" then cairo_move_to (cr, x+5, y);cairo_show_text (cr, top.mem[tonumber(a)].name); cairo_move_to (cr, x+105, y);cairo_show_text (cr, top.mem[tonumber(a)].cpu); local uprav = top.mem[tonumber(a)].mem_res z,k,vystup = string.find(uprav,"([%d%p]*%w)") cairo_move_to (cr, x+160, y);cairo_show_text (cr, vystup); cairo_move_to (cr, x+210, y);cairo_show_text (cr, top.mem[tonumber(a)].pid); cairo_move_to (cr, x+257, y);cairo_show_text (cr, top.mem[tonumber(a)].uid); cairo_move_to (cr, x+310, y);cairo_show_text (cr, top.mem[tonumber(a)].io_perc); elseif tostring(procesy_tab.vyber) == "time" then cairo_move_to (cr, x+5, y);cairo_show_text (cr, top.time[tonumber(a)].name); cairo_move_to (cr, x+105, y);cairo_show_text (cr, top.time[tonumber(a)].cpu); local uprav = top.time[tonumber(a)].mem_res z,k,vystup = string.find(uprav,"([%d%p]*%w)") cairo_move_to (cr, x+160, y);cairo_show_text (cr, vystup); cairo_move_to (cr, x+210, y);cairo_show_text (cr, top.time[tonumber(a)].pid); cairo_move_to (cr, x+257, y);cairo_show_text (cr, top.time[tonumber(a)].uid); cairo_move_to (cr, x+310, y);cairo_show_text (cr, top.time[tonumber(a)].io_perc); end--if tostring(procesy_tab.vyber) == "cpu" then end--for a = 1,9 do end--if klik_menu[tostring(name)] == 1 then ---------------------------------------- --pozice pro další modul if klik_menu[tostring(name)] == 1 then next_y = y + 20 else next_y = y + 17 end--if klik_menu[tostring(name)] == 1 then modul.pozice[tonumber(procesy_tab.pozice_y)+1] = next_y return modul end--function modul_procesy() --############################################################