Sample Header Ad - 728x90

{up, down}speedgraphs not shown using `lua_parse lua_func`

1 vote
1 answer
191 views
Here is my conkyrc:
-lua
conky.config = {
	use_xft = true, -- use xft?
	font = 'DejaVuSans:size=9', -- font name
	xftalpha = 1,
	uppercase = false, -- all text in uppercase?
	pad_percents = 0,
	text_buffer_size = 2048,
	override_utf8_locale = true, -- Force UTF8? note that UTF8 support required XFT
	use_spacer = 'none', -- Add spaces to keep things from moving about?  This only affects certain objects.

	update_interval = 1, -- Update interval in seconds
	double_buffer = true, -- Use double buffering (reduces flicker, may not work for everyone)
	total_run_times = 0, -- This is the number of times Conky will update before quitting. Set to zero to run forever.

	-- Create own window instead of using desktop (required in nautilus)
	own_window = true,
	own_window_class = 'Conky',
	own_window_transparent = true,
	own_window_argb_visual = true,
	own_window_argb_value = 255,
	own_window_type = 'desktop', -- transparency seems to work without this line
	own_window_hints = 'undecorated,sticky,below,skip_taskbar,skip_pager',

	-- Minimum size of text area
	minimum_height = 50,
	minimum_width = 210,

	draw_shades = false, -- draw shades?
	draw_outline = false, -- draw outlines?
	draw_borders = false, -- draw borders around text?
	draw_graph_borders = false, -- draw borders around graphs
	stippled_borders = 0, -- stripled borders?

	imlib_cache_size = 0, -- Imlib2 image cache size, in bytes. Increase this value if you use $image lots. Set to 0 to disable the image cache.

	-- Gap between borders of screen and text. Same thing as passing -x at command line
	gap_x = 90,
	gap_y = 5,

	alignment = 'middle_right', -- alignment on {y_axis}_{x_axis}

	cpu_avg_samples = 2, -- number of cpu samples to average. set to 1 to disable averaging
	net_avg_samples = 2, -- number of net samples to average. set to 1 to disable averaging

	no_buffers = true, -- Subtract file system buffers from used memory?

	default_color = 'e0e0e0',
	default_shade_color = '000000',
	default_outline_color = '000000',

	temperature_unit = 'celsius',

	color1 = 'ff55ff', -- heading's color
	color2 = 'ffffff', -- normal text's color

    lua_load = '.conky/netdevs.lua',
};

conky.text = [[
...
${color1}NET: ${hr 2}${color2}${lua_parse conky_show_netdevs}
...
]]
Here is .config/netdevs.lua:
-lua
-- conky_show_netdevs : template for network
-- usage : ${lua_parse conky_show_netdevs}

prev_result = ""

function conky_show_netdevs()
    updates = tonumber(conky_parse("${updates}"))
    interval = 10
    timer = (updates % interval)

    if timer == 0 or prev_result == "" then
        local netdevs_handle = io.popen("ip -j link show up | jq -r '.[] | select(.operstate == \"UP\" and .ifname != \"lo\") | .ifname'")
        local result = ""

        for netdev in netdevs_handle:lines() do
            result = result .. "\nIP (${color1}" .. netdev .. "${color2}): ${alignr}${addr " .. netdev .. "}\n" ..
                     "${color2}Up: ${color2}${upspeed " .. netdev .. "}/s${color1}${alignr}${upspeedgraph " .. netdev .. " 10,170}\n" ..
                     "${color2}Down: ${color2}${downspeed " .. netdev .. "}/s${color1}${alignr}${downspeedgraph " .. netdev .. " 10,170}\n" ..
                     "${color2}Total Down: ${color2}${totaldown " .. netdev .. "}${alignr}Total Up: ${totalup " .. netdev .. "}\n"
        end

        netdevs_handle:close()

        if result ~= "" then
            prev_result = result
        else
            prev_result = "\n"
        end
    end

    return prev_result
end
Everything works, except for the upspeedgraphs and downspeedgraphs, returned in conky_show_netdevs() function's output. Here is an image of the graphs I can see (the small lines in the last section of the image; on the lines where the texts "UP" and "DOWN" are present): conky window --- As far as I could think, I thought this issue was caused due to lua function's contents getting parsed every time conky reloaded, which could cause the graph to reload. So, I tried to increase the update interval of conky to 10 secs. But still, no luck :( 👎. --- Please tell me why is this happening and how to resolve this issue? Thanks 😊!
Asked by Lakshay Rohila (105 rep)
Feb 9, 2024, 10:34 AM
Last activity: Feb 9, 2024, 06:10 PM